Runtime map images (texture patterns, peak triangle) added with every style before tiles ask for them; styleimagemissing kept as the fallback (MapLibre 6 skips an image added from it for the requesting tile)
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-27 14:29:29 +01:00
1 parent f0ff5f390f
commit cd8444ce2a
2 files changed
+19 -5

No files matched your search

+16 -4
View File
@@ -23,7 +23,7 @@ import { getPosition } from "/vendor/suncalc/suncalc.js";
import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js";
import { DebugControl } from "/js/debug.js";
import { patchOnlineStyle, patternImage, NightMap } from "/js/map_themes.js";
import { patchOnlineStyle, patternImage, PATTERN_IDS, NightMap } 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";
@@ -473,8 +473,20 @@ setInterval(updateSun, 60000);
const NIGHT_MODES = { auto: ["◐", "Night mode: automatic (after sunset)"], on: ["☾", "Night mode: on"], off: ["☀", "Night mode: off"] };
const nightButton = document.querySelector(".topbar__night");
const nightMap = new NightMap(map);
// The base style's texture patterns (forest, grass, military hatch) are
// drawn on demand rather than shipped in a sprite sheet.
// The base style's texture patterns (grass, scrub, military hatch) and the
// peak triangle are drawn at runtime rather than shipped in a sprite
// sheet, added with every style before its tiles ask for them: since
// MapLibre 6 an image added on styleimagemissing (or from the missing-image
// resolver) misses the tiles that asked for it.
const addPatterns = () => {
for (const id of PATTERN_IDS) {
const pattern = !map.hasImage(id) && patternImage(id);
if (pattern) map.addImage(id, pattern.image, pattern.options);
}
};
map.on("style.load", addPatterns);
if (map.isStyleLoaded()) addPatterns();
// Still the fallback for one asked for before that.
map.on("styleimagemissing", ({ id }) => {
const pattern = !map.hasImage(id) && patternImage(id);
if (pattern) map.addImage(id, pattern.image, pattern.options);
@@ -592,7 +604,7 @@ fetch("/api/terrain-tiles")
fetch("/api/hiking-trails")
.then((response) => response.json())
.then(({ countries }) => overlaysControl.setHikingTrailsOfflineCountries(countries))
.then(({ countries, bboxes }) => overlaysControl.setHikingTrailsOfflineCountries(countries, bboxes))
.catch(() => {});
fetch("/api/kiwix")