[x] GeoJSON data as a gist file or geojson.io (filename extension must be .geojson).
http://geojson.io/#id=gist:anonymous/59a73beffdced0e4f7d2d12eb271d380&map=16/-36.8815/174.8318
[x] Snippet of source code or for complex examples use jsfiddle.
http://jsbin.com/joqeraloxe/edit?html,console,output
In the above data/example app, turf-mask fails with:
Uncaught Error: Each LinearRing of a Polygon must have 4 or more Positions.
at Object.polygon (npmcdn.com/@turf/[email protected]/turf.js:599)
at buildMask (npmcdn.com/@turf/[email protected]/turf.js:20252)
at Object.module.exports [as mask] (npmcdn.com/@turf/[email protected]/turf.js:20228)
at e.<anonymous> (<anonymous>:516:23)
at e.Evented.fire (mapbox-gl.js:411)
at e._render (mapbox-gl.js:385)
From what I could tell it's the unionPolygons step where it returns a MultiPolygon but the spec at https://github.com/Turfjs/turf/blob/master/packages/turf-mask/index.js#L137 says it should only return Polygon: @returns {FeatureCollection<Polygon>} polygons only apply union if they collide
I don't have the time to investigate further and I'll workaround this issue so it's not a critical issues.
/cc @rowanwins just flagging you as you did the original implementation.
Internally this library is using union from jsts which outputs Polygon|MultiPolygon, however the MultiPolygon output isn't get handled properly.
Solution: We could use flattenEach from @turf/meta to process the unioned outputs into simple polygons.
I am having the same issue here, I can try to fix and send a PR :)
That would be great thanks @thiagoxvo , sing out if you need a hand!
Most helpful comment
I am having the same issue here, I can try to fix and send a PR :)