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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With