Driving declutter by a ["pitch"] in the layers' filters (MapLibre 6.21): route numbers and minor roads' / paths' names go already while tilting past 30°, no pitchend listener, no re-apply on style.load
CI / check (push) Successful in 25s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-05 14:36:11 +01:00
1 parent f85785c61d
commit cba14300b5
2 files changed
+10 -17

No files matched your search

+1 -2
View File
@@ -24,7 +24,7 @@ import { addRoutePoint, setupSidePanelModes } from "/js/panels.js";
import { isLoggedIn } from "/js/auth.js"; import { isLoggedIn } from "/js/auth.js";
import { DebugControl } from "/js/debug.js"; import { DebugControl } from "/js/debug.js";
import { setupUpdate } from "/js/update.js"; import { setupUpdate } from "/js/update.js";
import { patchOnlineStyle, patternImage, PATTERN_IDS, NightMap, declutterWhenDriving } from "/js/map_themes.js"; import { patchOnlineStyle, patternImage, PATTERN_IDS, NightMap } from "/js/map_themes.js";
import { offerSharedFiles } from "/js/share_import.js"; import { offerSharedFiles } from "/js/share_import.js";
import HomeButton from "/vendor/npmap-home-button/home-button.esm.js"; import HomeButton from "/vendor/npmap-home-button/home-button.esm.js";
import OverviewMap from "/vendor/npmap-overview/overview.esm.js"; import OverviewMap from "/vendor/npmap-overview/overview.esm.js";
@@ -438,7 +438,6 @@ const addPatterns = () => {
} }
}; };
map.on("style.load", addPatterns); map.on("style.load", addPatterns);
declutterWhenDriving(map);
if (map.isStyleLoaded()) addPatterns(); if (map.isStyleLoaded()) addPatterns();
// Still the fallback for one asked for before that. // Still the fallback for one asked for before that.
map.on("styleimagemissing", ({ id }) => { map.on("styleimagemissing", ({ id }) => {
+9 -15
View File
@@ -11,28 +11,22 @@
// The driving view (the map tilted to 3D, as following does): route // The driving view (the map tilted to 3D, as following does): route
// numbers and minor roads' / paths' names hidden, the main roads' names // numbers and minor roads' / paths' names hidden, the main roads' names
// left — what's needed at a glance. Back as soon as the map is flat. // left — what's needed at a glance. Back as soon as the map is flat.
// A ["pitch"] in the layers' filters (MapLibre ≥ 6.21), so they go already
// while tilting, and come back with every style without a listener.
const DRIVE_HIDDEN_LABELS = /^(highway-shield|road_shield|highway-name-(minor|path))/; const DRIVE_HIDDEN_LABELS = /^(highway-shield|road_shield|highway-name-(minor|path))/;
const DRIVE_PITCH = 30; const DRIVE_PITCH = 30;
export function declutterWhenDriving(map) { function declutterWhenDriving(style) {
let hidden = null; for (const layer of style.layers) {
const apply = () => { if (!DRIVE_HIDDEN_LABELS.test(layer.id)) continue;
const hide = map.getPitch() >= DRIVE_PITCH; const flat = ["<", ["pitch"], DRIVE_PITCH];
if (hide === hidden) return; layer.filter = layer.filter ? ["all", flat, layer.filter] : flat;
hidden = hide;
for (const layer of map.getStyle().layers) {
if (DRIVE_HIDDEN_LABELS.test(layer.id)) map.setLayoutProperty(layer.id, "visibility", hide ? "none" : "visible");
} }
}; return style;
map.on("pitchend", apply);
map.on("style.load", () => {
hidden = null;
apply();
});
} }
export function patchOnlineStyle(style) { export function patchOnlineStyle(style) {
return insertTrackOnlyLayer(protectedAreasAndTextures(roadLabelSpacing(parkTilesStyle(style)))); return insertTrackOnlyLayer(protectedAreasAndTextures(roadLabelSpacing(declutterWhenDriving(parkTilesStyle(style)))));
} }
// Road names and route numbers repeat every symbol-spacing *pixels*, so // Road names and route numbers repeat every symbol-spacing *pixels*, so