The VersaTiles class is a wrapper around a .versatiles container file. It provides methods to access tile data, metadata, and other properties within the container.

Constructors

  • Constructs a new instance of the VersaTiles class.

    Parameters

    • source: string | Reader

      The data source for the tiles. This can be a URL starting with http:// or https://, a path to a local file, or a custom Reader function that reads data chunks based on offset and length.

    • Optionaloptions: OpenOptions

      Optional settings that configure tile handling.

    Returns Container

    Will throw an error if the provided source is neither a string nor a Reader function.

Methods

  • Protected

    Asynchronously retrieves a mapping of tile block indices. The map's keys are formatted as "{z},{x},{y}". This method is for internal use to manage tile lookup within the container.

    Returns Promise<Map<string, Block>>

    A promise that resolves with the block index map.

  • Asynchronously retrieves the header information from the .versatiles container.

    Returns Promise<Header>

    A promise that resolves with the header object.

    Will throw an error if the container does not start with expected magic bytes indicating a valid format.

  • Asynchronously retrieves the metadata associated with the .versatiles container. Metadata typically includes information about vector_layers for vector tiles. If the container does not include metadata, this method returns null.

    Returns Promise<undefined | string>

    A promise that resolves with an object representing the metadata.

  • Asynchronously retrieves a specific tile's data as a Buffer. If the tile data is compressed as defined in the container header, the returned Buffer will contain the compressed data. To obtain uncompressed data, use the getTileUncompressed method. If the specified tile does not exist, the method returns null.

    Parameters

    • z: number

      The zoom level of the tile.

    • x: number

      The x coordinate of the tile within its zoom level.

    • y: number

      The y coordinate of the tile within its zoom level.

    Returns Promise<null | Buffer<ArrayBufferLike>>

    A promise that resolves with the tile data as a Buffer, or null if the tile cannot be found.

  • Protected

    Asynchronously retrieves the tile index for a specified block. This is an internal method used to maintain a lookup for every tile within a block.

    Parameters

    • block: Block

      The block for which to retrieve the tile index.

    Returns Promise<TileIndex>

    A promise that resolves with the tile index.

  • Asynchronously retrieves a specific tile's uncompressed data as a Buffer. This method first retrieves the compressed tile data using getTile and then decompresses it based on the compression setting in the container header. If the specified tile does not exist, the method returns null.

    Parameters

    • z: number

      The zoom level of the tile.

    • x: number

      The x coordinate of the tile within its zoom level.

    • y: number

      The y coordinate of the tile within its zoom level.

    Returns Promise<null | Buffer<ArrayBufferLike>>

    A promise that resolves with the uncompressed tile data as a Buffer, or null if the tile cannot be found.

  • Protected

    A protected method to read a chunk of data from the source based on the specified offset and length.

    Parameters

    • offset: number

      The offset from the start of the source data to begin reading.

    • length: number

      The number of bytes to read from the source.

    Returns Promise<Buffer<ArrayBufferLike>>

    A promise that resolves with the read data as a Buffer.