mapbox / mapbox/mapbox-gl-draw
How to exit drawing mode and hide controls without deleting polygon
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
**mapbox-gl-js version**: 2.1.1
**mapbox-gl-draw version**: 1.3.0
### Steps to Trigger Behavior
```
this.draw = new window.MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
trash: true
},
defaultMode: 'draw_polygon'
})
```
```
enableDrawTools() {
if (!this.compMap.hasControl(this.draw)) {
this.compMap.addControl(this.draw)
}
},
disableDrawTools() {
if (this.compMap.hasControl(this.draw)) {
this.compMap.removeControl(this.draw)
}
},
```
I have a custom button overlay that switches between placing markers and drawing outlines. I thought removing the control would hide the drawing buttons, which it does, but it also deletes the polygon I created.
How do I exit drawing mode and hide the controls, without deleting the polygon?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the MapboxDraw control lifecycle around addControl, removeControl, and the configured defaultMode. Reproduce the polygon workflow with the shown MapboxDraw options and determine whether hiding controls can be separated from removing the control without deleting the polygon; document the supported behavior or required change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100