Firing an action if user clicks the trash control regardless of selection
Mapbox GL Version: 0.45.0 Mapbox GL Draw Version: 1.0.9
Steps to Trigger Behavior
- Click trash icon
Expected Behavior
Event to fire
Actual Behavior
No change or action fired
--
Hello --
I was wondering if an action fires when a user clicks the trash can icon when there is nothing selected.
I have a very simple mapbox draw component that users can draw a single polygon on. I am noticing that they are clicking the trash icon without selecting their polygon. I am wondering if an action fires when they click the trash (or how I can set one up) so that it will call deleteAll().
Either that or is there a way to modify the css of the trash icon when nothing is selected so I can make it look disabled?
Thanks!
Hi, did you find out how to do this?
I ended up using React state and an updateMap function to keep track of if a polygon existed and if I had coordinates drawn on the map. If that was the case, I was able to use Draw.getAll() and then run delete.
if (this._Draw && this._Draw.getAll().features.length > 0) {
this._Draw.deleteAll();
this.setState({ polygonSelected: false, currentPolygon: null });
}
@KayBeSee , did you end up bailing on using the Trash icon and draw.delete handler then? Did you roll your own trash button? I'm having the same issue of users wanting to "delete all" when nothing is selected and the Trash icon button not triggering any action.