如何在'popupopen`事件中识别Leaflet的标记? [英] How to identify Leaflet's Marker during a `popupopen` event?
问题描述
当点击标记时,我需要执行一些代码,找到与被点击的标记相对应的 id
,从后端API检索数据,然后添加新检索的数据到将打开的弹出窗口的内容
。
when a marker is clicked, I need to execute some code that finds the id
corresponding to the marker being clicked , retrieves data from backend API, then adds the newly retrieved data to the content
of the popup that will open.
唯一可以收听点击的方法标记上的事件是
The only way that is able to listen to a click event on the marker is
map.on('popupopen', function(e){
// How to retrieve marker?
// eg: Assign an id on creation, retrieve it now during popupopen
};)
如何找出这是哪个标记?是否可以为每个标记添加 id
属性,然后在期间检索此
event? id
popupopen
How can I find out which marker this is? Is it possible to add an id
attribute to each marker, then retrieve this id
during the popupopen
event?
推荐答案
事件对象包含一个popup属性,该属性具有一个名为private的属性_source是弹出窗口绑定的对象(即标记)。由于_source应该是私有的,这似乎不是正确的方式,但我不确定如何做到这一点。
The event object contains a "popup" attribute that has a private attribute called "_source" which is the object that the popup is bound to (i.e. the marker). Since _source is supposed to be private this doesn't seem like the right way but I'm not sure how else to do it.
map.on('popupopen', function(e) {
var marker = e.popup._source;
});
这篇关于如何在'popupopen`事件中识别Leaflet的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!