diff --git a/TODO.adoc b/TODO.adoc index e8f9a19..faa1310 100644 --- a/TODO.adoc +++ b/TODO.adoc @@ -31,8 +31,9 @@ independence from connectivity. ** [ ] Point detail/sidepanel: black header banner with white location name and an NPS pictogram in the corner; amenities (water, waste, power, slope) shown as a pictogram grid, no extra text; action buttons for "route here" (Valhalla), "start leveling", "save offline" ** [x] Filter panel as a "Unigrid Matrix" — an icon grid to toggle categories on/off, styled like the legend on an official NPS paper map, instead of plain dropdowns * [ ] Custom vector style (MVT/MapLibre) using the NPS color palette — muted natural tones for forests, water, and contours — so POIs and routes stand out at high zoom -** [ ] Landuse & protections: distinct styling for national parks, nature reserves (translucent green/gray-green), military zones, and private land (important for wild camping) -** [ ] OpenTopoMap-style `fill-pattern` texture for forest (tree icons) and meadow/pasture (grass texture) landcover, instead of flat fill colors — Liberty's own sprite (`public/vendor/liberty-sprite/`) only has a `wetland` dot pattern, no tree/grass, so this needs custom pattern images added to the sprite sheet; works offline and online alike since it's just a style/sprite change, unlike pulling in OpenTopoMap's own raster tiles (online-only, restrictive tile-usage policy, wouldn't match the NPS palette) +** [x] Landuse & protections: national parks keep the flat Park Tiles sage, other protected areas (nature reserves, landscape areas, …) a translucent gray-green with a dashed edge, military areas red-hatched (`protectedAreasAndTextures` in `public/js/map_themes.js`). National parks are told apart by substring of OpenMapTiles' park `class` (the OSM protection_title when there is one, so it's per-language) +*** [ ] Private land — not in the OpenMapTiles schema (no access tags on landuse); needs our own Planetiler layer or an Overpass overlay +** [x] OpenTopoMap-style `fill-pattern` texture for forest (tree icons) and meadow/pasture (grass texture) landcover, instead of flat fill colors — Liberty's own sprite (`public/vendor/liberty-sprite/`) only has a `wetland` dot pattern, no tree/grass, so this needs custom pattern images added to the sprite sheet; works offline and online alike since it's just a style/sprite change, unlike pulling in OpenTopoMap's own raster tiles (online-only, restrictive tile-usage policy, wouldn't match the NPS palette) — done without touching the sprite: the patterns are drawn on a canvas on MapLibre's `styleimagemissing` (`patternImage`), trees from zoom 12, grass from 13, with night variants ** [x] Elevation-tinted terrain — a `color-relief` layer (hypsometric tint, this app's own green→brown→gray palette) under the hillshade layer, same "Terrain shading" toggle ** [x] Road hierarchy: clearly distinguish paved roads from unpaved/gravel/track — critical for knowing if the camper can get there ** [x] Park Tiles "Standard" look as the base map — `PARK_TILES_PATCH` in `public/js/map_themes.js`, colors sampled from the Park Tiles legend swatches (values in `docs/nps-resources.adoc`): flat sage park areas above landcover with a tint band inside the boundary, cream land, Park Tiles road colors. Replaced the looser `ONLINE_STYLE_PATCH` palette (briefly both, switchable, to compare); map legend at `/symbols.html` diff --git a/public/js/map.js b/public/js/map.js index 5941dac..9c468e5 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -23,7 +23,7 @@ import { getPosition } from "/vendor/suncalc/suncalc.js"; import { notifySidePanelOpen, onlyOneSidePanelOpen, setupSidePanelModes } from "/js/panels.js"; import { isLoggedIn } from "/js/auth.js"; import { DebugControl } from "/js/debug.js"; -import { patchOnlineStyle, NightMap } from "/js/map_themes.js"; +import { patchOnlineStyle, patternImage, 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"; @@ -473,6 +473,12 @@ setInterval(updateSun, 60000); const NIGHT_MODES = { auto: ["◐", "Night mode: automatic (after sunset)"], on: ["☾", "Night mode: on"], off: ["☀", "Night mode: off"] }; const nightButton = document.querySelector(".topbar__night"); const nightMap = new NightMap(map); +// The base style's texture patterns (forest, grass, military hatch) are +// drawn on demand rather than shipped in a sprite sheet. +map.on("styleimagemissing", ({ id }) => { + const pattern = !map.hasImage(id) && patternImage(id); + if (pattern) map.addImage(id, pattern.image, pattern.options); +}); nightMap.base(initialStyle); let nightMode = "auto"; try { diff --git a/public/js/map_themes.js b/public/js/map_themes.js index 150922a..68abeb2 100644 --- a/public/js/map_themes.js +++ b/public/js/map_themes.js @@ -9,7 +9,7 @@ // same patched style, so the two can't drift apart. export function patchOnlineStyle(style) { - return insertTrackOnlyLayer(parkTilesStyle(style)); + return insertTrackOnlyLayer(protectedAreasAndTextures(parkTilesStyle(style))); } const PARK_TILES_PATCH = { @@ -87,6 +87,115 @@ function parkTilesStyle(style) { return style; } +// OpenMapTiles' park `class` is the OSM protection_title lowercased when +// there is one ("národný_park", "nationalpark", …), else the boundary/leisure +// tag ("national_park", "nature_reserve", "protected_area"), so national +// parks are told apart by substring. +// ponytail: a handful of languages; add a word when a park shows up gray. +const NATIONAL_PARK = ["any", ...["nation", "národn", "narodn", "nemzeti", "nazional", "nacional"].map((word) => ["in", word, ["coalesce", ["get", "class"], ""]])]; + +// National parks keep the flat Park Tiles sage; other protected areas +// (nature reserves, landscape areas, Natura 2000, …) get a translucent +// gray-green with a dashed edge, so the map tells "national park rules" +// from "some protection" at a glance. Military areas red-hatched. Forest +// and meadow get a tree/grass texture over their flat fill from zoom 12/13. +// The pattern images are drawn at runtime (patternImage below, on +// MapLibre's styleimagemissing), so there's no sprite sheet to extend and +// they work offline alike. +const PROTECTED_FILL = "rgba(140, 165, 120, 0.18)"; +const PROTECTED_LINE = "#7d9468"; + +function protectedAreasAndTextures(style) { + const find = (id) => style.layers.find((layer) => layer.id === id); + const park = find("park"); + const outline = find("park_outline"); + const band = find("park_tintband"); + if (!park || !outline) return style; + const sage = park.paint["fill-color"]; + park.paint["fill-color"] = ["case", ["!", NATIONAL_PARK], PROTECTED_FILL, sage]; + park.paint["fill-outline-color"] = ["case", ["!", NATIONAL_PARK], "rgba(0, 0, 0, 0)", sage]; + const protectedOutline = { + ...outline, + id: "park_outline_protected", + filter: ["all", outline.filter, ["!", NATIONAL_PARK]], + paint: { "line-color": PROTECTED_LINE, "line-width": 1.2, "line-dasharray": [3, 2] }, + }; + outline.filter = ["all", outline.filter, NATIONAL_PARK]; + if (band) band.filter = ["all", band.filter, NATIONAL_PARK]; + + const textures = [ + { id: "landcover_wood_pattern", source: "landcover", class: "wood", pattern: "forest", minzoom: 12 }, + { id: "landcover_grass_pattern", source: "landcover", class: "grass", pattern: "grass", minzoom: 13 }, + { id: "landuse_military", source: "landuse", class: "military", pattern: "military", minzoom: 8 }, + ].map((t) => ({ + id: t.id, + type: "fill", + source: park.source, + "source-layer": t.source, + minzoom: t.minzoom, + filter: ["==", ["get", "class"], t.class], + paint: { "fill-pattern": `maptool-pattern-${t.pattern}` }, + })); + const military = { + ...textures[2], + id: "landuse_military_outline", + type: "line", + paint: { "line-color": "#c0392b", "line-width": 1.2, "line-opacity": 0.7 }, + }; + // 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); + return style; +} + +const PATTERNS = { + forest: { day: "rgba(110, 130, 90, 0.45)", night: "rgba(120, 150, 110, 0.35)" }, + grass: { day: "rgba(130, 140, 95, 0.45)", night: "rgba(120, 140, 105, 0.3)" }, + military: { day: "rgba(192, 57, 43, 0.4)", night: "rgba(192, 57, 43, 0.35)" }, +}; + +// "maptool-pattern-[-night]" → { width, height, data } for +// map.addImage, drawn on a canvas at 2× (pixelRatio 2); null for other ids. +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 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; + ctx.lineWidth = 2; + ctx.lineCap = "round"; + if (match[1] === "forest") { + // Two little trees, staggered, so the texture doesn't read as a grid. + for (const [x, y] of [[12, 14], [36, 38]]) { + ctx.beginPath(); + ctx.arc(x, y - 3, 6, 0, 2 * Math.PI); + ctx.fill(); + ctx.fillRect(x - 1, y + 2, 2, 5); + } + } else if (match[1] === "grass") { + for (const [x, y] of [[10, 16], [34, 40], [30, 12]]) { + ctx.beginPath(); + for (const dx of [-4, 0, 4]) { + ctx.moveTo(x + dx * 0.4, y); + ctx.lineTo(x + dx, y - 6); + } + ctx.stroke(); + } + } else { + // Diagonal hatch, seamless across tile edges. + ctx.lineWidth = 3; + ctx.beginPath(); + for (const offset of [-size, 0, size]) { + ctx.moveTo(offset, size); + ctx.lineTo(offset + size, 0); + } + ctx.stroke(); + } + return { image: ctx.getImageData(0, 0, size, size), options: { pixelRatio: 2 } }; +} + // Liberty's own "road_service_track" layer paints service roads (paved // driveways/parking aisles) and actual unpaved tracks the same color — // fine for a general-purpose map, not for this app's "can the camper get @@ -137,8 +246,16 @@ const NIGHT_PATCH = { water: { "fill-color": "#12202b" }, waterway_river: { "line-color": "#1a3040" }, waterway_other: { "line-color": "#1a3040" }, - park: { "fill-color": "#1f2b22", "fill-outline-color": "#1f2b22" }, + park: { + "fill-color": ["case", ["!", NATIONAL_PARK], "rgba(120, 150, 110, 0.12)", "#1f2b22"], + "fill-outline-color": ["case", ["!", NATIONAL_PARK], "rgba(0, 0, 0, 0)", "#1f2b22"], + }, park_outline: { "line-color": "#4f6b3a" }, + park_outline_protected: { "line-color": "#46593a" }, + landcover_wood_pattern: { "fill-pattern": "maptool-pattern-forest-night" }, + landcover_grass_pattern: { "fill-pattern": "maptool-pattern-grass-night" }, + landuse_military: { "fill-pattern": "maptool-pattern-military-night" }, + landuse_military_outline: { "line-color": "#8a3a30" }, park_tintband: { "line-color": "#2b3a26" }, building: { "fill-color": "#262c32", "fill-outline-color": "#30373e" }, boundary_2: { "line-color": "#4a4f55" }, diff --git a/views/symbols.erb b/views/symbols.erb index 4b62656..8f652fa 100644 --- a/views/symbols.erb +++ b/views/symbols.erb @@ -80,7 +80,9 @@ // [label, layer id, casing/outline layer id] — Liberty's OpenMapTiles layer ids. const ROWS = [ ["Land", "background"], - ["National park / protected area", "park", "park_outline"], + ["National park", "park", "park_outline"], + ["Other protected area (nature reserve, …)", "park_outline_protected"], + ["Military area", "landuse_military"], ["Forest", "landcover_wood"], ["Grass, meadow", "landcover_grass"], ["Wetland", "landcover_wetland"],