mapbox / mapbox/mapbox-gl-draw
Drawn polygons do not have the correct winding number per RFC7946
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
[The RFC for GeoJSON](https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6) is clear about the winding order of the points of a polygon: relevant bullet points from the linked section are:
- A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.
- For type "Polygon", the "coordinates" member MUST be an array of linear ring coordinate arrays.
That is, the boundary ring of points for a polygon must be in counter-clockwise order.
However, in version 1.3.0 of mapbox-gl-draw, drawing a triangle in either direction (clockwise or counter-clockwise) causes the feature gotten on the `draw.create` event to have points in the same ordering as drawn, which is illegal GeoJSON, since the RFC mandates the winding order.
A relevant issue is #128, and it's worth noting that the issue predates the RFC linked at the top of this issue. An earlier draft of the RFC ([found here](https://datatracker.ietf.org/doc/id/draft-butler-geojson-00.txt)) does _not_ contain the winding order requirement, which is probably the reason why `mapbox-gl-draw` doesn't conform to it 😆. Some commenters in the linked issue also claim that the winding order does not matter "In the GeoJSON spec", but I don't know which spec they are referring to. I suspect it is the draft, since the RFC explicitly mentions the difference in winding order between the two.
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 by reviewing the draw.create event behavior described here, then compare it with RFC7946 section 3.1.6 and the related issue #128. Confirm how polygon rings are ordered when drawn in either direction. Done means emitted Polygon coordinates follow the required counter-clockwise exterior-ring winding order.
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
- Mostly clear
- Newbie friendliness
- 35/100