How to apply leaflet marker cluster using layers

给你一囗甜甜゛ 提交于 2019-12-02 09:15:57

Like for Leaflet.markercluster, you have to create a Marker Cluster Group where your sub-groups will go into.

In the case of Layer Support, you create a Marker Cluster Group with Layer Support instead:

var mcg = L.markerClusterGroup.layerSupport().addTo(map);

Then you "check in" the sub-groups, so that they know they have to go into that clustering group rather than directly to the map, when they are selected through the Layers Control:

mcg.checkIn([
    sitios,
    pueblo,
    gas
]);

Demo: http://plnkr.co/edit/CT3E63AKWze34FqUoiHn?p=preview

Note: you should download the JavaScript file leaflet.markercluster.layersupport-src.js, if not already done, and place it next to your HTML page, so that it can refer to it locally.

Note 2: if your usage requires only compatibility of clustering with L.Control.Layers, you might be interested in this more simple plugin: Leaflet.FeatureGroup.SubGroup.

Disclaimer: I am the author of these plugins.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!