Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to catch the click event on a leaflet popup

Tags:

leaflet

I'm having multiple popups on a leaflet map open at the same time, and they can overlap. I want to bring a popup to front if clicked on. While I have no trouble getting the click on the map with map.on('click', function(e) {do something;}); I can't seem to do the same thing with a popup.

How can i catch the click event on a L.Popup?

like image 809
Rudi Avatar asked Dec 30 '13 22:12

Rudi


1 Answers

The setContent method of L.Popup accepts HTML elements so you could do something like this:

var content = L.DomUtil.create('div', 'content'),
    popup = L.popup().setContent(content);

L.DomEvent.addListener(content, 'click', function(event){
    // do stuff
}, context);

Reference:

https://leafletjs.com/reference.html#domutil

https://leafletjs.com/reference.html#event

like image 141
iH8 Avatar answered Oct 06 '22 10:10

iH8