All 307 NPS symbols (symbol-library 2024 revision, CC0) vendored by bin/nps-symbols-sync.mjs and browsable at /symbols.html; POI_ICONS maps every symbol by name plus the OsmAnd names, the note icon picker gets a filter, and only the glyphs a shown file uses get rasterized

This commit is contained in:
randy committed 2026-11-18 23:01:13 +01:00
1 parent 6faabca93d
commit 085c14beca
10 files changed
+551 -279

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env node
// Vendors every NPS map symbol (22 px, black, standalone) from
// nationalparkservice/symbol-library's jakecoolidge-revision-2024 branch
// (PR #226, the newest artwork: a superset of npmap5-plugins' copy) into
// one ES module, { name: "<svg …>" }, cleaned to a bare viewBox and
// fill="currentColor". Public domain (CC0). Pinned to a commit; to update,
// change REF and run `node bin/nps-symbols-sync.mjs`.
import { mkdirSync, writeFileSync } from "node:fs";
const REPO = "nationalparkservice/symbol-library";
const REF = "94f772a21b593f2cdb6d2a2b8a5cc4d3dc5e3a61";
const out = new URL("../public/vendor/nps-symbols/", import.meta.url).pathname;
const tree = await (await fetch(`https://api.github.com/repos/${REPO}/git/trees/${REF}?recursive=1`)).json();
const files = tree.tree.map((t) => t.path).filter((p) => /^src\/standalone\/.+-black-22\.svg$/.test(p) && !p.includes("transparent"));
const clean = (svg) =>
svg
.replace(/<\?xml[^>]*>|<!--[\s\S]*?-->|<(style|title)[\s\S]*?<\/\1>/g, "")
.replace(/<\w+[^>]*fill="none"[^>]*\/>/g, "") // invisible leftovers
.replace(/\s(id|fill|class|style|enable-background|xml:space)="[^"]*"/g, "")
.replace(/<svg[^>]*>/, '<svg viewBox="0 0 22 22" fill="currentColor">')
.replace(/\s+/g, " ")
.replace(/> </g, "><")
.trim();
const symbols = {};
for (let i = 0; i < files.length; i += 6) {
await Promise.all(
files.slice(i, i + 6).map(async (path) => {
const res = await fetch(`https://raw.githubusercontent.com/${REPO}/${REF}/${path}`);
if (!res.ok) throw new Error(`${path}: ${res.status}`);
symbols[path.match(/([^/]+)-black-22\.svg$/)[1]] = clean(await res.text());
}),
);
}
mkdirSync(out, { recursive: true });
writeFileSync(
`${out}nps-symbols.mjs`,
`// Generated by bin/nps-symbols-sync.mjs from ${REPO}@${REF.slice(0, 7)} (CC0).\nexport const NPS_SYMBOLS = {\n` +
Object.keys(symbols)
.sort()
.map((name) => ` ${JSON.stringify(name)}: ${JSON.stringify(symbols[name])},\n`)
.join("") +
"};\n",
);
console.log(`${Object.keys(symbols).length} symbols`);