Skip to content

Commit e59a657

Browse files
ajrothwellclaude
andcommitted
sort popup features by configurable field
Add popupSortField and popupSortOrder to PopupConfig and PopupOverride. When set, features within the same layer are sorted by that field after deduplication. Defaults to descending (newest first). Enables PlowPHL treatments to display most recent first instead of arbitrary order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 346d542 commit e59a657

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/components/MapPanel.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ interface PopupFeature {
692692
title: string;
693693
fields: PopupField[];
694694
showTime?: boolean;
695+
popupSortField?: string;
696+
popupSortOrder?: "asc" | "desc";
695697
} | null;
696698
}
697699
@@ -891,6 +893,20 @@ function handleLayerClick(e: { lngLat: { lng: number; lat: number } }) {
891893
892894
if (newFeatures.length === 0) return;
893895
896+
// Sort features within the same layer by popupSortField if configured
897+
// (e.g., PlowPHL treatments sorted newest-first by time_visited_utc)
898+
newFeatures.sort((a, b) => {
899+
// Only sort features from the same layer
900+
if (a.layerId !== b.layerId) return 0;
901+
const sortField = a.popupConfig?.popupSortField;
902+
if (!sortField) return 0;
903+
const valA = a.properties[sortField];
904+
const valB = b.properties[sortField];
905+
if (valA == null || valB == null) return 0;
906+
const order = a.popupConfig?.popupSortOrder === "asc" ? 1 : -1;
907+
return valA < valB ? order : valA > valB ? -order : 0;
908+
});
909+
894910
popupFeatures.value = newFeatures;
895911
currentFeatureIndex.value = 0;
896912
popupLngLat.value = [e.lngLat.lng, e.lngLat.lat];

src/types/layer.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export interface PopupConfig {
2626
title: string;
2727
fields: PopupField[];
2828
showTime?: boolean;
29+
/** Sort popup features by this field when multiple features are at the click point */
30+
popupSortField?: string;
31+
/** Sort order: "desc" for newest-first, "asc" for oldest-first (default: "desc") */
32+
popupSortOrder?: "asc" | "desc";
2933
}
3034

3135
/**
@@ -65,6 +69,8 @@ export interface LayerConfig {
6569
*/
6670
export interface PopupOverride {
6771
showTime?: boolean;
72+
popupSortField?: string;
73+
popupSortOrder?: "asc" | "desc";
6874
}
6975

7076
/**

0 commit comments

Comments
 (0)