mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

call to draw.changeMode('simple_select') after draw.create generates range error

Open locomotif opened this issue 8 years ago • 2 comments

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

  1. Clone the project, install dependencies
  2. add map.on('draw.create', () => Draw.changeMode('simple_select')); to debug/index.html
  3. npm start
  4. 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!

locomotif avatar Dec 09 '17 01:12 locomotif

I was able to get the behavior I needed by delaying the modeChange. setTimeout(() => Draw.modeChange('simple_select'), 0)

locomotif avatar Dec 09 '17 09:12 locomotif

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?

Kolbein avatar Aug 13 '24 07:08 Kolbein