解决特定的geojson功能

时间:2016-04-21 08:05:41

标签: leaflet

我已经构建了一个地图,并通过L.circle()

在其上绘制了一些不错的geojson特征(点)
function loadNodes(map, geojson) {
   return L.geoJson(feature, {
            pointToLayer: function (feature, latlng) {
               return L.circle(latlng, 50, merge_options(cirkelOpties, {
                    fillColor: feature.properties.kleur,
                }));
            }
          }
        ).addTo(kaart);
}

在geojson功能中,我有一个唯一的ID:feature.properties.node_id我想用它来定位来自另一个(我的一部分)javascript的特定圈子。

查找和重新定位绘制圆圈的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

只需在pointToLayer回调之外的变量范围内引用圈子:

var circles = {};

function loadNodes(map, geojson) {
    return L.geoJson(feature, {
        pointToLayer: function (feature, latlng) {
            var circle = L.circle(latlng, 50, merge_options(cirkelOpties, {
                    fillColor: feature.properties.kleur,
                }));
            circles[feature.properties.node_id] = circle;
            }
        }
    ).addTo(kaart);
}

geojson.once('load', function(){
    // Do something with a specific circle, e.g.:

    circles[1234].remove();
});
相关问题