如何使用事件拖动标记?传单js
How to use event dragend markers? Leaflet js
我收到来自服务器的 geoJSON 格式类型 POINT 的响应。如何为标记添加 '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;
}
我收到来自服务器的 geoJSON 格式类型 POINT 的响应。如何为标记添加 '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;
}