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

119
Visualizações
How can I get Leaflet markerClusters to work with reading data from CSV with PapaParse?

I am trying to combine directions from two Leaflet tutorials:

  1. Getting marker data from CSV using PapaParse: https://github.com/HandsOnDataViz/leaflet-map-csv
  2. Clustering tutorial: https://asmaloney.com/2015/06/code/clustering-markers-on-leaflet-maps/

and here is what I have:

//create cluster group
var markerClusters = L.markerClusterGroup();

// Read markers data from data.csv
$.get('./data_jittered.csv', function(csvString) {
  
// Use PapaParse to convert string to array of objects
var data = Papa.parse(csvString, {header: true, dynamicTyping: true}).data;
// For each row in data, create a marker and add it to the map
// For each row, columns `Latitude`, `Longitude`, and `Title` are required
for (var i in data) {
  var row = data[i];

  var marker = L.marker([row.New_Lat, row.New_Long], {
    opacity: 1
  }).bindPopup(row.Title);      
  marker.addTo(map);
  markerClusters.addLayer(marker);
 
}
map.addLayer(markerClusters);

Currently, the markers are loading but the clustering function is not working: https://maggiehm.github.io/nzamorawilson-map/

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

marker.addTo(map);

was the issue. I followed the example provided by Dom in the comments here: stackoverflow.com/a/66616249/10684798

and updated the code (with simplified variables) to:

var markers = L.markerClusterGroup();

$.get('./data_jittered.csv', function(csvString) {
  
var data = Papa.parse(csvString, {header: true, dynamicTyping: true}).data;
for (var i in data) {
  var row = data[i];
  var marker = L.marker([row.New_Lat, row.New_Long], {
      opacity: 1
  }).bindPopup(row.Title);      
  markers.addLayer(marker);
}
});
map.addLayer(markers)

The clustering function works now: https://maggiehm.github.io/nzamorawilson-map/

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