Yo suelo:
¿Cómo hago para que los marcadores de mi capa geojson se agrupen solo si tienen el mismo valor en una propiedad? Los marcadores están localizados en cada estado de los Estados Unidos y quiero que los marcadores se agrupen solo entre marcadores del mismo estado. En la capa geojson, una propiedad indica a qué estado pertenece el marcador (feature.properties.state)
Gracias !
Simplemente haga un MarkerClusterGroup por estado:
// [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));Nota: a un nivel de zoom bajo, es probable que todos estos MCG se superpongan.