How to identify Leaflet#39;s Marker during a `popupopen` event?(如何在“popupopen事件期间识别 Leaflet 的标记?)
问题描述
当一个标记被点击时,我需要执行一些代码,找到与被点击的标记对应的 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
属性,然后在 popupopen
事件期间检索此 id
?
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"属性,该属性具有一个名为_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 的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在“popupopen"事件期间识别 Leaflet 的标记?
基础教程推荐
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01