draw.create fired before map click event
mapbox-gl-js 2.14.1: mapbox-gl-draw 1.4.1:
Steps to Trigger Behavior
when double clicking to complete a polygon, the draw.create event is fired before the second click event is fired.
- go to https://jsfiddle.net/dnltbrca/sdv4w16L/
- open the browser console
- draw a polygon and complete it by double clicking
Expected Behavior
the console shows the order of the events: clicked, clicked, drawing created
Actual Behavior
the order is clicked, drawing created, clicked
This is important because it can be architecturally undesirable to remove click handlers and then add them back after the drawing is finished. We used a flag to simply ignore these click events, but since the flag is disabled when the drawing is created the second click events does not get ignored.
This is important because it can be architecturally undesirable to remove click handlers and then add them back after the drawing is finished. We used a flag to simply ignore these click events, but since the flag is disabled when the drawing is created the second click events does not get ignored.
I worked around this by:
- taking off the undesired click handler during the
draw.createevent - in the
draw.createevent, add a one-time event handler to themap.once("click", ...)handler that adds the handler removed in 1 back to the map
It's hacky but it seems to have worked. It prevents the non-draw click handler from picking up the event from the click that finished the polygon