114 lines
5.6 KiB
JavaScript
114 lines
5.6 KiB
JavaScript
// The base map's look: OpenFreeMap Liberty recolored after the National Park
|
|
// Service's Park Tiles "Standard" style. Colors sampled from the Park Tiles
|
|
// legend swatches (nps.gov/maps/web/img/legend/*-standard.png) and their
|
|
// public Imagery style JSON (docs/nps-resources.adoc) — only the colors,
|
|
// none of their data or tiles. Line widths stay Liberty's own. Applied
|
|
// identically to the online style and the offline one (offline.pmtiles is
|
|
// built with Planetiler's OpenMapTiles profile, the schema Liberty expects).
|
|
// 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.
|
|
|
|
export function patchOnlineStyle(style) {
|
|
return insertTrackOnlyLayer(parkTilesStyle(style));
|
|
}
|
|
|
|
const PARK_TILES_PATCH = {
|
|
background: { "background-color": "#f7eee8" },
|
|
natural_earth: { "raster-opacity": 0 },
|
|
landuse_residential: { "fill-color": "#f7eee8" },
|
|
landcover_wood: { "fill-color": "#dfe0c9", "fill-opacity": 0.6 },
|
|
landcover_grass: { "fill-color": "#e9e7d6", "fill-opacity": 0.5 },
|
|
landcover_wetland: { "fill-color": "#d5dcc9", "fill-opacity": 0.6 },
|
|
landcover_ice: { "fill-color": "#ffffff" },
|
|
landcover_sand: { "fill-color": "#f1e7d0" },
|
|
water: { "fill-color": "#b5d0de" },
|
|
waterway_river: { "line-color": "#b5d0de" },
|
|
waterway_other: { "line-color": "#b5d0de" },
|
|
// Park Tiles' area fill is this muted sage (#b3e378 is their park *point* color).
|
|
park: { "fill-color": "#ced2b7", "fill-opacity": 1, "fill-outline-color": "#ced2b7" },
|
|
park_outline: { "line-color": "#8ba35a", "line-width": 1.3, "line-opacity": 1 },
|
|
building: { "fill-color": "#e7e4d5", "fill-outline-color": "#b8b1a0" },
|
|
boundary_2: { "line-color": "#bdb8b0" },
|
|
boundary_3: { "line-color": "#d6d0c8" },
|
|
road_motorway: { "line-color": "#f8ecbe" },
|
|
road_trunk_primary: { "line-color": "#f8ecbe" },
|
|
road_secondary_tertiary: { "line-color": "#f9f9f6" },
|
|
road_link: { "line-color": "#f9f9f6" },
|
|
road_motorway_link: { "line-color": "#f9f9f6" },
|
|
road_minor: { "line-color": "#f5f3e5" },
|
|
road_service_track: { "line-color": "#f5f3e5" },
|
|
road_motorway_casing: { "line-color": "#8f867a" },
|
|
road_trunk_primary_casing: { "line-color": "#8f867a" },
|
|
road_secondary_tertiary_casing: { "line-color": "#857f7a" },
|
|
road_link_casing: { "line-color": "#857f7a" },
|
|
road_motorway_link_casing: { "line-color": "#857f7a" },
|
|
road_minor_casing: { "line-color": "#a5a197" },
|
|
road_service_track_casing: { "line-color": "#a5a197" },
|
|
road_path_pedestrian: { "line-color": "#8e827b", "line-width": 1, "line-dasharray": [2, 1.5] },
|
|
water_name_point_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
|
|
water_name_line_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
|
|
waterway_line_label: { "text-color": "#31505f", "text-halo-color": "#ffffff" },
|
|
"highway-name-major": { "text-color": "#636363", "text-halo-color": "#ffffff" },
|
|
"highway-name-minor": { "text-color": "#636363", "text-halo-color": "#ffffff" },
|
|
"highway-name-path": { "text-color": "#636363", "text-halo-color": "#ffffff" },
|
|
};
|
|
|
|
// tunnel_*/bridge_* layers reuse their surface road's colors.
|
|
function parkTilesPatchFor(id) {
|
|
const match = id.match(/^(tunnel|bridge)_(.+)$/);
|
|
if (!match) return PARK_TILES_PATCH[id];
|
|
const alias = { street: "minor", street_casing: "minor_casing" }[match[2]] ?? match[2];
|
|
return PARK_TILES_PATCH[`road_${alias}`];
|
|
}
|
|
|
|
function parkTilesStyle(style) {
|
|
for (const layer of style.layers) {
|
|
const patch = parkTilesPatchFor(layer.id);
|
|
if (patch) Object.assign((layer.paint ??= {}), patch);
|
|
}
|
|
const take = (id) => {
|
|
const index = style.layers.findIndex((layer) => layer.id === id);
|
|
return index === -1 ? null : style.layers.splice(index, 1)[0];
|
|
};
|
|
const park = take("park");
|
|
const outline = take("park_outline");
|
|
if (!park || !outline) return style;
|
|
delete outline.paint["line-dasharray"];
|
|
// Park Tiles paints a whole NPS unit one flat sage, so the park fill moves
|
|
// above landcover (wood/grass would mottle it), just below water — with a
|
|
// light-green tint band inside the boundary line, like theirs.
|
|
const band = {
|
|
...outline,
|
|
id: "park_tintband",
|
|
paint: { "line-color": "#b2c294", "line-width": 5, "line-offset": 2.5, "line-opacity": 0.8 },
|
|
};
|
|
const index = style.layers.findIndex((layer) => layer.id === "waterway_tunnel");
|
|
style.layers.splice(index === -1 ? style.layers.length : index, 0, park, band, outline);
|
|
return style;
|
|
}
|
|
|
|
// 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
|
|
// there" use case. The underlying OpenMapTiles data does carry `class:
|
|
// "track"` separately from `"service"` (see the filter below), so rather
|
|
// than recoloring the merged layer (which would mislabel paved driveways
|
|
// as unpaved), this clones it into a second layer scoped to `class ==
|
|
// "track"` only, dashed and dirt-brown.
|
|
// Surface-level only (excludes tunnel_/bridge_ variants): an unpaved track
|
|
// in a tunnel or on a bridge is rare enough not to be worth a third layer.
|
|
function insertTrackOnlyLayer(style) {
|
|
const index = style.layers.findIndex((layer) => layer.id === "road_service_track");
|
|
if (index === -1) return style;
|
|
|
|
const base = style.layers[index];
|
|
const trackOnly = {
|
|
...base,
|
|
id: "road_track_only",
|
|
filter: ["all", base.filter, ["==", ["get", "class"], "track"]],
|
|
paint: { ...base.paint, "line-color": "#c9a66b", "line-dasharray": [2, 2] },
|
|
};
|
|
style.layers.splice(index + 1, 0, trackOnly);
|
|
return style;
|
|
}
|