Skip to content

fix: ensure feature is sorted by area (asc)#1539

Open
giulianovarriale wants to merge 1 commit intomapbox:mainfrom
giulianovarriale:fix-area-sorting-on-selection
Open

fix: ensure feature is sorted by area (asc)#1539
giulianovarriale wants to merge 1 commit intomapbox:mainfrom
giulianovarriale:fix-area-sorting-on-selection

Conversation

@giulianovarriale
Copy link

@giulianovarriale giulianovarriale commented Mar 18, 2026

Fixes #1540

When multiple polygons overlap, clicking on a smaller polygon could select the larger polygon instead. The sortFeatures function was intended to sort polygons by area (smallest first), but area.geometry() was being called with a GeoJSON Feature wrapper instead of the raw geometry object. This was causing the area result to be always undefined and the sorting logic to fail.

This PR fixes the area calculation by passing feature.geometry directly, and swaps the polygon input order in the existing test so it no longer passes by coincidence. Previously, the test input was already in the expected order, so the broken sort still produced a green result.

Before fix:

before-fix.mov

After fix:

after-fix.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant