I am working with the GoogleMaps API and I'm trying to distinguish between a rectangle object being resized or moved.
I am using the listener like so:
google.maps.event.addListener(newShape, 'bounds_changed', function() {
// do stuff
});
However, this will fire when the rectangle is resized AND when it is moved completely. Is there some way to distinguish between these two distinct events?
I tried the way @Darwin has suggested. When we just begin to drag the coordinates still remain the same and so the event is fired for drag as well as bounds_changed
An easier and more reliable way, I did is to have a global variable called isBeingDragged and set it to true in dragstart event handler. In the bounds_changed event handler, I checked if this variable is true. If it is not, its a resize event, else it is a drag event.
I again set the isBeingDragged variable to false in drag_end event handler.
Store the bounds of the rectangle initially, when the event fires check if both(soutWest and NorthEast) have been changed. When It does , the rectangle has been moved, otherwise it has been resized.
After the check update the stored bounds.
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