Configure webfonts for Mapbox/MapLibre styles
mainBecause ol-mapbox-style uses web fonts instead of PBF/SDF glyphs, you must specify a location for webfonts. You can do this in two ways:
- Via Style Metadata: Set the
ol:webfontsproperty in the root of the Style object. - Via Options: Use the
webfontsoption in theapply()orapplyStyle()functions.
Template URL Placeholders:
{font-family}: CSS font family (lowercase, blanks replaced with-, e.g.noto-sans){Font+Family}: CSS font family (original case, blanks replaced with+, e.g.Noto+Sans){fontweight}: CSS font weight (numeric, e.g.400){fontstyle}: CSS font style (e.g.normal,italic){-fontstyle}: CSS font style (e.g.-italicor empty string fornormal)
Font Stack Behavior: The library uses the primary font (the first in the stack) for style and weight. Subsequent fonts are used only as fallbacks if the primary font is unavailable, but they will inherit the style and weight of the primary font.
{
"version": 8,
"metadata": {
"ol:webfonts": "https://my.server/fonts/{font-family}/{fontweight}{-fontstyle}.css"
}
// ...
}