如何在传单弹出窗口上捕获点击事件 [英] how to catch the click event on a leaflet popup
问题描述
我在一张传单地图上同时打开了多个弹出窗口,它们可以重叠.如果单击,我想将弹出窗口置于前面.虽然我使用 map.on('click', function(e) {do something;});
在地图上点击没有问题,但我似乎无法用 a 做同样的事情弹出窗口.
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.
如何捕捉 L.Popup 上的点击事件?
How can i catch the click event on a L.Popup?
推荐答案
L.Popup 的 setContent 方法接受 HTML 元素,所以你可以这样做:
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);
参考:
https://leafletjs.com/reference.html#domutil
https://leafletjs.com/reference.html#event
这篇关于如何在传单弹出窗口上捕获点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!