Navigation banner across the top (the next maneuver's arrow by Valhalla's type, distance, street, then…, lanes, the street being driven; maneuvers gain type/street/exit); the driving view (tilted to 3D) hides route numbers and minor roads' names, road labels further apart
This commit is contained in:
1 parent
e62eb90dc7
commit
27313b3101
7 files changed
+144
-22
No files matched your search
+29
-5
@@ -8,19 +8,43 @@
|
||||
// map.js styles the map with it and /symbols.html draws its legend from the
|
||||
// same patched style, so the two can't drift apart.
|
||||
|
||||
// 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.
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
export function patchOnlineStyle(style) {
|
||||
return insertTrackOnlyLayer(protectedAreasAndTextures(roadLabelSpacing(parkTilesStyle(style))));
|
||||
}
|
||||
|
||||
// Road names and route numbers repeat every symbol-spacing *pixels*, so
|
||||
// zoomed in close (z22) a street got its name every few meters. Past
|
||||
// z16 the spacing grows with the zoom: the same distance on the ground
|
||||
// (~400 m here) at every zoom.
|
||||
const ROAD_LABEL_FIXED_ZOOM = 16;
|
||||
// zoomed in close (z22) a street got its name every few meters. 1.5×
|
||||
// Liberty's spacing, and past z15 it grows with the zoom: the same
|
||||
// distance on the ground (~900 m) at every zoom.
|
||||
const ROAD_LABEL_FIXED_ZOOM = 15;
|
||||
const ROAD_LABEL_SPACING = 1.5;
|
||||
function roadLabelSpacing(style) {
|
||||
for (const layer of style.layers) {
|
||||
if (layer.type !== "symbol" || layer["source-layer"] !== "transportation_name") continue;
|
||||
const spacing = layer.layout?.["symbol-spacing"] ?? 250; // the style spec's default
|
||||
const spacing = (layer.layout?.["symbol-spacing"] ?? 250) * ROAD_LABEL_SPACING; // 250: the style spec's default
|
||||
layer.layout = { ...layer.layout, "symbol-spacing": ["interpolate", ["exponential", 2], ["zoom"], ROAD_LABEL_FIXED_ZOOM, spacing, 22, spacing * 64] };
|
||||
}
|
||||
return style;
|
||||
|
||||
Reference in new issue
Block a user