With Leaflet markercluster, how can I switch between clustered and unclustered without changing zoom level?

时光怂恿深爱的人放手 提交于 2019-11-27 08:02:54

问题


I am using the Leaflet.markercluster plugin to cluster my points.

However, users are asking for the functionality to switch between clustered and unclustered views (basically, they want to see all their points at a high zoom).

I know that I can disable clustering at a specific zoom level:

markers = new L.MarkerClusterGroup({
    disableClusteringAtZoom: 8,
})

How can I force everything to uncluster when I am further zoomed out, though?


回答1:


You would probably be interested in Leaflet.MarkerCluster.Freezable plugin.

It provides extra methods on Leaflet.markercluster, including disableClustering() and enableClustering(), which enable you to uncluster / cluster programmatically (e.g. on a button click) without needing the user to zoom in/out.

See also the plugin demo page.

Of course, you should be careful whenever you call disableClustering(), since you may instantly load all your markers on map (if you are zoomed out to their full extent). If that tries loading thousands of markers, you may freeze your browser or even crash it.

Disclaimer: I am the author of this plugin.



来源:https://stackoverflow.com/questions/37142197/with-leaflet-markercluster-how-can-i-switch-between-clustered-and-unclustered-w

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