zakjan / mapbox-gl-draw-geodesic

Geodesic plugin for Mapbox GL Draw
https://zakjan.github.io/mapbox-gl-draw-geodesic/
MIT License
50 stars 8 forks source link

Changing the mode from draw_circle to simple_select on event onTouchEnd throws an error #28

Open pct-elizabeta-dimovska opened 9 months ago

pct-elizabeta-dimovska commented 9 months ago

When the user draws a circle, after the shape is created the mode needs to be changed to simple select, but instead an error is thrown:

Console error console error

The code is trying to access Constants.modes.SIMPLE_SELECT mouse up event

Constant modes doesn't contain property with key SIMPLE_SELECT - it's in lower case. constants

zakjan commented 9 months ago

Hi, this works for me in the demo. Select draw_circle in the mode select, draw a circle, the mode switches back to simple_select.

Can you debug what's specific in your setup?

jparish3 commented 9 months ago

your demo throws this error with any interaction after initial draw:get_features_and_set_cursor.js:14 Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf') at N (get_features_and_set_cursor.js:14:18) at i.mouseup (events.js:63:20) at Ct.fire (evented.js:119:26) at i.fire (setup.js:53:24) at Oo.mouseup (map_event.js:38:19) at gr.handleEvent (handler_manager.js:325:58)

Davey-Hughes commented 8 months ago

Hi, I think I'm running into a similar issue. I've tried the demo as well in Chrome, Firefox, and Safari, and on Linux and MacOS. The demo for me shows non-geodesic lines whenever a mode that's not the draw_circle is selected:

image

The object also has an extra field which is "undefined".

In this code: https://github.com/zakjan/mapbox-gl-draw-geodesic/blob/master/src/modes/index.js#L11-L22 what is happening when I step through the browser's debugger is patchDrawLineString(modes[Constants.modes.DRAW_LINE_STRING]) calls the patch function with undefined presumably because Constants.modes.DRAW_LINE_STRING is undefined.

zakjan commented 8 months ago

Hi, the root cause was in incorrect reading existing mapbox-gl-draw modes after upgrading to mapbox-gl-draw 1.4.3. Fixed in https://github.com/zakjan/mapbox-gl-draw-geodesic/commit/f6ca244aa973160c69941ae4850e8d86771ec8d1 and released as 2.3.1. Could you try it?

Davey-Hughes commented 8 months ago

Hi this fix seems to work for me, thanks! I figured it was something better than my hardcoded solution but I'm not as familiar with the mapbox library.