1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
import java.io.File;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class main extends Application {
double[][] coordodouble = {{49.84653688680709,2.263697236776352},{49.84661125902917,2.2638890147209167},{49.84654034598273, 2.264016419649124},{49.84607767904088,2.2648251056671143}
,{49.845558794959594,2.264261841773987},{49.845354699028064, 2.263827323913574},{49.84592893284039,2.2626739740371704},{49.84653688680709,2.263697236776352}};
String coordoString = "";
@Override
public void start(Stage primaryStage) {
String envoi = "[49.846535, 2.26388]";
Button btn = new Button();
btn.setText("tracer");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
for (int i=0;i<coordodouble.length;i++){//modifier la longueur de la chaine
for (int j=0;j<2;j++){
coordoString=coordoString+String.valueOf(coordodouble[i][j]);
if (j<1){coordoString=coordoString+";";}
}
coordoString=coordoString+"!";
}
System.out.println(coordoString);
if (webengine != null)
{
webengine.executeScript("montranslator(' " + coordoString + " ')");
}
}
});
publishServices();
StackPane root = new StackPane();
HBox hh = new HBox();
hh.getChildren().add(btn);
hh.getChildren().add(webview);
root.getChildren().add(hh);
Scene scene = new Scene(root, 700, 450);
primaryStage.setTitle("essai Leaflet");
primaryStage.setScene(scene);
primaryStage.show();
}
private WebEngine webengine;
private static WebView webview;
private void publishServices() {
try {
webview = new WebView();
webview.setVisible(true);
webengine = webview.getEngine();
webengine.setJavaScriptEnabled(true);
File file = new File("C:\\Users\\....le trajet du fichier html...\\leaflet.html");
System.out.println(file.exists() + " file exitence");
webengine.load(file.toURI().toURL().toString());
} catch (Exception ex) {
System.err.print("error " + ex.getMessage());
ex.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
} |
Partager