在javaFX应用程序中,我设置marker.setPosition(latlng)来改变标记位置。但是在地图中它仍然显示旧位置的标记。如果有五个事件,则显示五个标记。 但是当我调整地图大小时,其他四个标记消失了,只有新位置可见。哪个是所需的输出。
var map;
var latlng;
var markerMap = {};
function loadmap() {
latlng = new google.maps.LatLng(6.768378333333334, 79.91390166666666);
var options = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("mapcanvas"), options);
}
function addMarker(mapId, x, y) {
latlng = new google.maps.LatLng(x, y);
if (markerMap[mapId] == null) {
var marker = new google.maps.Marker({
position: latlng,
map: map,
draggable: false,
//icon: carMarkerImage,
title: "Vehicle",
autoPan: true
});
var infobulle = new google.maps.InfoWindow({
// You can pass some content to the function like addMarker(x, y, content)
content: "some content for your marker "+mapId
});
google.maps.event.addListener(marker, 'mouseover', function () {
infobulle.open(map, marker);
});
markerMap[mapId] = marker;
} else {
var marker = markerMap[mapId];
marker.setPosition(latlng);
}
goo
JAVAFX ---------
@Override
public void handle(ActionEvent event) {
String csvFileName = csvButtonMap.get(event.getSource());
Button button = (Button) event.getSource();
if (!"Pause".equals(button.getText()) && !"Continue".equals(button.getText())) {
button.setText("Pause");
Vehicle vehicle = new Vehicle(csvFileName);
Thread vThread = new Thread(vehicle);
vehicle.speedPropertyProperty().addListener((v, oldValue, newVlaue) -> {
Platform.runLater(new Runnable() {
@Override
public void run() {
double latitude = Double.parseDouble(vehicle.getLatitudeProperty());
double longitude = Double.parseDouble(vehicle.getLongitudeProperty());
String setMarker = "addMarker(" + vThread.getId() + "," + latitude + "," + longitude + ")".trim();
webEngine.executeScript(setMarker);
}
});
});
vThread.setDaemon(true);
button.setId(String.valueOf(vThread.getId()));
lockObjMap.put(vThread.getId(), new Object());
button.getParent().setId(String.valueOf(vThread.getId()));
statusLabel.setText("Vehicle " + csvFileName + " stared!");
vThread.start();