diff --git a/public/js/map_themes.js b/public/js/map_themes.js index 95e6b4a..9bdc6d0 100644 --- a/public/js/map_themes.js +++ b/public/js/map_themes.js @@ -9,7 +9,21 @@ // same patched style, so the two can't drift apart. export function patchOnlineStyle(style) { - return insertTrackOnlyLayer(protectedAreasAndTextures(parkTilesStyle(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; +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 + layer.layout = { ...layer.layout, "symbol-spacing": ["interpolate", ["exponential", 2], ["zoom"], ROAD_LABEL_FIXED_ZOOM, spacing, 22, spacing * 64] }; + } + return style; } const PARK_TILES_PATCH = {