mapbox / mapbox/mapbox-gl-draw
Don't throw error if geojsonhint fails
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
**mapbox-gl-js version**: 0.52.0
**mapbox-gl-draw version**: 1.1.1
### Steps to Trigger Behavior
1. Add some geojson (with `draw.add()`) that gets errors with `geojsonhint`.
### Expected Behavior
Often, geojson will fail geojsonhint but still be displayable. In these cases, it is preferable to see the geojson than it is to just get a console error and see nothing.
### Actual Behavior
The operation fails and I can't see my data.
### Suggestion
Instead of throwing an error, just log one, like so:
```js
const errors = geojsonhint.hint(geojson, { precisionWarning: false }).filter(e => e.level !== 'message');
if (errors.length) {
console.error('There were errors parsing your geojson, it may not display correctly', errors);
}
```
You could even throw up an `alert` if you were _really_ worried about accidentally misrepresenting some data.
I'm sorry I don't have an example, I only have a 20 MB file. In this file, two of the 38,000 features fail with the error "a LinearRing of coordinates needs to have four or more positions". I have no idea how I would even find these. But if I disable the error throwing I can load the file just fine and render the file to the map.
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
Start at the draw.add() path and find where geojsonhint.hint() errors are handled. Verify that invalid-but-displayable GeoJSON is still rendered while the validation problem is logged instead of stopping the operation; add or update a focused test if the relevant test location is found.
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
- Mostly clear
- Newbie friendliness
- 45/100