Legend page served as a view with the map's versioned importmap (shared partial): as a static page it imported icons.js and mdi.mjs unversioned and a browser with an older copy showed no symbols; it also stays light (color-scheme) since auto-darkening washed out its swatches, no autofocus, a clearer filter and a symbol count
CI / check (push) Successful in 19s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-18 23:47:07 +01:00
1 parent 1bb0e1137a
commit 3e5fada66a
5 files changed
+83 -52

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
<%# Every app module and every vendored module they import is versioned
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
each other — and /vendor modules — by plain path, and an import map
remaps those paths to a versioned URL, so a deploy busts all of them
without touching any import statement. A vendored module that changes
with the app (mdi.mjs gaining an icon) can't be left cached while the
module importing it is fresh. Static files are also revalidated
(static_cache_control in app.rb) as a backstop for anything loaded
some other way. Must come before the module script below: the
importmap has to be parsed first. %>
<script type="importmap">
{
"imports": {
"/js/auth.js": "/js/auth.js?v=<%= ASSET_VERSION %>",
"/js/contour.js": "/js/contour.js?v=<%= ASSET_VERSION %>",
"/js/dem.js": "/js/dem.js?v=<%= ASSET_VERSION %>",
"/js/gnss.js": "/js/gnss.js?v=<%= ASSET_VERSION %>",
"/js/gpx.js": "/js/gpx.js?v=<%= ASSET_VERSION %>",
"/js/hiking_trails.js": "/js/hiking_trails.js?v=<%= ASSET_VERSION %>",
"/js/icons.js": "/js/icons.js?v=<%= ASSET_VERSION %>",
"/js/livetrack.js": "/js/livetrack.js?v=<%= ASSET_VERSION %>",
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
"/js/map_themes.js": "/js/map_themes.js?v=<%= ASSET_VERSION %>",
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
"/js/debug.js": "/js/debug.js?v=<%= ASSET_VERSION %>",
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
"/js/plugins.js": "/js/plugins.js?v=<%= ASSET_VERSION %>",
"/js/preview.js": "/js/preview.js?v=<%= ASSET_VERSION %>",
"/js/radar.js": "/js/radar.js?v=<%= ASSET_VERSION %>",
"/js/route.js": "/js/route.js?v=<%= ASSET_VERSION %>",
"/js/share_import.js": "/js/share_import.js?v=<%= ASSET_VERSION %>",
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
"/js/sun.js": "/js/sun.js?v=<%= ASSET_VERSION %>",
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl/maplibre-gl.mjs": "/vendor/maplibre-gl/maplibre-gl.mjs?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs": "/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs?v=<%= ASSET_VERSION %>",
"/vendor/mdi/mdi.mjs": "/vendor/mdi/mdi.mjs?v=<%= ASSET_VERSION %>",
"/vendor/nps-symbols/nps-symbols.mjs": "/vendor/nps-symbols/nps-symbols.mjs?v=<%= ASSET_VERSION %>",
"/vendor/npmap-home-button/home-button.esm.js": "/vendor/npmap-home-button/home-button.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/npmap-overview/overview.esm.js": "/vendor/npmap-overview/overview.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/suncalc/suncalc.js": "/vendor/suncalc/suncalc.js?v=<%= ASSET_VERSION %>"
}
}
</script>
+1 -48
View File
@@ -27,54 +27,7 @@
</script>
<script src="/vendor/pmtiles/pmtiles.js?v=<%= ASSET_VERSION %>"></script>
<script src="/vendor/maplibre-contour/maplibre-contour.min.js?v=<%= ASSET_VERSION %>"></script>
<%# Every app module and every vendored module they import is versioned
(ASSET_VERSION, a fresh value per deploy): map.js and the rest import
each other — and /vendor modules — by plain path, and an import map
remaps those paths to a versioned URL, so a deploy busts all of them
without touching any import statement. A vendored module that changes
with the app (mdi.mjs gaining an icon) can't be left cached while the
module importing it is fresh. Static files are also revalidated
(static_cache_control in app.rb) as a backstop for anything loaded
some other way. Must come before the module script below: the
importmap has to be parsed first. %>
<script type="importmap">
{
"imports": {
"/js/auth.js": "/js/auth.js?v=<%= ASSET_VERSION %>",
"/js/contour.js": "/js/contour.js?v=<%= ASSET_VERSION %>",
"/js/dem.js": "/js/dem.js?v=<%= ASSET_VERSION %>",
"/js/gnss.js": "/js/gnss.js?v=<%= ASSET_VERSION %>",
"/js/gpx.js": "/js/gpx.js?v=<%= ASSET_VERSION %>",
"/js/hiking_trails.js": "/js/hiking_trails.js?v=<%= ASSET_VERSION %>",
"/js/icons.js": "/js/icons.js?v=<%= ASSET_VERSION %>",
"/js/livetrack.js": "/js/livetrack.js?v=<%= ASSET_VERSION %>",
"/js/locate.js": "/js/locate.js?v=<%= ASSET_VERSION %>",
"/js/map_themes.js": "/js/map_themes.js?v=<%= ASSET_VERSION %>",
"/js/measure.js": "/js/measure.js?v=<%= ASSET_VERSION %>",
"/js/notes.js": "/js/notes.js?v=<%= ASSET_VERSION %>",
"/js/debug.js": "/js/debug.js?v=<%= ASSET_VERSION %>",
"/js/offline_data.js": "/js/offline_data.js?v=<%= ASSET_VERSION %>",
"/js/overlays.js": "/js/overlays.js?v=<%= ASSET_VERSION %>",
"/js/panels.js": "/js/panels.js?v=<%= ASSET_VERSION %>",
"/js/plugins.js": "/js/plugins.js?v=<%= ASSET_VERSION %>",
"/js/preview.js": "/js/preview.js?v=<%= ASSET_VERSION %>",
"/js/radar.js": "/js/radar.js?v=<%= ASSET_VERSION %>",
"/js/route.js": "/js/route.js?v=<%= ASSET_VERSION %>",
"/js/share_import.js": "/js/share_import.js?v=<%= ASSET_VERSION %>",
"/js/search.js": "/js/search.js?v=<%= ASSET_VERSION %>",
"/js/shadow.js": "/js/shadow.js?v=<%= ASSET_VERSION %>",
"/js/sun.js": "/js/sun.js?v=<%= ASSET_VERSION %>",
"/js/track_profile.js": "/js/track_profile.js?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl/maplibre-gl.mjs": "/vendor/maplibre-gl/maplibre-gl.mjs?v=<%= ASSET_VERSION %>",
"/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs": "/vendor/maplibre-gl-lanes/maplibre-gl-lanes.mjs?v=<%= ASSET_VERSION %>",
"/vendor/mdi/mdi.mjs": "/vendor/mdi/mdi.mjs?v=<%= ASSET_VERSION %>",
"/vendor/nps-symbols/nps-symbols.mjs": "/vendor/nps-symbols/nps-symbols.mjs?v=<%= ASSET_VERSION %>",
"/vendor/npmap-home-button/home-button.esm.js": "/vendor/npmap-home-button/home-button.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/npmap-overview/overview.esm.js": "/vendor/npmap-overview/overview.esm.js?v=<%= ASSET_VERSION %>",
"/vendor/suncalc/suncalc.js": "/vendor/suncalc/suncalc.js?v=<%= ASSET_VERSION %>"
}
}
</script>
<%= erb :importmap, layout: false %>
<script type="module" src="/js/map.js?v=<%= ASSET_VERSION %>"></script>
</body>
</html>
+145
View File
@@ -0,0 +1,145 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%# Light only: without this, Android/Chrome auto-darkening repaints the
page dark and washes out the legend swatches. %>
<meta name="color-scheme" content="light">
<title>MapTool legend</title>
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
<style>
:root { color-scheme: light; --bg: #fff; --fg: #1a1a1a; --muted: #666; --line: #ddd; --hover: #eef3ee; }
body { margin: 0; padding: 16px; background: var(--bg); color: var(--fg); font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
header { position: sticky; top: 0; background: var(--bg); padding-bottom: 12px; }
h1 { font-size: 1.2rem; margin: 0 0 4px; }
p { margin: 0 0 8px; color: var(--muted); font-size: 0.85rem; }
input { width: 100%; max-width: 420px; box-sizing: border-box; padding: 8px; font-size: 1rem; }
main { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
button { all: unset; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 6px; font-size: 0.75rem; text-align: center; word-break: break-word; }
button:hover, button:focus-visible { background: var(--hover); }
button[hidden] { display: none; }
button svg { width: 32px; height: 32px; }
small { color: var(--muted); }
h2 { font-size: 1.2rem; margin: 0 0 4px; }
.legend { margin-bottom: 24px; }
table { border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 4px 12px 4px 0; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td svg { display: block; width: 72px; height: 22px; border-radius: 3px; }
td code { color: var(--muted); font-size: 0.75rem; }
</style>
</head>
<body>
<section class="legend">
<h2>Map legend</h2>
<p>How the base map (colors after the NPS Park Tiles style) draws each feature, read from the actual patched style.</p>
<table>
<thead><tr><th>Feature</th><th>Look</th></tr></thead>
<tbody></tbody>
</table>
</section>
<header>
<h2>Point symbols <small class="count"></small></h2>
<p>National Park Service map symbols (CC0) and the OsmAnd names mapped onto them. Click one to copy its name, the value of a point's <code>icon</code> property.</p>
<input type="search" placeholder="Filter symbols, e.g. water, campground">
</header>
<main></main>
<%= erb :importmap, layout: false %>
<script type="module">
import { POI_ICONS } from "/js/icons.js";
const main = document.querySelector("main");
const aliases = {}; // svg -> OsmAnd names pointing at it
for (const [key, svg] of Object.entries(POI_ICONS)) if (key.includes("_")) (aliases[svg] ||= []).push(key);
for (const [key, svg] of Object.entries(POI_ICONS)) {
if (key.includes("_")) continue;
const button = document.createElement("button");
button.innerHTML = svg;
button.append(key);
for (const alias of aliases[svg] || []) button.append(Object.assign(document.createElement("small"), { textContent: alias }));
button.dataset.search = [key, ...(aliases[svg] || [])].join(" ").replace(/[-_]/g, " ");
button.addEventListener("click", () => navigator.clipboard?.writeText(key));
main.append(button);
}
const count = document.querySelector(".count");
const showCount = () => {
const shown = [...main.children].filter((b) => !b.hidden).length;
count.textContent = shown === main.children.length ? `(${shown})` : `(${shown} of ${main.children.length})`;
};
showCount();
document.querySelector("input").addEventListener("input", (event) => {
const words = event.target.value.toLowerCase().split(/\s+/).filter(Boolean);
for (const button of main.children) button.hidden = !words.every((w) => button.dataset.search.includes(w));
showCount();
});
</script>
<script type="module">
import { patchOnlineStyle } from "/js/map_themes.js";
// [label, layer id, casing/outline layer id] — Liberty's OpenMapTiles layer ids.
const ROWS = [
["Land", "background"],
["National park / protected area", "park", "park_outline"],
["Forest", "landcover_wood"],
["Grass, meadow", "landcover_grass"],
["Wetland", "landcover_wetland"],
["Sand", "landcover_sand"],
["Glacier", "landcover_ice"],
["Water", "water"],
["River", "waterway_river"],
["Residential area", "landuse_residential"],
["Building", "building"],
["Motorway", "road_motorway", "road_motorway_casing"],
["Primary road", "road_trunk_primary", "road_trunk_primary_casing"],
["Secondary / tertiary road", "road_secondary_tertiary", "road_secondary_tertiary_casing"],
["Minor road", "road_minor", "road_minor_casing"],
["Service road", "road_service_track", "road_service_track_casing"],
["Track (unpaved)", "road_track_only"],
["Path, footway", "road_path_pedestrian"],
["Country border", "boundary_2"],
["Region border", "boundary_3"],
];
// A paint value can be a zoom expression; take its last (highest-zoom) color.
const color = (value) => {
if (typeof value === "string") return value;
const colors = JSON.stringify(value ?? null).match(/#[0-9a-f]{3,8}\b|(?:rgba?|hsla?)\([^)]*\)/gi);
return colors?.at(-1);
};
const number = (value, fallback) => (typeof value === "number" ? value : fallback);
function swatch(layers, id, casingId) {
const layer = layers[id];
if (!layer || layer.layout?.visibility === "none") return "<td>—</td>";
const p = layer.paint ?? {};
const bg = color(layers.background?.paint?.["background-color"]) ?? "#fff";
let shape;
if (layer.type === "background") {
shape = "";
} else if (layer.type === "fill" && !p["fill-color"]) {
return `<td><small>${p["fill-pattern"] ? "pattern" : "—"}</small></td>`;
} else if (layer.type === "fill") {
const outlinePaint = casingId && layers[casingId]?.paint;
const outline = outlinePaint && outlinePaint["line-opacity"] !== 0 ? color(outlinePaint["line-color"]) : null;
const tintband = layers.park_tintband && id === "park" ? color(layers.park_tintband.paint["line-color"]) : null;
shape = `<rect x="3" y="3" width="66" height="16" fill="${color(p["fill-color"])}" fill-opacity="${number(p["fill-opacity"], 1)}"/>`
+ (tintband ? `<rect x="5.5" y="5.5" width="61" height="11" fill="none" stroke="${tintband}" stroke-width="3" stroke-opacity="0.8"/>` : "")
+ (outline ? `<rect x="3" y="3" width="66" height="16" fill="none" stroke="${outline}" stroke-width="1.3"/>` : "");
} else {
const casing = casingId && layers[casingId];
const dash = Array.isArray(p["line-dasharray"]) && p["line-dasharray"].every((n) => typeof n === "number")
? ` stroke-dasharray="${p["line-dasharray"].map((n) => n * 3).join(" ")}"` : "";
shape = (casing ? `<line x1="0" y1="11" x2="72" y2="11" stroke="${color(casing.paint?.["line-color"])}" stroke-width="8"/>` : "")
+ `<line x1="0" y1="11" x2="72" y2="11" stroke="${color(p["line-color"])}" stroke-width="${casing ? 5 : 2.5}"${dash}/>`;
}
return `<td><svg viewBox="0 0 72 22"><rect width="72" height="22" fill="${bg}"/>${shape}</svg></td>`;
}
const template = await fetch("/vendor/liberty-style/liberty.json").then((response) => response.json());
const layers = Object.fromEntries(patchOnlineStyle(template).layers.map((l) => [l.id, l]));
document.querySelector(".legend tbody").innerHTML = ROWS.map(([label, id, casingId]) =>
`<tr><td>${label} <code>${id}</code></td>${swatch(layers, id, casingId)}</tr>`).join("");
</script>
</body>
</html>