如何使用事件拖动标记?传单js



我从服务器接收到POINT类型的geoJSON格式的响应。如何为标记添加"dragend"事件以查看坐标何时更改。我的尝试:

success: function (data) {
L.geoJSON(data, {
onEachFeature: onEachFeature
})
.on('click', markerOnClick)
.on('dragend', function(event) {
console.log('marker is dragged'); 
})
.addTo(map)
},

onEachFeature中,根据值,我将其设置为可拖动或不可

if (feature.properties.isBlocked == 0) {
layer.options.draggable = true;
}
else {
layer.options.draggable = false;
}

将侦听器移动到onEachFeature:

function onEachFeature(feature,layer){
YOUR CODE ...
if (feature.properties.isBlocked == 0) {
layer.options.draggable = true;
layer.on('dragend', function(event) {
console.log('marker is dragged'); 
})
}
else {
layer.options.draggable = false;
}

最新更新