When bringing GeoJSON files into Leaflet maps, I learned to addOverlay the data to the control layer toggle, defined as a global variable, following this method by @iH8:
How to add two geoJSON feature collections in to two layer groups
But, I cannot make this method work with JSON flickr photo data. In my current code, all of the photo markers appear on the map, but the toggle only controls one marker. The problem is probably in lines 25-30 of my script.js:
$.getJSON(flickrURL, function (data){
for (var i = 0; i < data.photos.photo.length; i++){
var photo_obj = data.photos.photo[i];
marker = new L.marker([photo_obj.latitude, photo_obj.longitude])
.bindPopup(popupHTML(photo_obj)).addTo(map);
}
controlLayers.addOverlay(marker, 'Flickr photos - broken button only toggles one image');
});
See demo of the problem in my Plunker: http://plnkr.co/edit/LyzCNdzWrIIQYDz4dpfJ?p=preview
Suggestions?