过滤标记会为其分配新ID

时间:2014-06-25 17:53:44

标签: leaflet mapbox

我正在尝试构建一个地图,用户可以使用GeoJSON对象的某些属性过滤标记。过滤器工作正常,问题是每次我应用过滤器时,标记都会分配新ID,正如您在运行以下示例时在控制台中看到的那样:

http://jsfiddle.net/lmartins/z8wBW/

我应用过滤器的方式基本上与Mapbox示例中描述的一样:

$('.menu-ui a').on('click', function() {
    // For each filter link, get the 'data-filter' attribute value.
    var filter = $(this).data('filter');
    $(this).addClass('active').siblings().removeClass('active');

    systemLocations.setFilter(function(f) {
        // If the data-filter attribute is set to "all", return
        // all (true). Otherwise, filter on markers that have
        // a value set to true based on the filter name.
        return (filter === 'all') ? true : f.properties[filter] === true;
    });


    return false;
});

可以在此处找到Mapbox示例:https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-with-multiple-filters/

我可以通过任何方式避免更改标记ID吗?

由于

1 个答案:

答案 0 :(得分:0)

正如Ilja所说,Leaflet ID是一个内部细节 - 在Leaflet库中以_为前缀的任何东西意味着它不是外部API的一部分,而不是你可以指望保持稳定的东西。过滤标记会删除并重新创建图层,从而更改ID。最好的途径是直接在GeoJSON数据中添加ID并依赖它们。

相关问题