I have a editable polygon and I want to listen to events when a vertex is dragged(polygon resized) . Normally attaching the paths to 'set_at' event is good but it fires a lot of events when the whole polygon is dragged.
google.maps.event.addListener(polygon, 'dragend', function(){search();});
google.maps.event.addListener(polygon.getPath(), 'insert_at', function(e, e1){search();});
google.maps.event.addListener(polygon.getPath(), 'remove_at', function(e, e1){search();});
//this also fires a lot of events when ploygon is dragged
google.maps.event.addListener(polygon.getPath(), 'set_at', function(){search();});
What I want to achieve is have an event something like "shape_changed" which doesn't fire events when it is dragged.
Remove the set_at
-listener on dragstart
and re-assign the set_at
-listener on dragend
Another option is to set a flag at dragstart and at dragend, and have your set_at listeners look at that flag before doing anything:
polygon.addListener('dragstart', function (event) {
dragging = true;
});
polygon.addListener('dragend', function (event) {
//do drag end stuff here
dragging = false;
});
//setup resize handler
var paths = polygon.getPaths();
paths.forEach(function (path) {
path.addListener('set_at', function (event) {
if (!dragging) //ignore this event while dragging
//do resize stuff here
});
});
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