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.
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');
}
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