call to draw.changeMode('simple_select') after draw.create generates range error
Hi -- I apologize in advance if this has already been covered, or if there is a way to deselect features after draw.create is fired. However, I have not been able to find the proper solution for this case.
mapbox-gl-js version: "name": "mapbox-gl", "version": "0.40.0", mapbox-gl-drawversion: "name": "@mapbox/mapbox-gl-draw", "version": "1.0.4",
Steps to Trigger Behavior
- Clone the project, install dependencies
- add map.on('draw.create', () => Draw.changeMode('simple_select')); to debug/index.html
- npm start
- open console, draw polygon.
Expected Behavior
After creating a feature, and clicking enter. The draw.create event is fired and the feature remains selected. I usually need to click on the map to move the feature to an unselected (not active) state. I proceed to draw.changeMode('simple_select') in the draw.create callback to deselect and change the mode from polygon to simple_select. I expect for any "active" feature to become "inactive"
I have called modeChange with different signature, i.e with { silent: true } as the third parameter, with { featureIds: [] } in second parameter, and various combinations, but continue to get the same behavior.
Actual Behavior
Calling draw.modeChange('simple_select') inside the callback for the fired event draw.create, I generate an endless loop where draw.create is called again after modeChange to simple_select.
Any guidance to be able to auto deselect after feature creation would be greatly appreciated.
Thanks!
I was able to get the behavior I needed by delaying the modeChange. setTimeout(() => Draw.modeChange('simple_select'), 0)
I encountered this problem now. Inside my handler for 'draw.create', I'm calling draw.modeChange('simple_select'). This in turn is firing 'draw.create', creating an endless loop. I also fixed the problem with a setTimeout. To me, it doesn't make sense to fire the 'draw.create' event on mode change. Is this intended behaviour?