How to delete polygon coordinate/vertex/node (Google Maps V3)

editing, events, google-maps, polygon

Solution

If your Polygon is editable, you can add an event listener to the Polygon and then handle click or right clicks. For example:

poly = new google.maps.Polygon({
  editable: true
});
poly.setMap(map);
google.maps.event.addListener(poly, 'rightclick', function(event) {
  if (event.vertex == undefined) {
    return;
  } else {
    removeVertex(event.vertex);
  }
});

Above code would create a polygon and attach a event listener that catches right clicks on vertices (nodes) of the polygon and then call removeVertex function.

function removeVertex(vertex) {
  var path = poly.getPath();
  path.removeAt(vertex);
}

Similar solution can be applied for Polylines as well.

Problem

How to use the insert_at, remove_at & set_at events of the polygon. Can someone provide some sample on how to use them and what is the event argument. What i want to do now is when user draw the polygon, and double-click the node of the polygon, i want the node to be deleted from the polygon. can it be done ?

Original source

Related problems