Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API rectangle bounds_changed event firing on resize and move

Tags:

google-maps

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?

like image 454
Darwin Tech Avatar asked Oct 24 '25 00:10

Darwin Tech


2 Answers

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.

like image 158
Nitin Avatar answered Oct 26 '25 08:10

Nitin


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.

like image 30
Dr.Molle Avatar answered Oct 26 '25 07:10

Dr.Molle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!