fgb-vt - v1.0.6
    Preparing search index...

    Class TileClient

    Semi-stateful tile client.

    A single Connector is bound at construction; Source descriptors are provided per tile() call. File headers and spatial index pages are cached per instance (see IoOptions.cache), so repeated tiles from the same files skip most index reads.

    Use case: application sharing one HTTP connector (with auth headers) but querying different FGB sources depending on request context.

    const client = new TileClient(connector, { tolerance: 2 });

    // Different sources per request
    const buildingsTile = await client.tile(14, 8192, 5461, buildingsSource);
    const roadsTile = await client.tile(14, 8192, 5461, roadsSource);

    // Multi-source layered tile
    const layered = await client.tile(14, 8192, 5461, [buildingsSource, roadsSource]);

    await client.close();
    Index
    • Create a new tile client bound to the given connector.

      Parameters

      • connector: Connector

        Byte-range reader for accessing FGB files. Shared across all subsequent tile() calls.

      • Optionaloptions: TileOptions & IoOptions & Pick<RequestOptions, "onTile">

        Tile-level tiling option defaults applied to every call unless overridden by per-source options, plus I/O options (cache, prefetch, range merging, scan budget) and a default onTile hook.

      Returns TileClient

      If an I/O option is invalid.

    • Release connector resources (pooled connections, file handles, etc.) and the client's own cache.

      After calling close(), this client instance must not be used again.

      Returns Promise<void>

      Resolves when the underlying connector has been closed.

    • Forget what is cached about a file, so the next request re-reads its header and index, e.g. after the file was replaced at the same path. Without a path, every source is reopened from its file (the client's own cache is cleared; in a cache passed as an option, the entries are replaced as the files are read again).

      Files with version tags are detected as changed automatically; this is for connectors and servers that report none.

      Parameters

      • Optionalpath: string

        Source path, or omitted for all sources.

      Returns Promise<void>

      Resolves when the entries are removed from the cache.

    • Open sources ahead of the first tile request: read each file's header and the top of its spatial index and, within the OpenOptions.warmIndex budget, all upper index levels.

      Useful during the init phase of a serverless function or at server start-up. Opening is otherwise lazy.

      Parameters

      • sources: Source | Source[]

        Sources (or a single source) to open.

      • Optionaloptions: OpenOptions

        Index warm-up budget.

      Returns Promise<void>

      Resolves when every source is open.

      If a source cannot be opened (annotated with its path), including UnsupportedFormatError for a CRS without a configured projection.

      If a source's idColumn is not an integer column of its file.

    • Generate a vector tile from multiple FlatGeobuf sources.

      Each source produces one MVT layer in the output PBF. Layer ordering matches the order of the sources array.

      Parameters

      • z: number

        Tile zoom level.

      • x: number

        Tile column.

      • y: number

        Tile row.

      • sources: Source[]

        Array of source descriptors; each becomes one MVT layer.

      • Optionalrequest: RequestOptions

        Optional abort signal and onTile hook (overrides the constructor's).

      Returns Promise<Uint8Array<ArrayBufferLike>>

      PBF-encoded Mapbox Vector Tile containing one layer per source.

      const pbf = await client.tile(12, 2048, 1365, [
      { name: 'water', path: '/data/water.fgb' },
      { name: 'roads', path: '/data/roads.fgb' },
      ]);
    • Generate a vector tile from a single FlatGeobuf source.

      Convenience overload that wraps the source in a single-element array and delegates to the multi-source implementation.

      Parameters

      • z: number

        Tile zoom level.

      • x: number

        Tile column.

      • y: number

        Tile row.

      • source: Source

        Single source descriptor; produces one MVT layer.

      • Optionalrequest: RequestOptions

        Optional abort signal and onTile hook (overrides the constructor's).

      Returns Promise<Uint8Array<ArrayBufferLike>>

      PBF-encoded Mapbox Vector Tile containing one layer.

      const pbf = await client.tile(14, 8192, 5461, {
      name: 'buildings',
      path: 'https://cdn.example.com/buildings.fgb',
      });
    • Compute the ETag of a tile without rendering it, e.g. to answer If-None-Match with 304 Not Modified. It changes whenever a source file, a setting or the library's tile encoding changes.

      Parameters

      • z: number

        Tile zoom level.

      • x: number

        Tile column.

      • y: number

        Tile row.

      • sources: Source | Source[]

        The sources (or source) the tile is rendered from.

      • Optionalrequest: Pick<RequestOptions, "signal">

        Optional abort signal.

      Returns Promise<string | null>

      A strong, quoted ETag, or null when a source's connector reports no version tag (e.g. an HTTP server without ETag or Last-Modified).

      If a source cannot be opened (annotated with its path).