Leaflet 带有GeoJson和多个标记的传单实时插件
大家好,我正在尝试更新我的标记位置,但我无法找到如何删除旧标记。我所能得到的只是这个标记的“历史”。我没有任何对我有帮助的例子。我希望有人能给我一个继续下去的线索。 非常感谢你的出色工作Leaflet 带有GeoJson和多个标记的传单实时插件,leaflet,real-time,geojson,Leaflet,Real Time,Geojson,大家好,我正在尝试更新我的标记位置,但我无法找到如何删除旧标记。我所能得到的只是这个标记的“历史”。我没有任何对我有帮助的例子。我希望有人能给我一个继续下去的线索。 非常感谢你的出色工作 var shipLayer = L.layerGroup(); var ships = L.icon({ iconUrl: '../icons/ship-icon.png',
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');
var shipLayer=L.layerGroup();
var=L.icon({
iconUrl:“../icons/ship icon.png”,
iconSize:[30,30]
});
var realtime=L.realtime({
url:'jsonServlet/ships.json',
交叉起源:对,
键入:“json”
}, {
间隔:5*1000,
pointToLayer:功能(特性、latlng){
marker=L.marker(latlng,{icon:ships});
marker.bindpoop('mmsi:'+feature.properties.mmsi+
“
课程:”+feature.properties.hdg+
“
速度:”+feature.properties.sog);
marker.addTo(发货人);
返回标记;
}
});
addOverlayer(geojson,“Ships”);
默认情况下,L.realtime使用功能的id
属性对其进行更新。正如您在评论中所解释的,您船舶的标识符位于GeoJSON功能的mmsi
属性中,没有id
。您需要将其添加到选项中的L.realtime设置中:
getFeatureId: function(featureData){
return featureData.properties.mmsi;
}
请参见此处:您可以发布ships.json的示例吗?正如所解释的,“传单实时将尝试寻找一个被调用的属性id,并使用它[删除旧标记]”。如果您能够更改json创建过程,您应该尝试这样做。{“类型”:“FeatureCollection”,“crs”:{“类型”:“name”,“properties”:{“name”:“urn:ogc:def:crs:ogc:1.3:CRS84”},“features”:[{“geometry”:{“坐标”:[48.517708,18.255447],“type”:“Point”},“type”:“Feature”,“properties”:{“geometry/coordinates/Length”:“48.517708”,“geometry/type”:“点”,“mmsi”:“512131345”,“几何/坐标/纬度”:“18.255447”,“hdg”:“108”,“cog”:“108”,“sog”:“30.0”,“类型”:“Feature”}]}这个json中的ID是mmsi(unigue商船代码)。这就是问题所在。我无法将“pointToLayer”和“getFeatureId”结合起来。你让我的周末成为我的朋友。非常感谢。