From cba14300b543cc9204e049e58bb40d380947e65d Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sat, 5 Dec 2026 14:36:11 +0100 Subject: [PATCH] =?UTF-8?q?Driving=20declutter=20by=20a=20["pitch"]=20in?= =?UTF-8?q?=20the=20layers'=20filters=20(MapLibre=206.21):=20route=20numbe?= =?UTF-8?q?rs=20and=20minor=20roads'=20/=20paths'=20names=20go=20already?= =?UTF-8?q?=20while=20tilting=20past=2030=C2=B0,=20no=20pitchend=20listene?= =?UTF-8?q?r,=20no=20re-apply=20on=20style.load?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/map.js | 3 +-- public/js/map_themes.js | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/public/js/map.js b/public/js/map.js index 7dbed48..da46df6 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -24,7 +24,7 @@ import { addRoutePoint, setupSidePanelModes } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { DebugControl } from "/js/debug.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 HomeButton from "/vendor/npmap-home-button/home-button.esm.js"; import OverviewMap from "/vendor/npmap-overview/overview.esm.js"; @@ -438,7 +438,6 @@ const addPatterns = () => { } }; map.on("style.load", addPatterns); -declutterWhenDriving(map); if (map.isStyleLoaded()) addPatterns(); // Still the fallback for one asked for before that. map.on("styleimagemissing", ({ id }) => { diff --git a/public/js/map_themes.js b/public/js/map_themes.js index 716143b..1fd3441 100644 --- a/public/js/map_themes.js +++ b/public/js/map_themes.js @@ -11,28 +11,22 @@ // The driving view (the map tilted to 3D, as following does): route // 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. +// 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_PITCH = 30; -export function declutterWhenDriving(map) { - let hidden = null; - const apply = () => { - const hide = map.getPitch() >= DRIVE_PITCH; - if (hide === hidden) return; - hidden = hide; - for (const layer of map.getStyle().layers) { - if (DRIVE_HIDDEN_LABELS.test(layer.id)) map.setLayoutProperty(layer.id, "visibility", hide ? "none" : "visible"); - } - }; - map.on("pitchend", apply); - map.on("style.load", () => { - hidden = null; - apply(); - }); +function declutterWhenDriving(style) { + for (const layer of style.layers) { + if (!DRIVE_HIDDEN_LABELS.test(layer.id)) continue; + const flat = ["<", ["pitch"], DRIVE_PITCH]; + layer.filter = layer.filter ? ["all", flat, layer.filter] : flat; + } + return 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