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

Firing an action if user clicks the trash control regardless of selection

Open KayBeSee opened this issue 7 years ago • 4 comments

Mapbox GL Version: 0.45.0 Mapbox GL Draw Version: 1.0.9

Steps to Trigger Behavior

  1. 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!

KayBeSee avatar Aug 30 '18 21:08 KayBeSee

Hi, did you find out how to do this?

benderlidze avatar Jan 20 '19 10:01 benderlidze

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 avatar Jan 21 '19 12:01 KayBeSee

@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.

dcdenu4 avatar Oct 18 '21 21:10 dcdenu4