mapbox / mapbox/mapbox-gl-draw

After entering draw_point mode with no features, getAll() returns a Point with no coordinates

Open
#774 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api bug
Dominant language
JavaScript
Stars
1.1k
Forks
612
Avg merge
8d 9h
Merged PRs (30d)
5

Description

**mapbox-gl-js version**: 0.44.2
**mapbox-gl-draw version**: 1.0.7

### Steps to Trigger Behavior

Do something like this:

```
map.addControl(draw);
draw.set({type: 'FeatureCollection', features: []});
draw.changeMode('draw_point');
console.log(draw.getAll());
```

jsbin: https://jsbin.com/hecipexiju/1/edit?html,output

### Expected Behavior

I would have expected `draw.getAll()` to return an empty `FeatureCollection`.

### Actual Behavior

I get a `FeatureCollection` with one feature, which is a `Point` with an empty array as `coordinates`, which is invalid GeoJSON. I have to manually filter such points out of the object before passing them downstream, otherwise calculations fail.

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 reproducing the issue with the draw.set and draw.changeMode('draw_point') calls shown in the report, then trace the draw_point mode and draw.getAll() entry points. Confirm that an empty drawing returns an empty FeatureCollection rather than a Point with empty coordinates, and add or update coverage if the repository has relevant tests.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.