你好,我想用gmaps在Java中用破折号连接两个点。 但是要点是在用户单击地图时插入的。
我的控制器中确实有该代码
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;
}
,并且该控制器在该应用程序上运行: actual application
,我想拥有: what i want
因此我测试了MapShare,但是找不到关于它的示例或文档。所以实际上我不知道我的观点如何联系在一起,我想有一个例子来测试并了解它的工作原理
答案 0 :(得分:0)
“但是,当用户单击地图时,要点是插入的。”
您将不得不使用javascript。
遵循以下示例: https://developers.google.com/maps/documentation/javascript/examples/polyline-simple
本质上:
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
});
您可以绘制很多东西,但始终要考虑要使用的点的负载。使用团聚等等。 顺便说一句,您的应用看起来不错。