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

109
Views
Cluster geojson Layer no funciona con el filtrado de marcadores

Estoy haciendo un mapa de folleto con algunos datos de GeoJSON.

Intento agregar la función de clúster a mi archivo JS. Como agregué algunas funciones de filtro y estilo de acuerdo con las propiedades, no puedo encontrar la forma correcta de codificar la función de clúster.

Aquí está la capa GeoJSON y el verificador de filtros:

 const geojsonLayer = L.geoJSON(null,{ filter: (feature) => { const isYearChecked = checkboxStates.years.includes(feature.properties.year) const isEventTypeChecked = checkboxStates.eventTypes.includes(feature.properties.eventType) return isYearChecked && isEventTypeChecked }, //only true if both are true

con la función de estilo:

 var year = feature.properties.year; if (year <= -150) { return { color: "black" };

Agrego luego la ventana emergente:

 layer.bindPopup(popupText, { closeButton: true, offset: L.point(0, -10) }); layer.on('click', function() { layer.openPopup(); }); }, }).addTo(map);

Intento agregar este fragmento de código para mostrar el clúster, pero no sé dónde colocarlo en mi código para que funcione ( https://github.com/Leaflet/Leaflet.markercluster ):

 var markers = L.markerClusterGroup(); markers.addLayer(L.marker(getRandomLatLng(map))); // ... Add more layers ... map.addLayer(markers);

Mi código completo está disponible aquí: https://github.com/jandre3/pince-crochet

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una vez que haya llenado su Grupo de capas Leaflet GeoJSON (generalmente con geojsonLayer.addData(geoJsonObject) , en lugar de agregar ese grupo a su mapa, simplemente agréguelo a su MarkerClusterGroup:

 const mcg = L.markerClusterGroup().addTo(map); geojsonLayer.addData(geoJsonObject).addTo(mcg);

Si más adelante desea intercambiar el contenido, puede borrarlo de ambos grupos y repetir:

 mcg.clearLayers(); geojsonLayer.clearLayers(); geojsonLayer.addData(geoJsonObject).addTo(mcg);

Demostración: https://jsfiddle.net/hd68ea7k/

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!