I use:
How to do so that the markers of my geojson layer are grouped only if they have the same value on a property ? The markers are localized on each state of the United States and I want the markers to be grouped only between markers of the same state. In the geojson layer, a property indicates to which state the marker belongs (feature.properties.state)
Thanks !
Simply make one MarkerClusterGroup per State:
// [state]: mcg
const mcgDictionary = {};
L.geoJSON(myGeoJSONdata, {
onEachFeature(feature, layer) {
const state = feature.properties.state;
// Initialize a new MCG for the State, if it does not exist yet
mcgDictionary[state] ??= L.markerClusterGroup();
mcgDictionary[state].addLayer(layer);
}
});
// Do not forget to add all MCG's to the map
Object.values(mcgDictionary).forEach((mcg) => mcg.addTo(map));
Note: at low zoom level, all these MCG's will likely overlap.