library/maps/label-font.js picks a symbol layer's text-font by engine: Noto Sans
(Regular, or Bold for medium/bold) under MapLibre, which is what OpenFreeMap
serves, and exactly the caller's fonts under Mapbox. Mapbox maps render as
before.
useMapClustering hard-coded 'DIN Offc Pro Medium, Arial Unicode MS Bold', which
OpenFreeMap does not have. Under MapLibre every native cluster count requested
it and got a 404; MapLibre then drew the counts in its fallback weight instead
of the intended bold. It now uses the helper, as do upg-neighbor (replacing its
own copy), prayer-walk-planner, and key-cities' city-name labels, which named no
font and so asked for MapLibre's default (also a 404 on OpenFreeMap).
Measured by importing the real composable in a browser, 3,000 points in native
mode:
- main under MapLibre: 1 glyph 404 (DIN Offc Pro Medium,Arial Unicode MS Bold),
and the counts drawn in the fallback weight;
- this change under MapLibre: 0 glyph 404s, text-font Noto Sans Bold, 22
clusters with counts in bold;
- this change under Mapbox: text-font still exactly DIN Offc Pro Medium /
Arial Unicode MS Bold.
No production map reaches native cluster counts today (Simple Research and
Country Posters force the 'mst' line mode), so this was latent in shared code.
Correction to b1e0c7fa: it said those labels "drew nothing". The screenshots here
show MapLibre falls back and draws them. The defect was the failed glyph request
on every load and the wrong weight, not missing text.
Rebuilt: country-posters, doxa-research-map, upg-neighbor, prayer-walk-planner,
key-cities.
34 lines
1.9 KiB
JavaScript
34 lines
1.9 KiB
JavaScript
/**
|
|
* label-font.js — a text-font the map's own glyph server actually serves.
|
|
*
|
|
* A symbol layer names its font by string, and the ENGINE's glyph server must have that exact name.
|
|
* Mapbox serves DIN Offc Pro, Arial Unicode MS and Open Sans. OpenFreeMap, the basemap under
|
|
* provider=maplibre, serves Noto Sans only. MEASURED 2026-09-25: a MapLibre layer asking for
|
|
* 'DIN Offc Pro Medium' or MapLibre's default ('Open Sans Regular, Arial Unicode MS Regular') gets
|
|
* a 404 on the glyph request and draws NO text, silently: no error, no warning, the circles still
|
|
* render. check:experimental-shelf caught it on upg-neighbor and prayer-walk-planner; the same
|
|
* hard-coded name sat in useMapClustering, so cluster counts were blank on every MapLibre map.
|
|
*
|
|
* Spread into a layer's layout:
|
|
* layout: { 'text-field': …, ...labelFont(map, { weight: 'bold', mapbox: ['DIN Offc Pro Medium', 'Arial Unicode MS Bold'] }) }
|
|
*
|
|
* Under Mapbox the result is EXACTLY what the caller passed (or nothing, which keeps the style's
|
|
* default), so a Mapbox map renders byte-identically to before this helper existed.
|
|
*/
|
|
const MAPLIBRE_FONT = { regular: 'Noto Sans Regular', medium: 'Noto Sans Bold', bold: 'Noto Sans Bold' }
|
|
|
|
function isMaplibreMap(map) {
|
|
return typeof window !== 'undefined' && !!window.maplibregl && map instanceof window.maplibregl.Map
|
|
}
|
|
|
|
/**
|
|
* @param {object} map the map the layer is added to
|
|
* @param {object} [opts]
|
|
* @param {'regular'|'medium'|'bold'} [opts.weight='regular'] used under MapLibre
|
|
* @param {string[]} [opts.mapbox] the fonts to keep under Mapbox; omit to use the style default
|
|
* @returns {{ 'text-font'?: string[] }}
|
|
*/
|
|
export function labelFont(map, { weight = 'regular', mapbox } = {}) {
|
|
if (isMaplibreMap(map)) return { 'text-font': [MAPLIBRE_FONT[weight] || MAPLIBRE_FONT.regular] }
|
|
return Array.isArray(mapbox) && mapbox.length ? { 'text-font': mapbox } : {}
|
|
}
|