mapbox-gl-draw icon indicating copy to clipboard operation
mapbox-gl-draw copied to clipboard

Don't throw error if geojsonhint fails

Open davidgilbertson opened this issue 6 years ago • 1 comments
trafficstars

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:

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.

davidgilbertson avatar Jan 27 '19 07:01 davidgilbertson

@kkaefer you may wish to close this, as @mapbox/geojsonhint has become deprecrated

ThisIsMissEm avatar May 12 '21 13:05 ThisIsMissEm