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
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-18 23:11:44 +01:00
1 parent cb6412f0ba
commit f09216b102
8 files changed
+407 -170

No files matched your search

+13 -5
View File
@@ -111,7 +111,7 @@ snapshot under `public/vendor/liberty-sprite/` — both `offlineStyle()`
and the online style otherwise share identical `glyphs`/`sprite`
roles, just resolved to local vs. `tiles.openfreemap.org` URLs.
`public/js/map.js`'s `ONLINE_STYLE_PATCH` — applied to whichever
`public/js/map_themes.js`'s `ONLINE_STYLE_PATCH` — applied to whichever
source is loaded, online or offline (see above) — nudges Liberty's
OpenMapTiles layer ids towards a warm, National Park Service
"Park Tiles"-inspired look. A few of these values are the genuine
@@ -137,11 +137,19 @@ labeling prioritized), not general-purpose worldwide cartography —
irrelevant to this app either way now, since it never talks to NPS's
tile service, only ever OpenFreeMap/Geofabrik.
A second theme, *NPS Park Tiles* (Base map panel → Theme, remembered in
`localStorage`), is a closer take on Park Tiles' Standard style:
`PARK_TILES_PATCH` in the same file, colors sampled from the Park Tiles
legend swatches (see `docs/nps-resources.adoc`), and the park fill moved
above landcover with a tint band inside its boundary line. Both themes
live in `public/js/map_themes.js` so `/symbols.html` can draw its map
legend from the very same patched style the map uses.
`loadOnlineStyle` (`public/js/map.js`) fetches Liberty's live
`style.json` once, patches it in place, and uses the resulting object
everywhere `ONLINE_STYLE` used to be a plain URL string — MapLibre
accepts a style object anywhere it accepts a style URL, so
`applyStyle`'s `map.setStyle(... : ONLINE_STYLE)` needed no change.
`style.json` once and keeps it unpatched as `ONLINE_STYLE_TEMPLATE`;
`onlineStyle(theme)` patches a fresh copy for whichever theme is
selected — MapLibre accepts a style object anywhere it accepts a style
URL, so `applyStyle`'s `map.setStyle` takes either.
That fetch runs before the map (and the rest of the page) is
constructed — a top-level `await` — so there's no flash of Liberty's
own colors before the patch lands; a 3s timeout and a catch-all fall
+1 -1
View File
@@ -27,7 +27,7 @@ checking here before searching from zero next time.
public domain as a US government work
| Park Tiles color palette (shared offline + online basemap theme)
| `public/js/map.js`'s `ONLINE_STYLE_PATCH`
| `public/js/map_themes.js`'s `ONLINE_STYLE_PATCH`
| Colors only — see <<park-tiles>> for why the actual tile service isn't used
| `overview` (top-right minimap/inset control)
+19
View File
@@ -586,6 +586,25 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
padding: 6px;
}
.basemap-panel__heading {
padding: 8px 10px 2px;
font-size: 12px;
color: #666;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.basemap-panel__link {
display: block;
padding: 10px;
font-size: 14px;
color: #1a5fb4;
}
.basemap-panel__sources[hidden] {
display: none;
}
.basemap-panel__option {
display: flex;
align-items: center;
+49 -161
View File
@@ -22,6 +22,7 @@ import { formatCoords, formatSunInfo, sunChartHtml } from "/js/sun.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js";
import { DebugControl } from "/js/debug.js";
import { patchOnlineStyle } from "/js/map_themes.js";
import { offerSharedFiles } from "/js/share_import.js";
import HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
@@ -31,149 +32,10 @@ const CENTER = [17.1077, 48.1486];
const ZOOM = 13;
const ONLINE_STYLE_URL = "https://tiles.openfreemap.org/styles/liberty";
// Recolors OpenFreeMap Liberty to a warm, NPS-Park-Tiles-inspired palette —
// cream ground, muted roads/boundaries — mapped onto Liberty's OpenMapTiles
// layer ids. Applied identically regardless of which PMTiles data actually
// backs the "openmaptiles" source (see offlineStyle() below): offline tiles
// are built by Planetiler's own OpenMapTiles profile (docs/development.adoc),
// the same schema Liberty already expects, so one patch serves both —
// no separate offline theme/palette to keep in sync. Only the layers that
// dominate the map's overall color read are touched; labels, halos, rail,
// and minor overlays (cemetery/hospital/school/pitch/track shading,
// building outlines) are left at Liberty's own defaults.
//
// wood/grass are deliberately left unpatched — Liberty's own green (a
// translucent landcover_wood/landcover_grass wash) already reads well over
// the patched cream background.
const ONLINE_STYLE_PATCH = {
background: { "background-color": "#f9f6ef" },
// Liberty washes every built-up area in a translucent gray-tan below
// z12 (landuse_residential, maxzoom 12 — gone by this app's default
// z13) that the offline schema has no equivalent of; protomaps just
// leaves that ground as plain background/earth. Matched to background
// here rather than left alone, so a zoomed-out view doesn't read as
// visibly dingier online than offline.
landuse_residential: { "fill-color": "#f9f6ef" },
landcover_sand: { "fill-color": "#f0e4c4" },
water: { "fill-color": "#a3cedf" },
// fill-outline-color isn't touched by a plain fill-color patch — Liberty
// draws it separately, defaulting to a bright green that reads as a
// distinct border around named conservation areas (e.g. the Malé
// Karpaty CHKO). Matched to the fill itself, and park_outline's own
// dashed line hidden below, so a reserve blends in as ordinary forest —
// offline has no equivalent stroke at all (see park_a/park_b below),
// and the point was never to call reserves out as visibly different,
// on either side.
park: { "fill-color": "#b3e378", "fill-outline-color": "#b3e378" },
park_outline: { "line-opacity": 0 },
// fill-opacity: 0.5 matches the offline theme's own "buildings" layer —
// without it, Liberty's dense individual building footprints (each with
// its own outline) paint fully opaque and read much heavier/grayer than
// offline's softer, half-transparent fill over the same cream ground.
building: { "fill-color": "#ded7cc", "fill-opacity": 0.5 },
boundary_2: { "line-color": "#546619" },
boundary_3: { "line-color": "#546619" },
// Highway (motorway/trunk/primary), major (secondary/tertiary/link),
// minor (residential/service/track), pedestrian — each repeated for its
// tunnel_/bridge_ counterpart so a road doesn't change color when it
// dips into a tunnel or crosses a bridge. Rail is left alone.
//
// line-width below is a flat number, not Liberty's own zoom-interpolated
// expression — picked to match the offline theme's actual rendered width
// at this app's default zoom (13; verified live via queryRenderedFeatures
// on both sides), since without it Liberty's own curve draws surface
// roads roughly twice as thick as offline at street level, reading as a
// much bolder road network online.
// ponytail: tuned for z13 only, not a matching curve across all zooms —
// will drift back apart at very different zoom levels. Upgrade path:
// sample offline's width at a few more zooms and replace with a matching
// ["interpolate", ["linear"], ["zoom"], ...] expression.
road_motorway: { "line-color": "#fdefbe", "line-width": 2.26 },
road_trunk_primary: { "line-color": "#fdefbe", "line-width": 2.26 },
road_secondary_tertiary: { "line-color": "#fef7dd", "line-width": 1.87 },
road_link: { "line-color": "#fef7dd", "line-width": 1 },
road_motorway_link: { "line-color": "#fef7dd", "line-width": 1 },
road_minor: { "line-color": "#fffdf8" },
road_service_track: { "line-color": "#fffdf8" },
road_path_pedestrian: { "line-color": "#e9e2d8" },
road_motorway_casing: { "line-color": "#c9a66b", "line-width": 1.48 },
road_trunk_primary_casing: { "line-color": "#c9a66b", "line-width": 1.48 },
road_secondary_tertiary_casing: { "line-color": "#c9a66b", "line-width": 1 },
road_link_casing: { "line-color": "#c9a66b", "line-width": 1.5 },
road_motorway_link_casing: { "line-color": "#c9a66b", "line-width": 1.5 },
road_minor_casing: { "line-color": "#c9a66b" },
road_service_track_casing: { "line-color": "#c9a66b" },
tunnel_motorway: { "line-color": "#fdefbe" },
tunnel_trunk_primary: { "line-color": "#fdefbe" },
tunnel_secondary_tertiary: { "line-color": "#fef7dd" },
tunnel_link: { "line-color": "#fef7dd" },
tunnel_motorway_link: { "line-color": "#fef7dd" },
tunnel_minor: { "line-color": "#fffdf8" },
tunnel_service_track: { "line-color": "#fffdf8" },
tunnel_path_pedestrian: { "line-color": "#e9e2d8" },
tunnel_motorway_casing: { "line-color": "#c9a66b" },
tunnel_trunk_primary_casing: { "line-color": "#c9a66b" },
tunnel_secondary_tertiary_casing: { "line-color": "#c9a66b" },
tunnel_link_casing: { "line-color": "#c9a66b" },
tunnel_motorway_link_casing: { "line-color": "#c9a66b" },
tunnel_street_casing: { "line-color": "#c9a66b" },
bridge_motorway: { "line-color": "#fdefbe" },
bridge_trunk_primary: { "line-color": "#fdefbe" },
bridge_secondary_tertiary: { "line-color": "#fef7dd" },
bridge_link: { "line-color": "#fef7dd" },
bridge_motorway_link: { "line-color": "#fef7dd" },
bridge_street: { "line-color": "#fffdf8" },
bridge_service_track: { "line-color": "#fffdf8" },
bridge_path_pedestrian: { "line-color": "#e9e2d8" },
bridge_motorway_casing: { "line-color": "#c9a66b" },
bridge_trunk_primary_casing: { "line-color": "#c9a66b" },
bridge_secondary_tertiary_casing: { "line-color": "#c9a66b" },
bridge_link_casing: { "line-color": "#c9a66b" },
bridge_motorway_link_casing: { "line-color": "#c9a66b" },
bridge_street_casing: { "line-color": "#c9a66b" },
bridge_path_pedestrian_casing: { "line-color": "#c9a66b" },
};
function patchOnlineStyle(style) {
for (const layer of style.layers) {
const patch = ONLINE_STYLE_PATCH[layer.id];
if (patch) Object.assign((layer.paint ??= {}), patch);
}
return insertTrackOnlyLayer(style);
}
// Liberty's own "road_service_track" layer paints service roads (paved
// driveways/parking aisles) and actual unpaved tracks the same color —
// fine for a general-purpose map, not for this app's "can the camper get
// there" use case. The underlying OpenMapTiles data does carry `class:
// "track"` separately from `"service"` (see the filter below), so rather
// than recoloring the merged layer (which would mislabel paved driveways
// as unpaved), this clones it into a second layer scoped to `class ==
// "track"` only, dashed and dirt-brown — matching how the offline theme
// already renders protomaps' own separate "other"/"path" road kind.
// Surface-level only (excludes tunnel_/bridge_ variants): an unpaved track
// in a tunnel or on a bridge is rare enough not to be worth a third layer.
function insertTrackOnlyLayer(style) {
const index = style.layers.findIndex((layer) => layer.id === "road_service_track");
if (index === -1) return style;
const base = style.layers[index];
const trackOnly = {
...base,
id: "road_track_only",
filter: ["all", base.filter, ["==", ["get", "class"], "track"]],
paint: { ...base.paint, "line-color": "#c9a66b", "line-dasharray": [2, 2] },
};
style.layers.splice(index + 1, 0, trackOnly);
return style;
}
// Fetched (not just referenced by URL) so its colors can be patched before
// the map ever sees it — MapLibre accepts a style object anywhere it'd
// accept a style URL, so every other use of ONLINE_STYLE (applyStyle's
// accept a style URL, so every use of onlineStyle() (applyStyle's
// map.setStyle) needs no change. This runs before the map — and the rest
// of the page's setup — is constructed (see the top-level await below), so
// it falls back to the plain URL, letting MapLibre fetch and render it
@@ -181,18 +43,34 @@ function insertTrackOnlyLayer(style) {
// (a 3s timeout): this app is meant to work offline in the field, and
// blocking the entire page on a remote style server would undermine that
// even though this particular fetch is only for the online map.
// Kept unpatched so either theme can be applied to a fresh copy (see onlineStyle()).
async function loadOnlineStyle() {
try {
const response = await fetch(ONLINE_STYLE_URL, { signal: AbortSignal.timeout(3000) });
return patchOnlineStyle(await response.json());
return await response.json();
} catch (err) {
return ONLINE_STYLE_URL;
}
}
const ONLINE_STYLE = await loadOnlineStyle();
const ONLINE_STYLE_TEMPLATE = await loadOnlineStyle();
// A vendored copy of the same Liberty style ONLINE_STYLE fetches live
// Base map state: which tiles (Online/Offline) and which color theme
// (Maptool / NPS Park Tiles, remembered), see applyStyle().
let currentSource = "online";
let currentTheme = "maptool";
try {
if (localStorage.getItem("mapTheme") === "parktiles") currentTheme = "parktiles";
} catch {
// storage unavailable: default theme
}
function onlineStyle(theme) {
if (typeof ONLINE_STYLE_TEMPLATE === "string") return ONLINE_STYLE_TEMPLATE;
return patchOnlineStyle(structuredClone(ONLINE_STYLE_TEMPLATE), theme);
}
// A vendored copy of the same Liberty style ONLINE_STYLE_TEMPLATE fetches live
// (public/vendor/liberty-style/liberty.json — a point-in-time snapshot, not
// auto-updated) that offlineStyle() below patches+repoints the exact same
// way. Offline mode can't depend on ONLINE_STYLE_URL actually being
@@ -225,8 +103,8 @@ addProtocol("pmtiles", protocol.tile);
// this only ever silently fails to load at a zoom level offline users
// aren't in, the same graceful-degradation story as this app's other
// online-only extras (Wikipedia, live radar).
function offlineStyle() {
const style = patchOnlineStyle(structuredClone(OFFLINE_STYLE_TEMPLATE));
function offlineStyle(theme) {
const style = patchOnlineStyle(structuredClone(OFFLINE_STYLE_TEMPLATE), theme);
style.sources.openmaptiles.url = `pmtiles://${window.location.origin}/tiles/offline.pmtiles`;
style.glyphs = `${window.location.origin}/vendor/fonts/{fontstack}/{range}.pbf`;
style.sprite = `${window.location.origin}/vendor/liberty-sprite/ofm`;
@@ -254,8 +132,9 @@ class LayerToggleControl {
.addEventListener("click", () => this._togglePanel(false));
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
button.addEventListener("click", () => {
this._onSelect(button.dataset.style);
this._togglePanel(false);
this._onSelect({ source: button.dataset.style, theme: button.dataset.theme });
// A theme switch keeps the panel open, to flip back and forth comparing.
if (button.dataset.style) this._togglePanel(false);
});
});
@@ -278,18 +157,19 @@ class LayerToggleControl {
this._togglePanel();
}
setActive(name) {
setActive(source, theme) {
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
button.classList.toggle("active", button.dataset.style === name);
const value = button.dataset.style ? source : theme;
button.classList.toggle("active", (button.dataset.style ?? button.dataset.theme) === value);
});
}
// Called once it's known there's no offline map to switch to (see the
// /api/offline-tiles check below) — an Online/Offline switch doesn't make
// sense to show at all when Offline was never going to work.
remove() {
this._container.remove();
this._panel.hidden = true;
// sense to show at all when Offline was never going to work. The panel
// itself stays for the theme choice.
hideSources() {
this._panel.querySelector(".basemap-panel__sources").hidden = true;
}
}
@@ -459,7 +339,7 @@ class RotationLockControl {
const map = new MaplibreMap({
container: "map",
style: ONLINE_STYLE,
style: onlineStyle(currentTheme),
center: CENTER,
zoom: ZOOM,
// MapLibre's built-in Hash control: keeps #map=zoom/lat/lon in the URL in
@@ -624,7 +504,7 @@ if (isLoggedIn()) new PluginsControl(map).mount(sidebar);
sidebar.insertAdjacentHTML("beforeend", `<div class="sidebar-group-label" title="Offline hub"></div>`);
layerToggle.mount(sidebar);
layerToggle.setActive("online");
layerToggle.setActive(currentSource, currentTheme);
new RoutePanelControl(map, gnssControl, profilePanel).mount(sidebar);
new OfflineDataControl().mount(sidebar);
@@ -642,9 +522,18 @@ setupSidePanelModes();
const mapLayersButton = new MapLayersButton(layerToggle);
map.addControl(mapLayersButton, "top-left");
function applyStyle(name) {
layerToggle.setActive(name);
map.setStyle(name === "offline" ? offlineStyle() : ONLINE_STYLE);
function applyStyle({ source = currentSource, theme = currentTheme } = {}) {
if (theme !== currentTheme) {
try {
localStorage.setItem("mapTheme", theme);
} catch {
// private window / blocked storage: the choice just isn't remembered
}
}
currentSource = source;
currentTheme = theme;
layerToggle.setActive(source, theme);
map.setStyle(source === "offline" ? offlineStyle(theme) : onlineStyle(theme));
}
// If a local PMTiles file is present, prefer it as the default style — its
@@ -657,10 +546,9 @@ fetch("/api/offline-tiles")
.then((response) => response.json())
.then(({ available }) => {
if (available) {
applyStyle("offline");
applyStyle({ source: "offline" });
} else {
layerToggle.remove();
map.removeControl(mapLayersButton);
layerToggle.hideSources();
}
offlineStatus.hidden = false;
offlineStatus.classList.toggle("topbar__offline-status--ready", available);
+226
View File
@@ -0,0 +1,226 @@
// The base map's two color themes (Base map panel → Theme), applied to the
// Liberty style JSON: map.js styles the map with them, /symbols.html draws
// its legend from the same patched style, so the two can't drift apart.
// Recolors OpenFreeMap Liberty to a warm, NPS-Park-Tiles-inspired palette —
// cream ground, muted roads/boundaries — mapped onto Liberty's OpenMapTiles
// layer ids. Applied identically regardless of which PMTiles data actually
// backs the "openmaptiles" source (see offlineStyle() below): offline tiles
// are built by Planetiler's own OpenMapTiles profile (docs/development.adoc),
// the same schema Liberty already expects, so one patch serves both —
// no separate offline theme/palette to keep in sync. Only the layers that
// dominate the map's overall color read are touched; labels, halos, rail,
// and minor overlays (cemetery/hospital/school/pitch/track shading,
// building outlines) are left at Liberty's own defaults.
//
// wood/grass are deliberately left unpatched — Liberty's own green (a
// translucent landcover_wood/landcover_grass wash) already reads well over
// the patched cream background.
export const ONLINE_STYLE_PATCH = {
background: { "background-color": "#f9f6ef" },
// Liberty washes every built-up area in a translucent gray-tan below
// z12 (landuse_residential, maxzoom 12 — gone by this app's default
// z13) that the offline schema has no equivalent of; protomaps just
// leaves that ground as plain background/earth. Matched to background
// here rather than left alone, so a zoomed-out view doesn't read as
// visibly dingier online than offline.
landuse_residential: { "fill-color": "#f9f6ef" },
landcover_sand: { "fill-color": "#f0e4c4" },
water: { "fill-color": "#a3cedf" },
// fill-outline-color isn't touched by a plain fill-color patch — Liberty
// draws it separately, defaulting to a bright green that reads as a
// distinct border around named conservation areas (e.g. the Malé
// Karpaty CHKO). Matched to the fill itself, and park_outline's own
// dashed line hidden below, so a reserve blends in as ordinary forest —
// offline has no equivalent stroke at all (see park_a/park_b below),
// and the point was never to call reserves out as visibly different,
// on either side.
park: { "fill-color": "#b3e378", "fill-outline-color": "#b3e378" },
park_outline: { "line-opacity": 0 },
// fill-opacity: 0.5 matches the offline theme's own "buildings" layer —
// without it, Liberty's dense individual building footprints (each with
// its own outline) paint fully opaque and read much heavier/grayer than
// offline's softer, half-transparent fill over the same cream ground.
building: { "fill-color": "#ded7cc", "fill-opacity": 0.5 },
boundary_2: { "line-color": "#546619" },
boundary_3: { "line-color": "#546619" },
// Highway (motorway/trunk/primary), major (secondary/tertiary/link),
// minor (residential/service/track), pedestrian — each repeated for its
// tunnel_/bridge_ counterpart so a road doesn't change color when it
// dips into a tunnel or crosses a bridge. Rail is left alone.
//
// line-width below is a flat number, not Liberty's own zoom-interpolated
// expression — picked to match the offline theme's actual rendered width
// at this app's default zoom (13; verified live via queryRenderedFeatures
// on both sides), since without it Liberty's own curve draws surface
// roads roughly twice as thick as offline at street level, reading as a
// much bolder road network online.
// ponytail: tuned for z13 only, not a matching curve across all zooms —
// will drift back apart at very different zoom levels. Upgrade path:
// sample offline's width at a few more zooms and replace with a matching
// ["interpolate", ["linear"], ["zoom"], ...] expression.
road_motorway: { "line-color": "#fdefbe", "line-width": 2.26 },
road_trunk_primary: { "line-color": "#fdefbe", "line-width": 2.26 },
road_secondary_tertiary: { "line-color": "#fef7dd", "line-width": 1.87 },
road_link: { "line-color": "#fef7dd", "line-width": 1 },
road_motorway_link: { "line-color": "#fef7dd", "line-width": 1 },
road_minor: { "line-color": "#fffdf8" },
road_service_track: { "line-color": "#fffdf8" },
road_path_pedestrian: { "line-color": "#e9e2d8" },
road_motorway_casing: { "line-color": "#c9a66b", "line-width": 1.48 },
road_trunk_primary_casing: { "line-color": "#c9a66b", "line-width": 1.48 },
road_secondary_tertiary_casing: { "line-color": "#c9a66b", "line-width": 1 },
road_link_casing: { "line-color": "#c9a66b", "line-width": 1.5 },
road_motorway_link_casing: { "line-color": "#c9a66b", "line-width": 1.5 },
road_minor_casing: { "line-color": "#c9a66b" },
road_service_track_casing: { "line-color": "#c9a66b" },
tunnel_motorway: { "line-color": "#fdefbe" },
tunnel_trunk_primary: { "line-color": "#fdefbe" },
tunnel_secondary_tertiary: { "line-color": "#fef7dd" },
tunnel_link: { "line-color": "#fef7dd" },
tunnel_motorway_link: { "line-color": "#fef7dd" },
tunnel_minor: { "line-color": "#fffdf8" },
tunnel_service_track: { "line-color": "#fffdf8" },
tunnel_path_pedestrian: { "line-color": "#e9e2d8" },
tunnel_motorway_casing: { "line-color": "#c9a66b" },
tunnel_trunk_primary_casing: { "line-color": "#c9a66b" },
tunnel_secondary_tertiary_casing: { "line-color": "#c9a66b" },
tunnel_link_casing: { "line-color": "#c9a66b" },
tunnel_motorway_link_casing: { "line-color": "#c9a66b" },
tunnel_street_casing: { "line-color": "#c9a66b" },
bridge_motorway: { "line-color": "#fdefbe" },
bridge_trunk_primary: { "line-color": "#fdefbe" },
bridge_secondary_tertiary: { "line-color": "#fef7dd" },
bridge_link: { "line-color": "#fef7dd" },
bridge_motorway_link: { "line-color": "#fef7dd" },
bridge_street: { "line-color": "#fffdf8" },
bridge_service_track: { "line-color": "#fffdf8" },
bridge_path_pedestrian: { "line-color": "#e9e2d8" },
bridge_motorway_casing: { "line-color": "#c9a66b" },
bridge_trunk_primary_casing: { "line-color": "#c9a66b" },
bridge_secondary_tertiary_casing: { "line-color": "#c9a66b" },
bridge_link_casing: { "line-color": "#c9a66b" },
bridge_motorway_link_casing: { "line-color": "#c9a66b" },
bridge_street_casing: { "line-color": "#c9a66b" },
bridge_path_pedestrian_casing: { "line-color": "#c9a66b" },
};
export function patchOnlineStyle(style, theme = "maptool") {
if (theme === "parktiles") return insertTrackOnlyLayer(parkTilesStyle(style));
for (const layer of style.layers) {
const patch = ONLINE_STYLE_PATCH[layer.id];
if (patch) Object.assign((layer.paint ??= {}), patch);
}
return insertTrackOnlyLayer(style);
}
// The alternative "NPS Park Tiles" theme (Base map panel → Theme), a closer
// take on Park Tiles' Standard style than ONLINE_STYLE_PATCH's: colors
// sampled from the Park Tiles legend swatches
// (nps.gov/maps/web/img/legend/*-standard.png) and the public Imagery style
// JSON (docs/nps-resources.adoc) — only the colors, none of their data.
// Line widths stay Liberty's own.
export const PARK_TILES_PATCH = {
background: { "background-color": "#f7eee8" },
natural_earth: { "raster-opacity": 0 },
landuse_residential: { "fill-color": "#f7eee8" },
landcover_wood: { "fill-color": "#dfe0c9", "fill-opacity": 0.6 },
landcover_grass: { "fill-color": "#e9e7d6", "fill-opacity": 0.5 },
landcover_wetland: { "fill-color": "#d5dcc9", "fill-opacity": 0.6 },
landcover_ice: { "fill-color": "#ffffff" },
landcover_sand: { "fill-color": "#f1e7d0" },
water: { "fill-color": "#b5d0de" },
waterway_river: { "line-color": "#b5d0de" },
waterway_other: { "line-color": "#b5d0de" },
// Park Tiles' area fill is this muted sage; #b3e378 (ONLINE_STYLE_PATCH)
// is their park *point* color.
park: { "fill-color": "#ced2b7", "fill-opacity": 1, "fill-outline-color": "#ced2b7" },
park_outline: { "line-color": "#8ba35a", "line-width": 1.3, "line-opacity": 1 },
building: { "fill-color": "#e7e4d5", "fill-outline-color": "#b8b1a0" },
boundary_2: { "line-color": "#bdb8b0" },
boundary_3: { "line-color": "#d6d0c8" },
road_motorway: { "line-color": "#f8ecbe" },
road_trunk_primary: { "line-color": "#f8ecbe" },
road_secondary_tertiary: { "line-color": "#f9f9f6" },
road_link: { "line-color": "#f9f9f6" },
road_motorway_link: { "line-color": "#f9f9f6" },
road_minor: { "line-color": "#f5f3e5" },
road_service_track: { "line-color": "#f5f3e5" },
road_motorway_casing: { "line-color": "#8f867a" },
road_trunk_primary_casing: { "line-color": "#8f867a" },
road_secondary_tertiary_casing: { "line-color": "#857f7a" },
road_link_casing: { "line-color": "#857f7a" },
road_motorway_link_casing: { "line-color": "#857f7a" },
road_minor_casing: { "line-color": "#a5a197" },
road_service_track_casing: { "line-color": "#a5a197" },
road_path_pedestrian: { "line-color": "#8e827b", "line-width": 1, "line-dasharray": [2, 1.5] },
water_name_point_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
water_name_line_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
waterway_line_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
"highway-name-major": { "text-color": "#636363", "text-halo-color": "#ffffff" },
"highway-name-minor": { "text-color": "#636363", "text-halo-color": "#ffffff" },
"highway-name-path": { "text-color": "#636363", "text-halo-color": "#ffffff" },
};
// tunnel_*/bridge_* layers reuse their surface road's colors.
function parkTilesPatchFor(id) {
const match = id.match(/^(tunnel|bridge)_(.+)$/);
if (!match) return PARK_TILES_PATCH[id];
const alias = { street: "minor", street_casing: "minor_casing" }[match[2]] ?? match[2];
return PARK_TILES_PATCH[`road_${alias}`];
}
function parkTilesStyle(style) {
for (const layer of style.layers) {
const patch = parkTilesPatchFor(layer.id);
if (patch) Object.assign((layer.paint ??= {}), patch);
}
const take = (id) => {
const index = style.layers.findIndex((layer) => layer.id === id);
return index === -1 ? null : style.layers.splice(index, 1)[0];
};
const park = take("park");
const outline = take("park_outline");
if (!park || !outline) return style;
delete outline.paint["line-dasharray"];
// Park Tiles paints a whole NPS unit one flat sage, so the park fill moves
// above landcover (wood/grass would mottle it), just below water — with a
// light-green tint band inside the boundary line, like theirs.
const band = {
...outline,
id: "park_tintband",
paint: { "line-color": "#b2c294", "line-width": 5, "line-offset": 2.5, "line-opacity": 0.8 },
};
const index = style.layers.findIndex((layer) => layer.id === "waterway_tunnel");
style.layers.splice(index === -1 ? style.layers.length : index, 0, park, band, outline);
return style;
}
// Liberty's own "road_service_track" layer paints service roads (paved
// driveways/parking aisles) and actual unpaved tracks the same color —
// fine for a general-purpose map, not for this app's "can the camper get
// there" use case. The underlying OpenMapTiles data does carry `class:
// "track"` separately from `"service"` (see the filter below), so rather
// than recoloring the merged layer (which would mislabel paved driveways
// as unpaved), this clones it into a second layer scoped to `class ==
// "track"` only, dashed and dirt-brown — matching how the offline theme
// already renders protomaps' own separate "other"/"path" road kind.
// Surface-level only (excludes tunnel_/bridge_ variants): an unpaved track
// in a tunnel or on a bridge is rare enough not to be worth a third layer.
function insertTrackOnlyLayer(style) {
const index = style.layers.findIndex((layer) => layer.id === "road_service_track");
if (index === -1) return style;
const base = style.layers[index];
const trackOnly = {
...base,
id: "road_track_only",
filter: ["all", base.filter, ["==", ["get", "class"], "track"]],
paint: { ...base.paint, "line-color": "#c9a66b", "line-dasharray": [2, 2] },
};
style.layers.splice(index + 1, 0, trackOnly);
return style;
}
+85 -2
View File
@@ -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>
+13 -1
View File
@@ -42,7 +42,7 @@
<strong>Base map</strong>
<button type="button" class="basemap-panel__close" aria-label="Close">&times;</button>
</div>
<div class="basemap-panel__list">
<div class="basemap-panel__list basemap-panel__sources">
<button type="button" class="basemap-panel__option" data-style="online">
<span>Online</span>
<span class="basemap-panel__check">&check;</span>
@@ -52,6 +52,18 @@
<span class="basemap-panel__check">&check;</span>
</button>
</div>
<div class="basemap-panel__list">
<div class="basemap-panel__heading">Theme</div>
<button type="button" class="basemap-panel__option" data-theme="maptool">
<span>Maptool</span>
<span class="basemap-panel__check">&check;</span>
</button>
<button type="button" class="basemap-panel__option" data-theme="parktiles">
<span>NPS Park Tiles</span>
<span class="basemap-panel__check">&check;</span>
</button>
<a class="basemap-panel__link" href="/symbols.html" target="_blank">Legend &amp; symbols ↗</a>
</div>
</div>
<div id="gpx-panel" class="gpx-panel" hidden>
+1
View File
@@ -45,6 +45,7 @@
"/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 %>",