Park Tiles look as the only base map theme: the old ONLINE_STYLE_PATCH palette and the theme switch are gone, the legend at /symbols.html shows the one look, and the docs carry the sampled Park Tiles colors
This commit is contained in:
1 parent
07b623b7ca
commit
59a29e86a5
8 files changed
+76
-227
No files matched your search
+18
-39
@@ -43,7 +43,7 @@ const ONLINE_STYLE_URL = "https://tiles.openfreemap.org/styles/liberty";
|
||||
// (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()).
|
||||
// Kept unpatched; onlineStyle() patches a fresh copy for each setStyle.
|
||||
async function loadOnlineStyle() {
|
||||
try {
|
||||
const response = await fetch(ONLINE_STYLE_URL, { signal: AbortSignal.timeout(3000) });
|
||||
@@ -55,19 +55,9 @@ async function loadOnlineStyle() {
|
||||
|
||||
const ONLINE_STYLE_TEMPLATE = await loadOnlineStyle();
|
||||
|
||||
// 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) {
|
||||
function onlineStyle() {
|
||||
if (typeof ONLINE_STYLE_TEMPLATE === "string") return ONLINE_STYLE_TEMPLATE;
|
||||
return patchOnlineStyle(structuredClone(ONLINE_STYLE_TEMPLATE), theme);
|
||||
return patchOnlineStyle(structuredClone(ONLINE_STYLE_TEMPLATE));
|
||||
}
|
||||
|
||||
// A vendored copy of the same Liberty style ONLINE_STYLE_TEMPLATE fetches live
|
||||
@@ -83,14 +73,14 @@ const protocol = new pmtiles.Protocol();
|
||||
addProtocol("pmtiles", protocol.tile);
|
||||
|
||||
// Builds the offline style from OFFLINE_STYLE_TEMPLATE — the identical
|
||||
// Liberty JSON + ONLINE_STYLE_PATCH recolor as the online map, just
|
||||
// Liberty JSON + patchOnlineStyle recolor (map_themes.js) as the online map, just
|
||||
// repointed at a local PMTiles source instead of tiles.openfreemap.org.
|
||||
// This works because data/offline.pmtiles is now built by Planetiler's own
|
||||
// OpenMapTiles profile (see docs/development.adoc), the same vector schema
|
||||
// Liberty expects — before that, offline tiles used a different schema
|
||||
// (protomaps' own basemaps) needing a completely separate hand-tuned
|
||||
// theme (protomaps-themes-base + OFFLINE_THEME) that could never be made
|
||||
// to match ONLINE_STYLE_PATCH's look exactly, no matter how much either
|
||||
// to match the online look exactly, no matter how much either
|
||||
// side got tuned.
|
||||
//
|
||||
// glyphs/sprite point at vendored local copies (public/vendor/fonts,
|
||||
@@ -103,8 +93,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(theme) {
|
||||
const style = patchOnlineStyle(structuredClone(OFFLINE_STYLE_TEMPLATE), theme);
|
||||
function offlineStyle() {
|
||||
const style = patchOnlineStyle(structuredClone(OFFLINE_STYLE_TEMPLATE));
|
||||
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`;
|
||||
@@ -132,9 +122,8 @@ class LayerToggleControl {
|
||||
.addEventListener("click", () => this._togglePanel(false));
|
||||
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
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);
|
||||
this._onSelect(button.dataset.style);
|
||||
this._togglePanel(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -157,17 +146,16 @@ class LayerToggleControl {
|
||||
this._togglePanel();
|
||||
}
|
||||
|
||||
setActive(source, theme) {
|
||||
setActive(name) {
|
||||
this._panel.querySelectorAll(".basemap-panel__option").forEach((button) => {
|
||||
const value = button.dataset.style ? source : theme;
|
||||
button.classList.toggle("active", (button.dataset.style ?? button.dataset.theme) === value);
|
||||
button.classList.toggle("active", button.dataset.style === name);
|
||||
});
|
||||
}
|
||||
|
||||
// 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. The panel
|
||||
// itself stays for the theme choice.
|
||||
// itself stays for its legend link.
|
||||
hideSources() {
|
||||
this._panel.querySelector(".basemap-panel__sources").hidden = true;
|
||||
}
|
||||
@@ -339,7 +327,7 @@ class RotationLockControl {
|
||||
|
||||
const map = new MaplibreMap({
|
||||
container: "map",
|
||||
style: onlineStyle(currentTheme),
|
||||
style: onlineStyle(),
|
||||
center: CENTER,
|
||||
zoom: ZOOM,
|
||||
// MapLibre's built-in Hash control: keeps #map=zoom/lat/lon in the URL in
|
||||
@@ -504,7 +492,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(currentSource, currentTheme);
|
||||
layerToggle.setActive("online");
|
||||
new RoutePanelControl(map, gnssControl, profilePanel).mount(sidebar);
|
||||
new OfflineDataControl().mount(sidebar);
|
||||
|
||||
@@ -522,18 +510,9 @@ setupSidePanelModes();
|
||||
const mapLayersButton = new MapLayersButton(layerToggle);
|
||||
map.addControl(mapLayersButton, "top-left");
|
||||
|
||||
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));
|
||||
function applyStyle(name) {
|
||||
layerToggle.setActive(name);
|
||||
map.setStyle(name === "offline" ? offlineStyle() : onlineStyle());
|
||||
}
|
||||
|
||||
// If a local PMTiles file is present, prefer it as the default style — its
|
||||
@@ -546,7 +525,7 @@ fetch("/api/offline-tiles")
|
||||
.then((response) => response.json())
|
||||
.then(({ available }) => {
|
||||
if (available) {
|
||||
applyStyle({ source: "offline" });
|
||||
applyStyle("offline");
|
||||
} else {
|
||||
layerToggle.hideSources();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user