Give trail pages an outdoor map
Mirror to forge / mirror (push) Canceled after 0s
Validate / validate (push) Canceled after 0s
Validate / site (push) Canceled after 0s
Validate / deploy (push) Canceled after 0s

Trail maps now open on an outdoor style of our own, drawn on the same
OpenFreeMap tiles: hill shading and contour lines from the public
Terrain Tiles, woods, water, footpaths, and peaks with their heights.
Heights and contours follow the visitor's units. A switch on the map
goes back to the plain map and is remembered.

The home page's overview map is unchanged. If the elevation tiles or
the contour script fail, the map still loads without them.

The security policy allows the one elevation-tile path. The contour
add-on (maplibre-contour 0.1.1) is vendored with its licence, and the
elevation data is credited on the map, under it and in the footer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-15 13:26:45 -07:00
1 parent 540a3220be
commit ad2223f427
15 files changed
+994 -27

No files matched your search

+24
View File
@@ -183,6 +183,30 @@ def plate(rec, *, size="", link=False, eager=False, alt=None):
return Markup(f'<div class="{cls} plate--none" aria-hidden="true"><span>{inner}</span></div>')
# Map credits. The base map is OpenFreeMap on every map. The trail maps add
# relief and contours drawn from the Terrain Tiles elevation data: their credit
# is the one tools/elevation.py gives (ATTRIBUTION; test_pages checks the two
# agree), plus Mexico, which the maps near the border show.
BASE_MAP_CREDIT = Markup("OpenFreeMap, &copy;&nbsp;OpenMapTiles, data &copy;&nbsp;OpenStreetMap contributors.")
ELEVATION_CREDIT = (
"Terrain Tiles, accessed from https://registry.opendata.aws/terrain-tiles. "
"United States 3DEP (formerly NED) and global GMTED2010 and SRTM terrain data "
"courtesy of the U.S. Geological Survey. Canada terrain data contains "
"information licensed under the Open Government Licence - Canada. ArcticDEM "
"terrain data DEM(s) were created from DigitalGlobe, Inc., imagery and funded "
"under National Science Foundation awards 1043681, 1559691, and 1542736. "
"Global ETOPO1 terrain data U.S. National Oceanic and Atmospheric "
"Administration."
)
MAP_ELEVATION_CREDIT = ELEVATION_CREDIT + " Mexico terrain data source: INEGI, Continental relief, 2016."
# The trail maps' own caption line: the full credit of everything they can draw.
TRAIL_MAP_CREDIT = Markup(f"Base map: {BASE_MAP_CREDIT} Relief and contours: {esc(MAP_ELEVATION_CREDIT)}")
# The site footer's short form; the elevation figures on every list come from the same data.
FOOTER_MAP_CREDIT = Markup(
f"Base maps: {BASE_MAP_CREDIT} Elevation, relief and contours: Terrain Tiles, with data courtesy of "
"the U.S. Geological Survey, NOAA, ArcticDEM and INEGI; Canada terrain data under the Open Government "
"Licence - Canada. The full credit is under each trail map.")
SWATCH_LINE = Markup('<span class="swatch swatch--line" aria-hidden="true"></span>')
SWATCH_ROUTE = Markup('<span class="swatch swatch--route" aria-hidden="true"></span>')
SWATCH_ALT = Markup('<span class="swatch swatch--alt" aria-hidden="true"></span>')
+13 -3
View File
@@ -18,7 +18,7 @@ scripts or styles (the Content-Security-Policy forbids them).
import json
import os
from . import site as site_settings
from . import common, site as site_settings
from .markup import Markup, attrs, esc, json_block
NAV = (
@@ -38,6 +38,11 @@ FONT_PRELOADS = (
)
MAPLIBRE_CSS = "/assets/vendor/maplibre-gl/maplibre-gl.css"
MAPLIBRE_JS = "/assets/vendor/maplibre-gl/maplibre-gl.js"
# The outdoor map of the trail pages: its style, named on each trail map figure
# (data-outdoor) for app.js to fetch, and the contour add-on (maplibre-contour),
# loaded on those pages only (layout(outdoor=True)).
OUTDOOR_STYLE = "/assets/map/outdoor.json"
CONTOUR_JS = "/assets/vendor/maplibre-contour/maplibre-contour.js"
def _current(path, href):
@@ -113,7 +118,7 @@ def footer(site):
</div>
</div>
<div class="site-footer__base">
<div class="container">Base maps: OpenFreeMap, &copy;&nbsp;OpenMapTiles, data &copy;&nbsp;OpenStreetMap contributors.</div>
<div class="container">{common.FOOTER_MAP_CREDIT}</div>
</div>
</footer>""")
@@ -124,7 +129,8 @@ def _ld_json_block(obj):
return Markup(f'<script type="application/ld+json">{text}</script>')
def layout(title, body, *, path, description="", maps=False, scripts=(), data=None, site=None, jsonld=None, og_type="website"):
def layout(title, body, *, path, description="", maps=False, outdoor=False, scripts=(), data=None, site=None,
jsonld=None, og_type="website"):
"""Return a complete HTML document.
title the page's own title ("Arizona National Scenic Trail"); the site
@@ -133,6 +139,8 @@ def layout(title, body, *, path, description="", maps=False, scripts=(), data=No
path the page's site path, e.g. "/regions/" (canonical link, nav state).
description meta description; defaults to the site tagline.
maps True to load MapLibre (pages with a .mapfig[data-map]).
outdoor True as well on a page whose map is an outdoor map (a trail
page): loads the contour add-on after MapLibre, deferred.
scripts extra same-origin script URLs, loaded with defer after app.js.
data optional object, embedded as <script type="application/json" id="page-data">.
site settings (olt.site.Site); defaults to web/site.toml.
@@ -187,6 +195,8 @@ def layout(title, body, *, path, description="", maps=False, scripts=(), data=No
head.append('<script src="/assets/app.js" defer></script>')
if maps:
head.append(f'<script src="{MAPLIBRE_JS}" defer></script>')
if outdoor:
head.append(f'<script src="{CONTOUR_JS}" defer></script>')
head += [f'<script src="{esc(s)}" defer></script>' for s in scripts]
data_block = json_block(data, "page-data") if data is not None else ""
return f"""<!doctype html>
+1 -1
View File
@@ -84,7 +84,7 @@ def render_site(records, out_dir, repo_root, site=None):
title, description, body, needs_map = trail.render(rec, site, records)
path = f"/trails/{rec['id']}/"
layout.write_page(out_dir, path, layout.layout(title, body, path=path, description=description,
maps=needs_map, site=site))
maps=needs_map, outdoor=needs_map, site=site))
pages += 1
dataset = seo.dataset_jsonld(records, site)
body = home.render(records, site)
+5 -4
View File
@@ -9,6 +9,7 @@ import re
import urllib.parse
from . import common, elevation, facets, hike, words
from .layout import OUTDOOR_STYLE
from .markup import Markup, esc
EXTRACT_SOURCES = {"osm": "OpenStreetMap", "usfs": "USDA Forest Service", "nps": "National Park Service"}
@@ -307,7 +308,7 @@ def map_figure(rec):
bbox = rec["derived"].get("map_bbox") or rec["derived"].get("bbox")
bbox_attr = f' data-bbox="{",".join(str(v) for v in bbox)}"' if bbox else ""
credit = common.sentence(common.credit_text(src.get("attribution", "")))
return f"""<figure class="mapfig mapfig--detail detail__map" data-map="trail" data-src="/trails/{esc(rec["id"])}/map.json" data-route="{"yes" if route else "no"}"{bbox_attr}>
return f"""<figure class="mapfig mapfig--detail detail__map" data-map="trail" data-src="/trails/{esc(rec["id"])}/map.json" data-route="{"yes" if route else "no"}"{bbox_attr} data-outdoor="{OUTDOOR_STYLE}">
<div class="mapfig__frame">
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
<div class="map" role="region" aria-label="Map of the {esc(rec["name"])}">
@@ -319,7 +320,7 @@ def map_figure(rec):
</div>
<figcaption class="mapfig__caption">
<ul class="legend" aria-label="Legend">{legend}</ul>
<p>Track: {esc(src.get("line_source", ""))}, read {esc(src.get("source_checked", ""))}, drawn simplified to 30&nbsp;m. Credit: {esc(credit)} Base map: OpenFreeMap, &copy;&nbsp;OpenMapTiles, data &copy;&nbsp;OpenStreetMap contributors.</p>
<p>Track: {esc(src.get("line_source", ""))}, read {esc(src.get("source_checked", ""))}, drawn simplified to 30&nbsp;m. Credit: {esc(credit)} {common.TRAIL_MAP_CREDIT}</p>
</figcaption>
</figure>"""
@@ -476,7 +477,7 @@ def sketch_figure(rec):
legend_text = "No GPX here: start only"
_title, status, reason, rule, actions_html = _no_gpx_parts(rec)
reason_html = reason if isinstance(reason, Markup) else common.rich(reason)
return f"""<figure class="mapfig mapfig--detail detail__map" id="track" data-map="sketch" data-src="/trails/{esc(rec["id"])}/sketch.json" data-route="{"yes" if route else "no"}"{bbox_attr}>
return f"""<figure class="mapfig mapfig--detail detail__map" id="track" data-map="sketch" data-src="/trails/{esc(rec["id"])}/sketch.json" data-route="{"yes" if route else "no"}"{bbox_attr} data-outdoor="{OUTDOOR_STYLE}">
<div class="mapfig__frame">
<span class="mapfig__corner mapfig__corner--nw" aria-hidden="true"></span>
<div class="map" role="region" aria-label="Map showing the start and end of the {esc(rec["name"])}; no GPX here">
@@ -493,7 +494,7 @@ def sketch_figure(rec):
<p>{reason_html}</p>
<p class="note">{esc(rule)}</p>
{actions_html}
<p>Base map: OpenFreeMap, &copy;&nbsp;OpenMapTiles, data &copy;&nbsp;OpenStreetMap contributors.</p>
<p>{common.TRAIL_MAP_CREDIT}</p>
</div>
</figcaption>
</figure>"""