mapbox / mapbox/mapbox-gl-draw

Cannot read property 'getMode' of undefined

Open
#1,007 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auto-triaged bug
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);
```

![20200827-1](https://user-images.githubusercontent.com/33017449/91416465-ffe75f80-e881-11ea-80df-4578978c6ae7.JPG)

![20200827-0](https://user-images.githubusercontent.com/33017449/91416428-f5c56100-e881-11ea-9cf0-3f5cdb274691.JPG)

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);
```
![20200827-2](https://user-images.githubusercontent.com/33017449/91417647-b435b580-e883-11ea-8c71-7d121093e392.JPG)

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.