[英]Leaflet animated marker not displaying the latitude and longitude
I am using this code it shows the message in a popup when I remove the e.latlng.lat and + e.latlng.lng
我正在使用此代码,当我删除
e.latlng.lat and + e.latlng.lng
时,它会在弹出窗口中显示消息
var myMovingMarker = L.Marker.movingMarker([
[23.59582641820334, 58.439605236053474],
[21.5278654, 55.9196996]
], [100000], {
icon: orangeIcon
}, {
title: "MyPoint",
alt: "The Big I",
draggable: true
}, )
var popup = L.popup({
keepInView: false,
autoPan: false,
closeButton: false,
closeOnClick: true,
maxWidth: 1000
}).setContent("Lat, Lon : " + e.latlng.lat + ", " + e.latlng.lng)
myMovingMarker.bindPopup(popup).openPopup()
The variable e
is not defined.变量
e
未定义。 Additionally setContent()
set a static content, this means when you add text with setContent()
is will not updated, even if the marker latlng has changed.此外
setContent()
设置了 static 内容,这意味着当您使用setContent()
添加文本时,即使标记 latlng 已更改,也不会更新。
You have to set the content every time the popup is opened:每次打开弹出窗口时,您都必须设置内容:
myMovingMarker.on('popupopen',function(e){
var markerLatLng = e.popup._source.getLatLng();
e.popup.setContent("Lat, Lon : " + markerLatLng.lat + ", " + markerLatLng.lng)
})
Another way would be to updated the content every time the marker is moved:另一种方法是每次移动标记时更新内容:
myMovingMarker.on('move',function(e){
var markerLatLng = e.target.getLatLng();
popup.setContent("Lat, Lon : " + markerLatLng.lat + ", " + markerLatLng.lng)
})
PS: Both not tested, but should work PS:两者都没有测试,但应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.