Resolve every url-referencing source in a style into an inlined, self-contained one.
This is the asynchronous half of the API: osm() and satellite() build a style with
no I/O, and this fetches whatever those styles left as a reference. It is orthogonal to
style building — it works on any style, including guessStyle() output and hand-written
documents.
Call it on every style before handing it to MapLibre, unless the TileJSONs it references list
absolute tile URLs and use none of the VersaTiles extensions below. MapLibre reads a referenced
TileJSON itself, but only its standard fields (tiles, zooms, bounds, attribution, scheme)
and the MapLibre keys tileSize and encoding, and a property the style sets wins over the
document. Without this function:
relative tile URLs, which the VersaTiles tile server publishes, are not resolved, and every
tile request fails with … is not a valid URL;
MLT tiles — tile_format: application/vnd.maplibre-tile — are decoded as MVT, and the map
stays empty;
Terrain-RGB elevation — tile_schema: dem/mapbox — is decoded as Terrarium, the encoding the
style builders write, so terrain and hillshade show wrong heights;
raster tile sizes — tile_size: 256 — are ignored, and the tiles are drawn at MapLibre's
default of 512 px.
It also makes a style stand on its own: a published style.json, an offline or air-gapped
deployment, or a map whose first tile request should not wait for a TileJSON round-trip.
Every fetched document is checked before it is inlined: it must be a valid TileJSON, and it must
describe the kind of tiles the source claims — a type: "vector" source needs a TileJSON with
vector_layers, a raster or raster-dem source one without. A url pointing at the wrong tileset
fails here, naming the offending source, rather than turning into an empty map later.
Returns a new style; the input is not mutated. Sources without a url are left alone, and so is a
url with a scheme other than http(s): pmtiles://… is not a TileJSON reference but an archive
MapLibre reads through a registered protocol, so there is nothing for fetch to download.
Resolve every
url-referencing source in a style into an inlined, self-contained one.This is the asynchronous half of the API:
osm()andsatellite()build a style with no I/O, and this fetches whatever those styles left as a reference. It is orthogonal to style building — it works on any style, includingguessStyle()output and hand-written documents.Call it on every style before handing it to MapLibre, unless the TileJSONs it references list absolute tile URLs and use none of the VersaTiles extensions below. MapLibre reads a referenced TileJSON itself, but only its standard fields (
tiles, zooms,bounds,attribution,scheme) and the MapLibre keystileSizeandencoding, and a property the style sets wins over the document. Without this function:… is not a valid URL;tile_format: application/vnd.maplibre-tile— are decoded as MVT, and the map stays empty;tile_schema: dem/mapbox— is decoded as Terrarium, the encoding the style builders write, so terrain and hillshade show wrong heights;tile_size: 256— are ignored, and the tiles are drawn at MapLibre's default of 512 px.It also makes a style stand on its own: a published
style.json, an offline or air-gapped deployment, or a map whose first tile request should not wait for a TileJSON round-trip.Every fetched document is checked before it is inlined: it must be a valid TileJSON, and it must describe the kind of tiles the source claims — a
type: "vector"source needs a TileJSON withvector_layers, a raster or raster-dem source one without. Aurlpointing at the wrong tileset fails here, naming the offending source, rather than turning into an empty map later.Returns a new style; the input is not mutated. Sources without a
urlare left alone, and so is aurlwith a scheme other thanhttp(s):pmtiles://…is not a TileJSON reference but an archive MapLibre reads through a registered protocol, so there is nothing forfetchto download.