Base map theme switch: Maptool or NPS Park Tiles (colors sampled from the Park Tiles legend, park fill above landcover with a tint band), remembered; both themes in map_themes.js so /symbols.html draws a side-by-side map legend from the same patched style, linked from the Base map panel, which now stays even without offline tiles
This commit is contained in:
1 parent
cb6412f0ba
commit
f09216b102
8 files changed
+407
-170
No files matched your search
+85
-2
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>MapTool symbols</title>
|
||||
<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; }
|
||||
@@ -19,11 +19,26 @@
|
||||
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 draws each feature in its two themes (Base map panel → Theme), read from the actual patched style.</p>
|
||||
<table>
|
||||
<thead><tr><th>Feature</th><th>Maptool</th><th>NPS Park Tiles</th></tr></thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</section>
|
||||
<header>
|
||||
<h1>Point symbols</h1>
|
||||
<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>
|
||||
@@ -49,5 +64,73 @@
|
||||
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 themes = ["maptool", "parktiles"].map((theme) =>
|
||||
Object.fromEntries(patchOnlineStyle(structuredClone(template), theme).layers.map((l) => [l.id, l])));
|
||||
document.querySelector(".legend tbody").innerHTML = ROWS.map(([label, id, casingId]) =>
|
||||
`<tr><td>${label} <code>${id}</code></td>${themes.map((layers) => swatch(layers, id, casingId)).join("")}</tr>`).join("");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user