mapbox / mapbox/mapbox-gl-draw

How to exit drawing mode and hide controls without deleting polygon

Open
#1,110 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.