传单中的标记,单击事件 [英] Marker in leaflet, click event
本文介绍了传单中的标记,单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var map = L.map('map');
var marker = L.marker([10.496093,-66.881935]).on('click', onClick);
function onClick(e) {alert(e.latlng);}
marker.addTo(map)
当我点击标记时,警告信息是:undefined
When I do click in the marker, the alert message is: undefined
但如果我把它放在变量图中,它就可以了! (显示纬度和经度)
But if I put it in the variable map, it works! (shows latitude and longitude)
map.on('click', onClick);
有人知道为什么它在标记中不起作用吗?
Does someone know why it doesn't work in the marker?
推荐答案
我找到了解决方案:
function onClick(e) {alert(this.getLatLng());}
使用标记的getLatLng()方法
used the method getLatLng() of the marker
这篇关于传单中的标记,单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文