[16:52] <BarCar> Can anybody help me understand how to add many markers from a JS array to a map with leaflet?
[16:52] <BarCar> Seems I need to create all the markers and add to a layer group in one go which doesn't lend itself to client-side iteration through an array.
[17:15] <ybon> BarCar: what your array looks like?
[17:26] <BarCar> array of location name, longitude, latitiude, description (for infobox pop up)
[17:26] <BarCar> var locations = [];
[17:27] <BarCar> locations.push(new map_location("AE-DUBAI", 25.0, 55.3, "DUBAI", "Full Address"));
[17:27] <BarCar> Repeat times several hundred locations
[17:28] <BarCar> You may be able to tell that JavaScript is not my strong suit...
[17:29] <ybon> so you just need to do: var marker = L.marker([lat, lng]).addTo(map);
[17:29] <BarCar> yeah - thanks - I figured that for basic markers
[17:29] <ybon> then if you want a popup, marker.bindPopup(you_content);
[17:29] <BarCar> but I want to group them into layers - home locations and office locations
[17:30] <ybon> I see
[17:31] <BarCar> I've been working through that but it suggests all the markers need to be defined with known names before a layer group can be created
[17:31] <BarCar> which doesn't lend itself to iterating through an array of locations
[17:32] <ybon> ah
[17:32] <ybon> no, you can use layer.addLayer(your_marker)
[17:32] <ybon> layer is your LayerGroup instance
[17:33] <BarCar> great! that's exactly what I was missing I think.
[17:33] <ybon> so you can 1. create your layer group 2. loop over your array of locations 3. for each, create the marker and add it to the layer
[17:33] <ybon> ok
[17:33] <BarCar> much much appreciated.
[17:35] <ybon> :)
Hope that helps others too. I've not tried it out yet.