mapbox-gl-draw
mapbox-gl-draw copied to clipboard
Trash is disabled while programatically selecting feature from draw using direct select
I am trying to select a newly created object in draw in code.
created_ids = draw.add(draw_feature); draw.changeMode('direct_select',{featureId:created_ids[0]});
The feature gets selected,but delete does not work on clicking trash icon. When I deselect and reselect the feature using pointer delete works.
@jithintomz please provide a fiddle of this bug happening along with the versions of mapbox-gl-draw and mapbox-gl-js that you are using per the issue template.
Regards, Matthew
This happens even on the example at https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
- Draw a polygon.
- Select it.
- Press delete.
It wont work.
However, if you deselect it, then re-select it, you can delete.
Any update on this issue?
Here is the solution for deleting polygon.
created_ids = draw.add(draw_feature); draw.changeMode('simple_select',{featureIds:[created_ids[0]]});
It's working at my side, I hope it will work for you too.
FYI, it seems that not deleting a feature from direct select mode is intended behavior. However, you can override the mode's toTrash function and get it working. See this PR for how:
https://github.com/mapbox/mapbox-gl-draw/pull/975