The console show this error: "spots is not defined"
How can I use my layerGroup spots
outside of the function?
$.get("./data.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.Latitude, row.Longitude], {
opacity: 1,
}).bindPopup(row.Name);
var spots = L.layerGroup([marker]);
}
});
var overlaySpots = {
"Some name": spots,
};
L.control.layers(null, overlaySpots).addTo(map);
spots.addTo(map);