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
This commit is contained in:
1 parent
1bb0e1137a
commit
3e5fada66a
5 files changed
+83
-52
No files matched your search
@@ -1,135 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>MapTool legend</title>
|
||||
<link rel="icon" href="/icons/icon.svg" type="image/svg+xml">
|
||||
<style>
|
||||
:root { --bg: #fff; --fg: #1a1a1a; --muted: #666; --line: #ddd; --hover: #eef3ee; }
|
||||
@media (prefers-color-scheme: dark) { :root { --bg: #1a1a1a; --fg: #eee; --muted: #999; --line: #333; --hover: #26302a; } }
|
||||
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</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="Search" autofocus>
|
||||
</header>
|
||||
<main></main>
|
||||
<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);
|
||||
}
|
||||
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));
|
||||
});
|
||||
</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>
|
||||
Reference in new issue
Block a user