Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygon coordinates changed/edited/moved event (Google Maps V3)

Since Google maps v3.11, it's possible to set the draggable property onto the Polygon, Circle and Rectangle. eg, new google.maps.Polygon({ draggable: true }).

For Circle and Rectangle, there are events like radius_changed,center_changed and bounds_changed for us to subscribe when there is any change.

But for Polygon, we can only subscribe the set_at,insert_at and remove_at events of polygon.getPath().

So, there will be a problem after I dragged the polygon, the position of the polygon had been changed/edited/moved, but no event to listen for this changes.

like image 696
Timeless Avatar asked Mar 22 '13 05:03

Timeless


1 Answers

There is a better way to achive this, if you want to listen to changes on the path position and new points into the path, here is the code:

place_polygon = new google.maps.Polygon({/*...*/});
var place_polygon_path = place_polygon.getPath()
google.maps.event.addListener(place_polygon_path, 'set_at', polygonChanged);
google.maps.event.addListener(place_polygon_path, 'insert_at', polygonChanged);

function polygonChanged(){
    console.log('Changed');
}
like image 80
Rodrigo Polo Avatar answered Dec 08 '22 03:12

Rodrigo Polo