@versatiles/style
    Preparing search index...

    Function inlineSources

    • 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.

      Parameters

      • style: StyleSpecification
      • Optionaloptions: {
            fetch?: {
                (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
                (input: string | URL | Request, init?: RequestInit): Promise<Response>;
            };
        }
        • Optionalfetch?: {
              (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
              (input: string | URL | Request, init?: RequestInit): Promise<Response>;
          }

      Returns Promise<StyleSpecification>