如何在传单弹出窗口中捕获click事件 [英] how to catch the click event on a leaflet popup

查看:95
本文介绍了如何在传单弹出窗口中捕获click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在传单地图上同时打开了多个弹出窗口,它们可以重叠.如果要单击,我想弹出一个窗口.尽管使用map.on('click', function(e) {do something;});可以毫不费力地单击地图,但弹出窗口似乎无法完成相同的操作.

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

这篇关于如何在传单弹出窗口中捕获click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆