Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rounding errors in center calculation for small layers #8784

Merged
merged 5 commits into from Feb 28, 2023

Conversation

Falke-Design
Copy link
Member

For small areas, the center was to far away of the layer. It looks like the reason are rounding errors (Thx to turf.js for the idea: https://github.com/Turfjs/turf/blob/master/packages/turf-center-of-mass/index.ts#L39). But this solution doesn't work good for normal / larger areas, so I added a check if the area of the bounds are small then 1700 it using the rounding preventing solution.

To solve this I needed to add the new function PolyUtil.centroid.

This needs merged in the main banche too.

error:
grafik

fixed:
grafik

L.polygon([[42.87097909758862, -81.12594320566181], [42.87108302016597, -81.12594320566181], [42.87108302016597, -81.12576504805303], [42.87097909758862, -81.12576504805303]]).addTo(map);

Fixes #8783

PS: I also cleaned up some unnecessary tests.

@Falke-Design Falke-Design added the blocker Critical issue or PR that must be resolved before the next release label Feb 11, 2023
@Falke-Design
Copy link
Member Author

We should release this fix. @mourner @jonkoops @IvanSanchez can you please review.

src/geometry/PolyUtil.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@jonkoops jonkoops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/geometry/LineUtil.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker Critical issue or PR that must be resolved before the next release bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltip anchor locations are incorrect for small GeoJSON polygons in 1.9.x
3 participants