【问题标题】:How to add a markercluster to Mapbox StoreLocator Template如何将标记集群添加到 Mapbox StoreLocator 模板
【发布时间】:2016-05-27 10:55:32
【问题描述】:

我尝试了不同的方法来将集群与商店定位器同步。添加集群很容易,但是左侧的列表有一些问题。

我的问题是,我不确定如何集成此功能,最后商店定位器与自定义标记一起使用,并且列表以正确的方式同步。

商店定位器: https://jsfiddle.net/sd5vt439/

L.mapbox.featureLayer('examples.map-h61e8o8e').on('ready', function(e) {
    var clusterGroup = new L.MarkerClusterGroup();
    e.target.eachLayer(function(layer) {
        clusterGroup.addLayer(layer);
    });
    map.addLayer(clusterGroup);
});

【问题讨论】:

    标签: leaflet mapbox geojson marker markerclusterer


    【解决方案1】:

    好的,我试了一下,现在可以使用嵌套函数了:

    locations.on('ready', function(e) {
      var clusterGroup = new L.MarkerClusterGroup();
        e.target.eachLayer(function(layer) {
            clusterGroup.addLayer(layer);
        });
        map.addLayer(clusterGroup);
    
        locations.eachLayer(function(locale) {
        ....
    }
    

    【讨论】: