A client library for VersaTiles containers.
npm i @versatiles/container
import VersaTiles from '@versatiles/container';
import fs from 'fs';
const container = new VersaTiles('https://example.org/planet.versatiles');
const header = await container.getHeader();
const tile = await container.getTileUncompressed(z,x,y);
fs.writeFileSync('tile.' + header.tile_format, tile);
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. [src]
Constructs a new instance of the VersaTiles class. [src]
Parameters:
source: string | Reader
The data source for the tiles. This can be a URL starting withhttp://
orhttps://
, a path to a local file, or a customReader
function that reads data chunks based on offset and length.options: OpenOptions
(optional)
Optional settings that configure tile handling.
Asynchronously retrieves the header information from the .versatiles
container. [src]
Returns: Promise<Header>
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
. [src]
Returns: Promise<undefined | string>
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
. [src]
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>
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
. [src]
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>
interface {
bbox: [number, number, number, number];
blockIndexLength: number;
blockIndexOffset: number;
magic: string;
metaLength: number;
metaOffset: number;
tileCompression: [Compression](#type_compression);
tileFormat: [Format](#type_format);
tileMime: string;
version: string;
zoomMax: number;
zoomMin: number;
}
interface {
tms: boolean;
}
Type: "br" | "gzip" | "raw"
Type: "avif" | "bin" | "geojson" | "jpg" | "json" | "pbf" | "png" | "svg" | "topojson" | "webp"
Type: (position: number, length: number) => Promise<Buffer>
This library could be extended to run in a web browser to read VersaTiles containers via fetch
.