Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize clustering of markers on Leaflet maps

I'm working on an app with a large number of markers and would like to cluster them. I found Leaflet.markercluster and it does a good job. However, I would like to customize the clustering of the markers. Specifically, I want to cluster my markers depending on the country they are in. I don't want a cluster which includes all markers in Europe but instead several clusters by country.

Is there any way to achieve this?

like image 998
Christoph Avatar asked Dec 22 '25 04:12

Christoph


1 Answers

You can create several clusters and add your markers to them accordingly.

var franceCluster = L.markerClusterGroup();
var germanyCluster = L.markerClusterGroup();
franceCluster.addLayer(parisMarker);
germanyCluster.addLayer(berlinMarker);

map.addLayer(franceCluster);
map.addLayer(germanyCluster);
like image 80
YaFred Avatar answered Dec 24 '25 10:12

YaFred



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!