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

+8 -14
View File
@@ -53,16 +53,9 @@ export class GpxPanelControl {
this._openDownloadMenu = null; // the one gpx-tree__download-menu currently open, if any
// setStyle() (switching the Online/Offline base map) tears down all
// custom sources/layers/images — re-register the category glyphs before
// putting visible GPX layers back, so a symbol layer added right away
// doesn't reference a not-yet-existing image. Badge images are handled
// separately (_registerBadgeColors, called from _addLayers) since which
// colors are needed depends on which file/category is being shown.
this._iconsReady = this._registerCategoryGlyphs();
map.on("style.load", () => {
this._iconsReady = this._registerCategoryGlyphs();
this._visible.forEach((path) => this._addLayers(path));
});
// custom sources/layers/images — _addLayers re-registers the glyph and
// badge images a file needs before putting its layers back.
map.on("style.load", () => this._visible.forEach((path) => this._addLayers(path)));
// notes.js writes directly into the same GPX store (a hand-drawn note
// saved into a .geojson layer) — refresh so a newly created/grown file
@@ -79,7 +72,7 @@ export class GpxPanelControl {
});
}
// Registered once, always white, as plain (non-SDF) images: these used to
// Registered on first use, always white, as plain (non-SDF) images: these used to
// be SDF images tinted white via icon-color, but MapLibre's SDF rendering
// assumes the source encodes an actual distance field (a smooth multi-pixel
// gradient at each edge) — feeding it a normally-antialiased raster (a
@@ -89,9 +82,10 @@ export class GpxPanelControl {
// below), there's no need for SDF's runtime-tintable alpha mask at all —
// baking the color into the raster and skipping SDF renders as sharp as
// any ordinary sprite.
async _registerCategoryGlyphs() {
// Only the icons a file actually uses: there are ~330 to choose from.
async _registerCategoryGlyphs(keys) {
await Promise.all(
POI_ICON_KEYS.map(async (key) => {
[...keys].filter((key) => POI_ICONS[key]).map(async (key) => {
if (this._map.hasImage(key)) return;
const whiteSvg = POI_ICONS[key].replace(/currentColor/g, "#fff");
const imageData = await svgToImageData(whiteSvg, POI_ICON_IMAGE_SIZE);
@@ -749,7 +743,7 @@ export class GpxPanelControl {
// enough to cluster (a handful of waypoints just render individually).
this._map.addSource(pointsId, { type: "geojson", data: points, cluster: true, clusterRadius: 50, clusterMaxZoom: 14 });
const badgeColors = new Set(points.features.map((f) => f.properties.color));
await Promise.all([this._iconsReady, this._registerBadgeColors(badgeColors)]);
await Promise.all([this._registerCategoryGlyphs(new Set(points.features.map((f) => f.properties.icon))), this._registerBadgeColors(badgeColors)]);
if (!this._map.getSource(pointsId)) return true; // a style.load (basemap switch) tore it down while icons were loading
this._addClusterLayers(pointsId, path);