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

How to add custom code to trash button click?

Open benderlidze opened this issue 7 years ago • 4 comments

Hi, this code fires on standard "zoom in/out etc." mapbox controls, but nothing happens on draw trash icon click. Any thoughts how to access "trash" icon click event? Thanks

    document.querySelector("#map").addEventListener("click", function (e) {
      console.log('', this, e);
      //mapbox-gl-draw_ctrl-draw-btn mapbox-gl-draw_trash
    })

benderlidze avatar Jan 20 '19 10:01 benderlidze

map.on('draw.delete', function (e) {
  console.log('deleted');
});

fxi avatar Mar 07 '19 13:03 fxi

deleteFeature(){
    let _id = this.draw.getSelectedIds();
    this.draw.delete(_id)
}

You can bind this function on your custom button

q869939686 avatar Mar 11 '19 06:03 q869939686

looks like this question was answered

kkaefer avatar Jan 07 '20 14:01 kkaefer

This won't fire if there is nothing to delete

SnakeO avatar Sep 28 '21 15:09 SnakeO