Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet MarkerCluster stop auto re-clustering when zooming

When you zoom in and out, the markerclusters automatically "re-cluster", as in it calculates clustering again.

Is there an option for to disable the auto re-cluster when the zoom is changed?

like image 744
Valachio Avatar asked Dec 14 '25 04:12

Valachio


1 Answers

Depending on exactly what you are trying to achieve, you might be interested in Leaflet.MarkerCluster.Freezable subplugin:

When frozen / disabled, clusters will no longer split / merge on map zoom, but retain their status as if they were on the specified zoom level.

For example if you want the clusters to reflect the zoom 15 configuration:

var map = L.map("map"),
  mcg = L.markerClusterGroup(options);

mcg.addLayers(arrayOfMarkers);
mcg.addTo(map);

mcg.freezeAtZoom(15);

Disclaimer: I am the author of that subplugin.

like image 57
ghybs Avatar answered Dec 16 '25 07:12

ghybs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!