How to trigger events when drawing a polygon at the data level of Google Maps

When drawing a polygon on a Google Maps Data Layer, I want to handle events when the user draws the first, second and subsequent points so that the user interface can give different instructions for the user, such as:

  • no dots drawn: "click to draw first point"
  • extracted first point: "click to draw next point"
  • second point made: "click to add another point or click on the first point to the end"

When a close point is drawn on the data layer using the data library, the addfeature event occurs. When the last point is drawn using the drawing library, there are various events, such as a polygon.

To find out if any events are emitted for the first, second, and subsequent points, I used a sample Google code to display all the events and changed it to handle drawing events at the data level. New Events:

'addfeature': 'data layer event', 'click': 'data layer event', 'dblclick': 'data layer event', 'mousedown': 'data layer event', 'mouseout': 'data layer event', 'mouseover': 'data layer event', 'mouseup': 'data layer event', 'removefeature': 'data layer event', 'removeproperty': 'data layer event', 'rightclick': 'data layer event', 'setgeometry': 'data layer event', 'setproperty': 'data layer event', 'circlecomplete': 'This event is fired when the user has finished drawing a circle', 'markercomplete': 'This event is fired when the user has finished drawig a marker', 'overlaycomplete': 'This event is fired when the user has finished drawing an overlay of any type', 'polygoncomplete': 'This event is fired when the user has finished drawing a polygon', 'polylinecomplete': 'This event is fired when the user has finished drawing a polyline', 'rectanglecomplete': 'This event is fired when the user has finished drawing a rectangle' } 

http://jsfiddle.net/bunjil/gfp9qntx/9/

The event listener has also been expanded to also listen to data-level events, not just map events.

If you look at the events that were triggered and check the documentation that appears, there is no event to add points when drawing a new polygon, just a mouse event at the data level.

Although one could count mouseup events, this might not be a reliable solution.

I see that when adding or moving vertices there are several events on polygons and polylines, but they seem to exist only after creating a polygon.

Can anyone confirm whether this understanding is correct, or if there are events that I am missing something.

There is a related question that seems to confirm that there are no events at the data or map level, but you can listen to mouse events on the canvas. How can I listen to the beginning of a user drawing a polygon in Google Maps v3?

+5
source share

Source: https://habr.com/ru/post/1239965/


All Articles