简体   繁体   中英

gmapsfx connected two point with a dash

Hello I would like to connecte two point with a dash in java with gmaps. But the point are insert when the user click on the map.

I have actually that code in my controller

public class Controller implements Initializable, MapComponentInitializedListener  {
    private int VitesseRef;
    private double HauteurRef;
    private DroneJava python;

    private int id=0;

    @FXML
    private GoogleMapView mapView;


    @FXML
    private TextField Vitesse;


    @FXML
    private TextField Hauteur;

    @FXML
    private TableView<Cordonnée> TabValue;

    private GoogleMap map;

    private List<Point> Point;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        mapView.addMapInializedListener(this);
        Vitesse.setText(String.valueOf(VitesseRef));
        Vitesse.focusedProperty().addListener(new ChangeListener<Boolean>()
        {
            @Override
            public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
            {
                if (newPropertyValue)
                {
                    System.out.println("Textfield on focus");
                }
                else
                {
                    VitesseRef= Integer.parseInt(Vitesse.getText());
                    System.out.println("Textfield out focus V = "+VitesseRef);
                }
            }
        });
        Hauteur.setText(String.valueOf(HauteurRef));
        Hauteur.focusedProperty().addListener(new ChangeListener<Boolean>()
        {
            @Override
            public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
            {
                if (newPropertyValue)
                {
                    System.out.println("Textfield on focus H");
                }
                else
                {
                    HauteurRef= Double.parseDouble(Hauteur.getText());
                    System.out.println("Textfield out focus H = "+HauteurRef);

                }
            }
        });

        TableColumn<Cordonnée, Integer> IDColumn = new TableColumn("Id");
        IDColumn.setCellValueFactory(new PropertyValueFactory<>("ID"));

        TableColumn<Cordonnée, Type_Point> TypeColumn = new TableColumn("Type");
        TypeColumn.setCellValueFactory(new PropertyValueFactory<>("Type"));
        TypeColumn.setCellFactory(ComboBoxTableCell.forTableColumn(Type_Point.values()));


        TableColumn<Cordonnée, Double> LatColumn = new TableColumn("Latitude");
        LatColumn.setCellValueFactory(new PropertyValueFactory<>("Latitude"));
        LatColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter<Double>() {

            @Override
            public String toString(Double object) {
                return String.valueOf(object);
            }

            @Override
            public Double fromString(String string) {
                return Double.valueOf(string);
            }
        }));

        TableColumn<Cordonnée, Double> LongColumn = new TableColumn("Longitude");
        LongColumn.setCellValueFactory(new PropertyValueFactory<>("Longitude"));
        LongColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter<Double>() {

            @Override
            public String toString(Double object) {
                return String.valueOf(object);
            }

            @Override
            public Double fromString(String string) {
                return Double.valueOf(string);
            }
        }));

        TableColumn<Cordonnée, Double> AltColumn = new TableColumn("Hauteur");
        AltColumn.setCellValueFactory(new PropertyValueFactory<>("Altitude"));
        AltColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter<Double>() {

            @Override
            public String toString(Double object) {
                return String.valueOf(object);
            }

            @Override
            public Double fromString(String string) {
                return Double.valueOf(string);
            }
        }));

        TableColumn<Cordonnée, Integer> VitColumn = new TableColumn("Vitesse");
        VitColumn.setCellValueFactory(new PropertyValueFactory<>("Vitesse"));
        VitColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter<Integer>() {

            @Override
            public String toString(Integer object) {
                return String.valueOf(object);
            }

            @Override
            public Integer fromString(String string) {
                return Integer.parseInt(string);
            }
        }));

        TableColumn<Cordonnée, Double> DiaColumn = new TableColumn("Diametre");
        DiaColumn.setCellValueFactory(new PropertyValueFactory<>("Diametre"));
        DiaColumn.setCellFactory(TextFieldTableCell.forTableColumn(new StringConverter<Double>() {

            @Override
            public String toString(Double object) {
                return String.valueOf(object);
            }

            @Override
            public Double fromString(String string) {
                return Double.valueOf(string);
            }
        }));

        TableColumn Action = new TableColumn("Action");
        TableColumn Up = new TableColumn("Up");
        TableColumn Down = new TableColumn("Down");
        TableColumn Delete = new TableColumn("Delete");
        Action.getColumns().addAll(Up,Down,Delete);

        TabValue.getColumns().addAll(IDColumn,TypeColumn,LatColumn,LongColumn,AltColumn,VitColumn,DiaColumn,Action);
    }

    @Override
    public void mapInitialized() {

        //Set the initial properties of the map.
        MapOptions mapOptions = new MapOptions();

        mapOptions.center(new LatLong(44.84062305077133, -0.5831479278476763))
                .overviewMapControl(true)
                .panControl(false)
                .rotateControl(false)
                .scaleControl(false)
                .streetViewControl(false)
                .zoomControl(true)
                .zoom(12);

        map = mapView.createMap(mapOptions);


        map.addMouseEventHandler(UIEventType.click, (GMapMouseEvent event) -> {
            LatLong latLong = event.getLatLong();
            System.out.println("Latitude: " + latLong.getLatitude());
            System.out.println("Longitude: " + latLong.getLongitude());
            MarkerOptions markerOptions1 = new MarkerOptions();
            markerOptions1.position(latLong);
            Marker joeSmithMarker = new Marker(markerOptions1);
            map.addMarker( joeSmithMarker );


            Cordonnée tmp = new Cordonnée(id,null,latLong.getLatitude(),latLong.getLongitude(),HauteurRef,VitesseRef);
            Point tmp1 = new Point(tmp,joeSmithMarker);
            id++;
            Point.add(tmp1);
            TabValue.getItems().add(tmp);
        });


    }

    public Controller(){
        Point = new ArrayList<Point>();
        VitesseRef=3;
        HauteurRef=2.5;
    }

and that controller run on that application : actual application

and i want to have that : what i want

So for did that i test the MapShare but i cant find some exemple or documentation on it. So actually i don't know how link my point and i would like to have one exemple to test and undestood how it's work

"But the point are insert when the user click on the map."

You will have to move to javascript.

Follow this example: https://developers.google.com/maps/documentation/javascript/examples/polyline-simple

Essentially:

var flightPlanCoordinates = [
          {lat: 37.772, lng: -122.214},
          {lat: 21.291, lng: -157.821},
          {lat: -18.142, lng: 178.431},
          {lat: -27.467, lng: 153.027}
        ];
        var flightPath = new google.maps.Polyline({
          path: flightPlanCoordinates,
          geodesic: true,
          strokeColor: '#FF0000',
          strokeOpacity: 1.0,
          strokeWeight: 2
        });

You can draw a lot of things, but always take in account the load of points you will use. Use agrupations and so on. Btw, your app loos nice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM