Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!