Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/sort_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ const FEATURE_SORT_RANKS = {
Polygon: 2
};

const POINT_META_RANKS = {
vertex: 0,
midpoint: 1,
feature: 2
};

function comparator(a, b) {
const score = FEATURE_SORT_RANKS[a.geometry.type] - FEATURE_SORT_RANKS[b.geometry.type];

if (score === 0 && a.geometry.type === Constants.geojsonTypes.POLYGON) {
return a.area - b.area;
}

// Always consider vertices before midpoints!
if (score === 0 && a.geometry.type === Constants.geojsonTypes.POINT) {
return POINT_META_RANKS[a.properties.meta] - POINT_META_RANKS[b.properties.meta];
}

return score;
}

Expand Down