Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda