mapbox / mapbox/mapbox-gl-draw
Uncaught TypeError: `onUncombineFeatures` and `onCombineFeatures` is not a function in `direct_select´ draw mode
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
1. Go here: https://jsfiddle.net/u6z2a5s4/
2. Draw a polygon
3. Enter `direct_select` mode by clicking on the polygon twice.
4. Click the `combine_features` or `uncombine_features` button, and experience that there are errors in the console:
```
object_to_mode.js:61 Uncaught TypeError: i.onCombineFeatures is not a function
at Object.combineFeatures (object_to_mode.js:61:14)
```
https://github.com/mapbox/mapbox-gl-draw/blob/02c5e798377db6f11e73566450dbaad6963f11f4/src/modes/object_to_mode.js#L60-L65
I would expect the behavior of the buttons to be similar to in `simple_select` mode when having selected only one polygon: No effect, yet without uncaught type errors.
probably the safest is to solve by checking for the function before calling it:
```diff
combineFeatures() {
- mode.onCombineFeatures(state);
+ if (mode.onCombineFeatures instanceof Function ) {
+ mode.onCombineFeatures(state);
+ }
},
uncombineFeatures() {
- mode.onUncombineFeatures(state);
+ if (mode.onUncombineFeatures instanceof Function ) {
+ mode.onUncombineFeatures(state);
+ }
}
```
Further, I would also have expected such a TypeError to be detected at compilation time, since both `onCombineFeature` and `onUncombineFeature` are [well defined as optional in the DrawCustomMode interface](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mapbox__mapbox-gl-draw/index.d.ts#L265)
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
Reproduce the issue with the linked JSFiddle, then inspect src/modes/object_to_mode.js around lines 60-65, where combineFeatures and uncombineFeatures call the mode handlers. Confirm that using these controls in direct_select produces no uncaught TypeError and preserves the no-effect behavior expected for a single polygon.
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
- 55/100