你好傢伙我試圖更新我的標記位置,但我沒有設法找出如何刪除舊的。我所得到的只是標記的「歷史」。我沒有任何可以幫助我的例子。我希望有人會給我一個線索繼續。 非常感謝Per Liedman這個出色的工作。Leaflet-GeoJson和多個標記的實時插件
var shipLayer = L.layerGroup();
var ships = L.icon({
iconUrl: '../icons/ship-icon.png',
iconSize: [30, 30]
});
var realtime = L.realtime({
url: 'jsonServlet/ships.json',
crossOrigin: true,
type: 'json'
}, {
interval: 5 * 1000,
pointToLayer: function (feature, latlng) {
marker = L.marker(latlng, {icon: ships});
marker.bindPopup('mmsi: ' + feature.properties.mmsi +
'<br/> course:' + feature.properties.hdg+
'<br/> speed:' + feature.properties.sog);
marker.addTo(shipLayer);
return marker;
}
});
controlLayers.addOverlay(geojson, 'Ships');
您可以發佈您ships.json的例子嗎?正如[這個錯誤報告](https://github.com/perliedman/leaflet-realtime/issues/10)所解釋的,「Leaflet Realtime會嘗試尋找一個被調用的屬性ID並使用它來移除舊標記」。如果你能夠改變json的創建過程,你應該嘗試一下。 – chrki
{「type」:「FeatureCollection」,「crs」:{「type」:「name」,「properties」:{「name」:「urn:ogc:def:crs:OGC:1.3:CRS84」}} 「特徵」:[{ 「幾何」:{ 「座標」:[48.517708,18.255447], 「類型」: 「點」}, 「類型」: 「功能」, 「屬性」:{ 「幾何/座標/經度」 : 「48.517708」, 「幾何/類型」: 「點」, 「MMSI」: 「512131345」, 「幾何/座標/緯度」: 「18.255447」, 「HDG」: 「108」, 「嵌齒」: 「108」 ,「sog」:「30.0」,「type」:「Feature」}}]}這個json中的ID是mmsi(unigue商船碼) –