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

前端 未结 1 437
无人共我
无人共我 2020-12-11 21:38

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 (

相关标签:
1条回答
  • 2020-12-11 22:09

    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.

    0 讨论(0)
提交回复
热议问题