I am trying to write a simple snap function to edit a polygon in Google Maps v3.9
I have several polygons on the map that can be made editable one at a time. When you make it editable, I will also add a listener to it to invoke when the vertex is being dragged.
Since there is no drag event for google.maps.Polygon , I add a mousedown listener, which checks if the vertex is under the cursor, and if it adds a mouseup listener. The code inside this mouseup listener checks the vertices of all other polygons and updates the drag vertex if a match is found.
This works well except for one problem. Validation is performed using the latLng PolyMouseEvent returned by the mouseup listener. This property indicates the location of the vertex before it is dragged, and I cannot find a way to refer to the vertex in its new position.
dragListener = google.maps.event.addListener( poly1, "mousedown", function( dragData ) { // if dragging a vertex if ( dragData.vertex != null ) { // perform snap on mouseup snapListener = google.maps.event.addListener( poly1, "mouseup", function( mouseData ) { var editingVertex = mouseData.vertex; var draggedLatLng = mouseData.latLng; // code here to compare draggedLatLng with latLng of editingVertex // and perform snap, which seems to work fine as is... } } }
Piggo source share