【问题标题】:Leaflet-Realtime plugin with GeoJson and multiple markers带有 GeoJson 和多个标记的 Leaflet-Realtime 插件
【发布时间】:2016-01-22 15:49:57
【问题描述】:

大家好,我正在尝试更新我的标记位置,但我不知道如何删除旧标记。我得到的只是标记的“历史”。我没有任何可以帮助我的例子。我希望有人能给我一个线索继续下去。 非常感谢 Per Liedman 的出色工作。

                    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');

【问题讨论】:

  • 你能发布一个你的 ship.json 的例子吗?正如this bug report 解释的那样,“Leaflet Realtime 将尝试查找被调用的属性 id 并使用它[删除旧标记]”。如果您能够更改 json 创建过程,您应该尝试一下。
  • {"type":"FeatureCollection","crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:OGC: 1.3:CRS84"}},"features":[{"geometry":{"coordinates":[48.517708,18.255447],"type":"Point"},"type":"Feature","properties":{ "几何/坐标/经度":"48.517708","几何/类型":"点","mmsi":"512131345","几何/坐标/纬度":"18.255447","hdg":"108", "cog":"108","sog":"30.0","type":"Feature"}}]} 这个 json 中的 ID 是 mmsi(唯一商船代码)

标签: leaflet real-time geojson


【解决方案1】:

默认情况下,L.realtime 使用功能的id 属性来更新它。正如您在 cmets 中所解释的,您的船舶标识符位于 GeoJSON 功能的 mmsi 属性中,并且没有 id。您需要将其添加到options 中的 L.realtime 设置中:

getFeatureId: function(featureData){
    return featureData.properties.mmsi;
}

请看这里:https://jsfiddle.net/chk1/hmyxb6ur/

【讨论】:

  • 好的。这就是问题所在。我无法将“pointToLayer”和“getFeatureId”结合起来。你让我的周末成为我的朋友。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-11
  • 2015-02-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多