Keyless maps label places in one language, English included

English readers got the style's own bilingual labels, native script under every name,
so an English page fetched a glyph range for every script at world view: Prayer
Progress loaded 18 font/sprite requests (777 KB) in English against 5 (185 KB) in
Arabic. English now gets the same single-language labels as every other locale.
This commit is contained in:
Doxa Maps 2026-09-28 02:08:20 +00:00
parent 4244c9097a
commit d6f0e8c13f

View file

@ -30,7 +30,7 @@ function isMaplibreMap(map) {
}
/**
* Point the basemap's place-name labels at `lang` ('en' = the style's own labels).
* Point the basemap's place-name labels at `lang` (every language, English included).
* Call after style.load, and again whenever the reader's language changes.
* @returns {number} how many label layers were localized (0 on Mapbox, which localizes internally)
*/
@ -58,9 +58,10 @@ export function localizeBasemapLabels(map, lang) {
if (!OSM_NAME_FIELD.test(json)) continue // a plugin's own label: leave it
saved.set(layer.id, current)
} else if (!saved.has(layer.id)) continue
const next = code === 'en'
? saved.get(layer.id)
: ['coalesce', ['get', 'name:' + code], ['get', 'name:latin'], ['get', 'name']]
// English too, not the style's own bilingual labels ("Россия" under "Russia"): those drew every
// native script at world view, so an English page fetched 13 extra glyph ranges (~600 KB, rega:
// Prayer Progress 18 requests / 777 KB in en against 5 / 185 KB in ar). One language per label.
const next = ['coalesce', ['get', 'name:' + code], ['get', 'name:latin'], ['get', 'name']]
map.setLayoutProperty(layer.id, 'text-field', next)
n++
}