From cc833d5793e019362297b8e666398c4ea385d676 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Fri, 27 Nov 2026 12:30:30 +0100 Subject: [PATCH] =?UTF-8?q?Map:=20protected=20area=20names=20while=20zoome?= =?UTF-8?q?d=20out=20(z6=E2=80=9310,=20local=20name,=20green=20italic)=20a?= =?UTF-8?q?nd=20mountain=20peaks=20from=20z7=20(triangle=20drawn=20at=20ru?= =?UTF-8?q?ntime=20as=20SDF,=20name=20and=20elevation,=20highest=20win=20a?= =?UTF-8?q?=20collision);=20both=20recolored=20in=20night=20mode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/map_themes.js | 66 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/public/js/map_themes.js b/public/js/map_themes.js index 7e077af..78fb285 100644 --- a/public/js/map_themes.js +++ b/public/js/map_themes.js @@ -152,10 +152,62 @@ function protectedAreasAndTextures(style) { // Above the park group (a national park's sage is opaque), below water. const index = style.layers.indexOf(outline) + 1; style.layers.splice(index, 0, protectedOutline, ...textures, military); + + // Park names while zoomed out (as OsmAnd does); from z11 village, peak + // and other local names take over. Before the place labels, so towns win + // a collision. The OpenMapTiles park layer carries a label point per area. + const label = { + id: "park_label", + type: "symbol", + source: park.source, + "source-layer": "park", + minzoom: 6, + maxzoom: 11, + filter: ["==", ["geometry-type"], "Point"], + layout: { + "text-field": ["coalesce", ["get", "name"], ["get", "name_en"]], + "text-font": ["Noto Sans Italic"], + "text-size": ["interpolate", ["linear"], ["zoom"], 6, 10, 10, 13], + "text-max-width": 8, + "text-letter-spacing": 0.05, + "symbol-sort-key": ["coalesce", ["get", "rank"], 99], + }, + paint: { "text-color": "#3f5a2e", "text-halo-color": "#ffffff", "text-halo-width": 1.5 }, + }; + // Peaks from z7, great for orientation zoomed out (Liberty has none): + // the highest win a collision, names and towns take precedence. + const peaks = { + id: "mountain_peak_label", + type: "symbol", + source: park.source, + "source-layer": "mountain_peak", + minzoom: 7, + filter: ["match", ["get", "class"], ["peak", "volcano"], true, false], + layout: { + "icon-image": "maptool-pattern-peak", + "text-field": ["case", ["has", "ele"], + ["format", ["coalesce", ["get", "name"], ""], {}, "\n", {}, ["concat", ["get", "ele"], " m"], { "font-scale": 0.8 }], + ["coalesce", ["get", "name"], ""]], + "text-font": ["Noto Sans Regular"], + "text-size": ["interpolate", ["linear"], ["zoom"], 7, 10, 12, 12], + "text-anchor": "top", + "text-offset": [0, 0.5], + "text-max-width": 8, + "text-optional": true, + "text-padding": 6, + "symbol-sort-key": ["-", 0, ["coalesce", ["get", "ele"], 0]], + }, + paint: { "icon-color": "#6b4f3a", "text-color": "#6b4f3a", "text-halo-color": "#ffffff", "text-halo-width": 1.5 }, + }; + const placeIndex = style.layers.findIndex((layer) => layer["source-layer"] === "place"); + style.layers.splice(placeIndex === -1 ? style.layers.length : placeIndex, 0, peaks, label); return style; } const PATTERNS = { + // Not a pattern: the peak triangle, drawn by the same on-demand path as + // an SDF so night mode recolors it with icon-color. + peak: { day: "#000000", sdf: true }, grass: { day: "rgba(130, 140, 95, 0.45)", night: "rgba(120, 140, 105, 0.3)" }, // Scrub, incl. dwarf pine (kosodrevina) above the tree line: its own // tint (bg) plus bushes, so it reads apart from both meadow and forest. @@ -169,7 +221,7 @@ export function patternImage(id) { const match = id.match(/^maptool-pattern-(\w+?)(-night)?$/); const colors = match && PATTERNS[match[1]]; if (!colors) return null; - const size = 48; + const size = match[1] === "peak" ? 20 : 48; const ctx = document.createElement("canvas").getContext("2d", { willReadFrequently: true }); ctx.canvas.width = ctx.canvas.height = size; ctx.strokeStyle = ctx.fillStyle = match[2] ? colors.night : colors.day; @@ -180,7 +232,13 @@ export function patternImage(id) { ctx.fillRect(0, 0, size, size); ctx.fillStyle = match[2] ? colors.night : colors.day; } - if (match[1] === "scrub") { + if (match[1] === "peak") { + ctx.beginPath(); + ctx.moveTo(10, 3); + ctx.lineTo(18, 17); + ctx.lineTo(2, 17); + ctx.fill(); + } else if (match[1] === "scrub") { // Low bushes: three overlapping dots each, staggered. for (const [x, y] of [[12, 16], [36, 40], [34, 14], [10, 38]]) { for (const dx of [-3, 0, 3]) { @@ -208,7 +266,7 @@ export function patternImage(id) { } ctx.stroke(); } - return { image: ctx.getImageData(0, 0, size, size), options: { pixelRatio: 2 } }; + return { image: ctx.getImageData(0, 0, size, size), options: { pixelRatio: 2, sdf: !!colors.sdf } }; } // Liberty's own "road_service_track" layer paints service roads (paved @@ -272,6 +330,8 @@ const NIGHT_PATCH = { landuse_military: { "fill-pattern": "maptool-pattern-military-night" }, landuse_military_outline: { "line-color": "#8a3a30" }, park_tintband: { "line-color": "#2b3a26" }, + park_label: { "text-color": "#8fae7a", "text-halo-color": NIGHT_GROUND }, + mountain_peak_label: { "icon-color": "#b8a48c", "text-color": "#b8a48c", "text-halo-color": NIGHT_GROUND }, building: { "fill-color": "#262c32", "fill-outline-color": "#30373e" }, boundary_2: { "line-color": "#4a4f55" }, boundary_3: { "line-color": "#3a3f45" },