The map draws its own icons on an overlay (#967)

An overlay drawn with a style of its own names icons, which needed the sprite sheet that style was made for.  The map now ships icons for overlays, the Maki and Temaki sets (both CC0), and always draws those, in both viewers.

The sprite sheet is the translation: its index lists every icon under its own name, under each other name it answers to (modules/map/icons/aliases.json), and in both spellings of each.  A name with no icon is drawn as a plain dot.  The icons are signed distance fields, so a style's icon color and halo apply.

A pattern is not an icon: what it filled (a fill, a line or an extrusion) is drawn in a translucent color, where removing a pattern used to leave MapLibre's opaque black.

A sprite sheet beside a map file is no longer used, served or reported.  wrolpi/scripts/build_map_icons.py builds the sheet from the SVGs; the sheet is committed.
This commit is contained in:
lrnselfreliance 2026-11-13 17:59:03 -07:00 • committed by Roland
parent 177d0dba4b
commit b2b8e2075c
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
794 changed files with 4193 additions and 252 deletions

View file

@ -32,7 +32,7 @@ import {
setOverlayEnabled,
setOverlayLayerEnabled,
} from "./mapOverlays";
import {loadOverlayStyles, overlaySpriteId, overlaySpriteUrl} from "./mapOverlayStyle";
import {addMissingOverlayIcon, loadOverlayStyles, OVERLAY_ICONS_SPRITE_ID} from "./mapOverlayStyle";
// Layer groups matching the standalone viewer.
const LAYER_GROUPS = {
@ -213,16 +213,19 @@ function buildStyle(sources, flavor = "light", hasTerrain = false, scaleUnit = "
addOverlaysToStyle(styleSources, allLayers, overlays, overlayState);
// An overlay drawn with its own style may bring its own icons: a second sprite beside the
// basemap's, whose images are named `<sprite id>:<image>`.
// An overlay drawn with a style of its own names icons: the map's overlay icons, a second
// sprite beside the basemap's. It is only asked for when there is such an overlay.
const basemapSprite = `${window.location.origin}/map-assets/sprites/${sprite}`;
const overlaySprites = overlays.filter(f => isStyledOverlay(f) && f.has_sprite)
.map(f => ({id: overlaySpriteId(f), url: overlaySpriteUrl(f)}));
const overlayIcons = {
id: OVERLAY_ICONS_SPRITE_ID,
url: `${window.location.origin}/map-assets/sprites/${OVERLAY_ICONS_SPRITE_ID}`,
};
const styled = overlays.some(isStyledOverlay);
return {
version: 8,
glyphs: "/map-assets/fonts/{fontstack}/{range}.pbf",
sprite: overlaySprites.length ? [{id: "default", url: basemapSprite}, ...overlaySprites] : basemapSprite,
sprite: styled ? [{id: "default", url: basemapSprite}, overlayIcons] : basemapSprite,
sources: styleSources,
layers: allLayers,
};
@ -793,6 +796,8 @@ export default function MapViewer() {
});
});
map.on("click", () => setContextMenu(null));
// A name the overlay icons do not have is drawn as a plain dot.
map.on("styleimagemissing", (e) => addMissingOverlayIcon(map, e.id));
map.on("movestart", () => setContextMenu(null));
// Click a POI to see the details the pmtiles file already has (kind, detail, elevation).