-
Notifications
You must be signed in to change notification settings - Fork 1
feat: hide non-matching trails when an activity is selected + backfill activities #457
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| -- Migration 080: Backfill and correct trail activities so the activity filter | ||
| -- (e.g. selecting "Biking") only surfaces trails that actually allow that activity. | ||
| -- | ||
| -- Three parts, all idempotent (guarded so re-runs are no-ops and so later admin | ||
| -- edits are not clobbered once a row no longer matches the known-bad state): | ||
| -- 1. Untagged trails -> 'Hiking' (most are CVNP/Metro foot trails). | ||
| -- 2. Drop 'Biking' from 11 footpaths that were mis-tagged as bikeable. | ||
| -- 3. Bikeable multi-use trails on the allowlist (Towpath, Bike & Hike, Gateway, | ||
| -- etc.) keep their existing 'Hiking, Biking' tags — no change needed. | ||
|
|
||
| BEGIN; | ||
|
|
||
| -- 1. Untagged trails -> 'Hiking' | ||
| UPDATE pois | ||
| SET primary_activities = 'Hiking' | ||
| WHERE 'trail' = ANY(poi_roles) | ||
| AND coalesce(deleted, false) = false | ||
| AND coalesce(nullif(trim(primary_activities), ''), '') = ''; | ||
|
|
||
| -- 2. Remove 'Biking' from hiking-only footpaths that were incorrectly tagged. | ||
| -- Element-wise: split on commas, drop the 'Biking' item, rejoin. Guarded by id list | ||
| -- + "still contains Biking" (Postgres word boundaries are \m \M, NOT \b), so it | ||
| -- fires once and re-runs as UPDATE 0. Gateway Trail (West Creek paved connector, | ||
| -- id 1018) and the paved/limestone multi-use trails are intentionally excluded. | ||
| UPDATE pois | ||
| SET primary_activities = ( | ||
| SELECT string_agg(trim(part), ', ') | ||
| FROM unnest(string_to_array(primary_activities, ',')) AS part | ||
| WHERE lower(trim(part)) <> 'biking' | ||
| ) | ||
| WHERE id IN (974, 1021, 1036, 1045, 1050, 1057, 1068, 1074, 1089, 1099, 1095) | ||
| AND primary_activities ~* '\mBiking\M'; | ||
|
|
||
| COMMIT; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,36 @@ export function poiMatchesActivityForTypes(poi, visibleTypes, iconConfig) { | |
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * True when the legend is narrowed to a subset of activity-bearing types | ||
| * (e.g. just "Biking") rather than showing everything. The Trails layer is only | ||
| * refined by activity while this is true; with all (or no) activity types | ||
| * selected it stays all-or-nothing, preserving plain "show me the trails" browsing. | ||
| */ | ||
| export function isActivityFilterActive(visibleTypes, iconConfig) { | ||
| if (!iconConfig || iconConfig.length === 0) return false; | ||
| let activityTypes = 0, selected = 0; | ||
| for (const icon of iconConfig) { | ||
| if (icon.enabled === false || !icon.activity_fallbacks) continue; | ||
| activityTypes++; | ||
| if (visibleTypes.has(icon.name)) selected++; | ||
| } | ||
| return selected > 0 && selected < activityTypes; | ||
| } | ||
|
|
||
| /** | ||
| * Whether a trail (linear feature) should remain visible under the current | ||
| * activity narrowing. Untagged trails always pass, so a missing tag never | ||
| * silently hides a trail; a tagged trail passes only if it matches a selected | ||
| * activity. Selecting "Biking" thus hides hiking-only trails while the trail | ||
| * layer is on. | ||
| */ | ||
| export function trailPassesActivityFilter(feature, visibleTypes, iconConfig) { | ||
| if (!isActivityFilterActive(visibleTypes, iconConfig)) return true; | ||
| if (!(feature.primary_activities || '').trim()) return true; | ||
| return poiMatchesActivityForTypes(feature, visibleTypes, iconConfig); | ||
| } | ||
|
Comment on lines
+64
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Performance & Safety Improvements
let lastVisibleTypes = null;
let lastIconConfig = null;
let lastResult = false;
/**
* True when the legend is narrowed to a subset of activity-bearing types
* (e.g. just "Biking") rather than showing everything. The Trails layer is only
* refined by activity while this is true; with all (or no) activity types
* selected it stays all-or-nothing, preserving plain "show me the trails" browsing.
*/
export function isActivityFilterActive(visibleTypes, iconConfig) {
if (!iconConfig || iconConfig.length === 0) return false;
if (!visibleTypes || typeof visibleTypes.has !== 'function') return false;
if (visibleTypes === lastVisibleTypes && iconConfig === lastIconConfig) {
return lastResult;
}
let activityTypes = 0, selected = 0;
for (const icon of iconConfig) {
if (icon.enabled === false || !icon.activity_fallbacks) continue;
activityTypes++;
if (visibleTypes.has(icon.name)) selected++;
}
lastVisibleTypes = visibleTypes;
lastIconConfig = iconConfig;
lastResult = selected > 0 && selected < activityTypes;
return lastResult;
}
/**
* Whether a trail (linear feature) should remain visible under the current
* activity narrowing. Untagged trails always pass, so a missing tag never
* silently hides a trail; a tagged trail passes only if it matches a selected
* activity. Selecting "Biking" thus hides hiking-only trails while the trail
* layer is on.
*/
export function trailPassesActivityFilter(feature, visibleTypes, iconConfig) {
if (!feature) return false;
if (!isActivityFilterActive(visibleTypes, iconConfig)) return true;
if (!(feature.primary_activities || '').trim()) return true;
return poiMatchesActivityForTypes(feature, visibleTypes, iconConfig);
} |
||
|
|
||
| export function getIconUrlForPOI(poi, iconConfig, poiType) { | ||
| if (poiType === 'trail') return '/icons/layers/trails.svg'; | ||
| if (poiType === 'river') return '/icons/layers/rivers.svg'; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a trail only has
'Biking'as its primary activity, removing'Biking'will cause the subquery to returnNULL. This would setprimary_activitiestoNULL(or empty), which in the frontend is treated as an untagged trail. Since untagged trails always pass the activity filter, this trail would incorrectly continue to show up when the "Biking" filter is active.To prevent this, we should fallback to
'Hiking'if removing'Biking'leaves the activities list empty.