fix loading style font

This commit is contained in:
vcoppe
2026-01-04 19:29:46 +01:00
parent 256d62b29b
commit 5dcb93ca5d
2 changed files with 7 additions and 14 deletions

View File

@@ -101,9 +101,7 @@
acc: Record<string, ImportSpecification>, acc: Record<string, ImportSpecification>,
imprt: ImportSpecification imprt: ImportSpecification
) => { ) => {
if ( if (!['basemap', 'overlays'].includes(imprt.id)) {
!['basemap', 'overlays', 'glyphs-and-sprite'].includes(imprt.id)
) {
acc[imprt.id] = imprt; acc[imprt.id] = imprt;
} }
return acc; return acc;

View File

@@ -35,17 +35,6 @@ export class MapboxGLMap {
sources: {}, sources: {},
layers: [], layers: [],
imports: [ imports: [
{
id: 'glyphs-and-sprite', // make Mapbox glyphs and sprite available to other styles
url: '',
data: {
version: 8,
sources: {},
layers: [],
glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
sprite: 'mapbox://sprites/mapbox/outdoors-v12',
},
},
{ {
id: 'basemap', id: 'basemap',
url: '', url: '',
@@ -163,6 +152,12 @@ export class MapboxGLMap {
} }
}); });
}); });
map.on('style.import.load', () => {
const basemap = map.getStyle().imports?.find((imprt) => imprt.id === 'basemap');
if (basemap && basemap.data && basemap.data.glyphs) {
map.setGlyphsUrl(basemap.data.glyphs);
}
});
map.on('load', () => { map.on('load', () => {
this._map.set(map); // only set the store after the map has loaded this._map.set(map); // only set the store after the map has loaded
window._map = map; // entry point for extensions window._map = map; // entry point for extensions