Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps api v3 polygon edit event not fired on all handles

I have a drawingManager that allows the user to draw a polygon. When the user is done drawing that polygon, I calculate the area of that polygon. All of this works perfectly except for editing the polygon event handling. I use the following code

google.maps.event.addListener(path, "set_at", function(){
    //my code here
});

So this sort of works but only works for the "corners" of the polygon. There are intermediary, barely visible edit handles (squares) in between the main white handles. If I edit the polygon by pulling one of these handles, the event does not fire.

Any ideas on this behavior? Is this intended or some sort of bug with the api or my code?

Thank you for any help.

Greg

like image 265
geraldcor Avatar asked Apr 04 '12 19:04

geraldcor


1 Answers

The "set_at" event is triggered when a LatLng on a path is updated. This occurs when you move those existing square nodes (changing the LatLng of that node). The 'slightly greyed out squares' on the edges of overlays allow the user to add new LatLngs to the path, rather than edit an existing one (you will notice moving a greyed out node with create another corner). In this case, add an eventListener for "insert_at" instead of "set_at" to handle when new LatLngs are added to the shapes path.

like image 168
techshaman Avatar answered Nov 11 '22 07:11

techshaman