Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

302
Vistas
Leaflet's cluster plugin: how to group markers only when they have the same property

I use:

  • Leaflet 1.3.4
  • the cluster plugin: https://github.com/Leaflet/Leaflet.markercluster

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 !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda