1 回答
TA贡献1995条经验 获得超2个赞
问题是,当您在侦听器中添加一个函数并将其添加到该函数时,()它会直接执行,而不是在执行侦听器时执行。
所以正确的是:_newMarker.addEventListener('click', markerDetails)
将您的代码更改为:
for (obj in Allpoints){
_newMarker = L.marker(Allpoints[obj].LatLong,
{title: Allpoints[obj].names,
riseOnHover: true,
},
).addTo(mymap);
_newMarker.data = Allpoints[obj]; // save the objectData on the marker
allMarkers.push(_newMarker);
_newMarker.on('click', markerDetails);
}
function markerDetails(e){
var currentMarker = e.target;
var obj = currentMarker.data; //your objectData
$("#returnControlName").html(currentMarker.controlName);
$("#returnControlEastings").html(controlEastings);
$("#returnControlNorthings").html(controlNorthings);
}
添加回答
举报