how to catch the click event on a leaflet popup

怎甘沉沦 提交于 2019-12-31 02:54:45

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/20848786/how-to-catch-the-click-event-on-a-leaflet-popup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!