Map: protected area names while zoomed out (z6–10, local name, green italic) and mountain peaks from z7 (triangle drawn at runtime as SDF, name and elevation, highest win a collision); both recolored in night mode

This commit is contained in:
randy committed 2026-11-27 12:30:30 +01:00
1 parent 6182a2856d
commit cc833d5793
1 file changed
+63 -3
+63 -3
View File
@@ -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" },