mapbox / mapbox-gl-draw

Draw tools for mapbox-gl-js
https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-draw/
ISC License
953 stars 593 forks source link

The delete coordinate keybinding is broken if displayControlsDefault: false #805

Open woodpav opened 6 years ago

woodpav commented 6 years ago

mapbox-gl-js: 0.47.0 mapbox-gl-draw: 1.0.9

var draw = new MapboxDraw({ 
    displayControlsDefault: false,
    keybindings: true,
});

draw.changeMode('draw_polygon');

Steps:

1) Draw a polygon with your mouse 2) Click one of the polygon's coordinates and select it 3) Hit delete on your keyboard.

Expected:

The coordinate deletes and the polygon changes shape.

Actual:

The coordinate only deletes if displayControlsDefault: true.

Demo:

Try switching bugActive:

https://jsbin.com/gidotifaxa/1/edit?html,output

zhaozhe0831 commented 6 years ago

I have a same problem.

ShadowSonata commented 1 year ago

Can't believe we still have this issue from 2018...

A temporary solution is to enable controls and then hide it in css...

.mapboxgl-control-container {
  display: none;
}
markphillips100 commented 1 year ago

Just for added observation, I think this is more to do with which control is enabled than just if keyBindings is false. For a delete vertex to work the trash control must be enabled (which means it is visible of course under regular circumstances). If the displayControlsDefault and keyBindings are both true the trash control value determines if a delete key will work.

This snapshot demos my observation. Just change the value of trashActive to show that without it enabled you cannot delete even though the displayControlsDefault and keyBindings are active: https://jsbin.com/kocijekexo/1/edit?html,output

As @ShadowSonata explains, the solution to not show a control but still get the behaviour is to provide some css to hide the specific control icon or the whole control container.