As you see in the following code, the Markers are draggable. In some cases, If a marker is dropped in a wrong area(polygon) I would like to cancel the drop event and consequently the marker come back to its original location automatically.
function placeMarker(latlng, color, isDraggable) {
var marker = new GMarker(latlng, { icon: getIcon(color), draggable: true });
map.addOverlay(marker);
GEvent.addListener(marker, "dragend", function () {
//redraw polygons again
});
GEvent.addListener(marker, "click", function () {
var latlng = marker.getPoint();
map.openInfoWindowHtml(marker.getPoint(), latlng.y + ", " + latlng.x);
});
return marker;
}
The question is how can I cancel the drag event of marker when it's already dropped in dragend
event?
Still couldn't find any solutions after these years, and yet again encountering this issue. I wish there was event.cancelDrag()
to call.
All I can think of is to check if the marker belongs to mypolygon
if not move it back to where it was before:
dragstart
save the current location as preLocation
dragend
use containsLocation(e.latLng, mypolygon)
preLocation
.google map containsLocation
google map Events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With