Nyx*_*nyx 18 javascript gis jquery openstreetmap leaflet
单击标记时,我需要执行一些代码,找到id
与被单击的标记对应的代码,从后端API检索数据,然后将新检索的数据添加到content
将打开的弹出窗口中.
能够在标记上收听点击事件的唯一方法是
map.on('popupopen', function(e){
// How to retrieve marker?
// eg: Assign an id on creation, retrieve it now during popupopen
};)
Run Code Online (Sandbox Code Playgroud)
我怎样才能找出这是哪个标记?是否可以为id
每个标记添加属性,然后id
在popupopen
事件期间检索它?
InP*_*uit 26
事件对象包含一个"popup"属性,该属性具有一个名为"_source"的私有属性,该属性是弹出窗口绑定的对象(即标记).由于_source应该是私有的,这似乎不是正确的方式,但我不确定如何做到这一点.
map.on('popupopen', function(e) {
var marker = e.popup._source;
});
Run Code Online (Sandbox Code Playgroud)