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

Draw.delete programmatically is not removing features from the map

Open ghigio2000 opened this issue 6 years ago • 5 comments

Hi,

I am new to this library. I am trying to remove some features (created programmatically) using Draw.delete(id) but they are not removed from the map, even if they are no more listed in the Draw.getAll() . Any idea?

Is there a way to redraw all the features?

Thanks for your help Giorgio

ghigio2000 avatar Jan 24 '20 10:01 ghigio2000

@ghigio2000 Can you please post a minimal reproducible case as suggested in the new issue template:

  • Include a link to a minimal demonstration of the bug. We recommend using https://jsbin.com

asheemmamoowala avatar Feb 22 '20 00:02 asheemmamoowala

@ghigio2000 Can you please post a minimal reproducible case as suggested in the new issue template:

  • Include a link to a minimal demonstration of the bug. We recommend using https://jsbin.com

Not OP, but can provide a link to recreate this issue: https://jsfiddle.net/xqpuvb78/19/

Load that, click on the polygon, then click off the polygon so that no geometry is selected. The routine executed checks if selected feature count is nil and, if so, instructs Mapbox Draw to deleteAll. After doing so, the geometry remains. If you try and click on the geometry again, your web browser's console will be lit up red.

Nicksil avatar Feb 25 '20 07:02 Nicksil

Having the same issue, this is definitely a bug, and can be easily reproduced as per @Nicksil 's instructions.

hugomorg avatar Aug 04 '20 13:08 hugomorg

Having the same issue too when using it in React framework. I found that if I call deleteAll in draw.delete callback, the features are still on the map. But when I call it in click callback of a button, it works ! Finally, I use setTimeout to solve my problem temporarily like below.

map.on('draw.delete', () => {
    setTimeout(() => {
        draw.deleteAll() 
    }, 0)
})

But why ? I have no much ideas.

wisdomG avatar Dec 16 '20 07:12 wisdomG