0

When I'm drawing a polygon with Google Maps Api DrawingManager, I use the event listener 'polygoncomplete' to do some actions:

google.maps.event.addListener(drawingManager, 'polygoncomplete', function(poly) {
    // Some actions here...
}

Sometimes, especially using the Apple Pencil on iPadPro, the event raises even when not expected: usually it is because I place two vertex one next to the other (but not so much as expected to close polygon).

I wonder if there is a way to control the 'double-click' sensitivity to raise the polygoncomplete event, or if there is a workaround to raise the event in a custom way (ex. clicking a button).

From This question I understand (and tried too) that preventDefault and stopPropagation are not working if used in Maps Api events.

kiks73
  • 3,718
  • 3
  • 25
  • 52

1 Answers1

1

I got the same problem. When you make a double click after the first point, it automatically closes the polygon (with 2 points only). In the callback I make a check, if the points in the polygon are less than 3, do nothing. You can try it with the following code:

google.maps.event.addListener(drawingManager, 'polygoncomplete', function(poly) {
    if (poly.getPath().length < 3) {
        return;
    }

    // Some actions here...
}

It's a workaround but works for me. In my case I did that check after showing the poly to the map, so before the 'return' I remove the poly from the map, but that works for me.

Rajat Gupta
  • 568
  • 1
  • 6
  • 19
Kaloian Kunov
  • 159
  • 1
  • 8