Add Nearest to me to every list's sort control

Choosing it asks the browser for the visitor's position once and orders the list by straight-line
distance to the nearest point of each trail's track on the overview map (or its start and end,
where it has no track), shown on each row in miles or kilometres. The position stays in the page:
it is not stored, sent or put in the address. Trails with no position go last and are counted;
a refused or failed request puts the list back in its earlier order with a plain line.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-19 14:09:16 -07:00
1 parent 3ff2281129
commit d89a5f0da7
4 files changed
+391 -7

No files matched your search

+5 -1
View File
@@ -489,6 +489,10 @@ SAVED_ORDER = ("saved", "Order saved")
HERE_ORDER = "here"
# The last order of every list: nearest to the visitor. app.js asks the browser for the position when
# it is chosen and keeps it in the page only; it is never in the address, so no list opens in it.
NEAREST = ("nearest", "Nearest to me")
def sort_select(default_sort="name", saved=False, ranked="", wholly=None):
"""The one sort control of every list of trails, with the page's
@@ -510,7 +514,7 @@ def sort_select(default_sort="name", saved=False, ranked="", wholly=None):
default_sort = facets.normalize_sort(default_sort)
options = "".join(
f'\n <option value="{esc(k)}"{" selected" if k == default_sort else ""}>{esc(label)}</option>'
for k, label in sorts)
for k, label in tuple(sorts) + (NEAREST,))
return f"""<label class="results-sort"><span class="results-sort__label">Sort by</span>
<select class="select" id="sort" name="sort" data-sort-select>{options}
</select>