A popup won't open until the data file has loaded and the layer is added to the map – that's pretty obvious. I figured it would help to bind it to the 'add' event – but that never fires:
var l1 = omnivore.kml('data/Niveauregulering01a.kml');
var pop = '<img src="content/img/whatever.jpg" alt="..." style="width:300px;"/>'
l1.on('add', function(){
console.log('add');
l1.openPopup();
});
l1.bindPopup(pop).addTo(map);
There seems to be no other event that I can bind it to:
http://leafletjs.com/reference.html#path-add
Any suggestions?
Best Answer
You can try:
You should bind the event to the map object.
/**UPDATE****/
You cannot bind the popup directly to
omnivore.kml
, according to their docs the returned object is aL.geoJson()
layer -- so a pool of features.Try to bind the popup on each feature: