mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

How to properly override glyphs url? (style.load bug in v3.4.0?)

Open palhal opened this issue 8 months ago • 0 comments

mapbox-gl-js version: 3.4.0

Question

Up until now, I have enabled custom fonts from our Mapbox account by overriding the glyphs url like this:

const glyphsUrl = 'mapbox://fonts/<my-account>/{fontstack}/{range}.pbf'
const glyphsRootScope = ''

let map = new mapboxgl.Map({
    style: 'mapbox://styles/<my-account>/<id>'
})
    
map.on('style.load', event => event.style.glyphManager.setURL(glyphsUrl, glyphsRootScope))

After upgrading to version 3.4.0, event.style is undefined in the style.load event. It is however defined in the style.import.load event, but that doesn't trigger for non-basemap styles. Is this an intentional change or a bug?

I assume my method is not the official way to enable custom fonts, but what is? Is there a way other than creating bogus layers that use the different fonts for all my styles in Mapbox Studio? I am adding all layers programmatically, that's why my styles have the default glyphs url when loading them.

palhal avatar Jun 11 '24 08:06 palhal