mapbox / mapbox/mapbox-gl-draw
Cannot read property 'getMode' of undefined
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
### Cannot read property 'getMode' of undefined at MapboxDraw.__webpack_exports__.default.api.getMode
**mapbox-gl-js version**: 1.12.0
**mapbox-gl-draw version**: 1.2.0
```
draw.current = new MapboxDraw({
displayControlsDefault: false,
styles: drawingStyle,
modes:
{
...MapboxDraw.modes,
[MapConstants.drawingTypeOption.freehand]: FreeDraw,
lots_of_points: LotsOfPointsMode,
}
});
console.log('draw.current.getMode', draw.current.getMode(), MapboxDraw.modes)
map.addControl(draw.current);
```


https://github.com/mapbox/mapbox-gl-draw/blob/main/src/setup.js
the 'ctx' object missing events
add this line to solve this problem:
```
ctx.events = events(ctx);
```

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
Open src/setup.js and reproduce the initialization shown in the issue, focusing on the ctx object and the getMode call before the control is added. Verify that the reported undefined-property error no longer occurs and that the initialization remains compatible with the custom modes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100