Goal: Show markers for lat-lon positions from a CSV file. The other columns need to be placed in pop-up as attributes.
CSV file can be seen at: airport.csv
Code:
headers = ['iata', 'title', 'city', 'state', 'country'] // determined programmatically and excludes latitude longitude customLayerLocalData = L.geoJson(null, { onEachFeature: function (feature, layer) { var popupContent = ''; $.each(headers, function (h) { popupContent += feature.properties + '.' + headers[h]; if (h != headers.length - 1) { popupContent += '+' }; }); layer.bindPopup(popupContent); }, pointToLayer: function (feature, latlng) { return L.circleMarker(latlng, customMarkerOptions); } }); layerLocalData = omnivore.csv.parse(fr.result, null, customLayerLocalData).addTo(map); Problem: The pop-up shows the object:
[object Object].iata +[object Object].title +[object Object].city +[object Object].state +[object Object].country If I change: layer.bindPopup(popup content); to layer.bindPopup(eval(popup content));, it works. But, I am not happy with this solution (does not feel right). Morever, in this case new lines can't be inserted inside the custom geoJSON layer.
I'm looking for a smarter solution that can interpret the 'popupContent' and pass onto to layer.bindPopup correctly.