gis-tools-ts - v0.6.0
    Preparing search index...

    Class S2PMTilesWriter

    S2 PMTiles Writer

    Writes data via the S2-PMTiles specification.

    A Modified TypeScript implementation of the PMTiles library. It is backwards compatible but offers support for the S2 Projection.

    import { TileType, BufferWriter, S2PMTilesWriter, Compression } from 'gis-tools-ts';
    import type { Metadata } from 'gis-tools-ts';

    // Setup the writers
    const bufWriter = new BufferWriter();
    const writer = new S2PMTilesWriter(bufWriter, TileType.Unknown, Compression.Gzip);
    // example data
    const txtEncoder = new TextEncoder();
    const str = 'hello world';
    const uint8 = txtEncoder.encode(str);
    const str2 = 'hello world 2';
    const uint8_2 = txtEncoder.encode(str2);
    // write data in tile
    await writer.writeTileWM(0, 0, 0, uint8);
    await writer.writeTileWM(1, 0, 1, uint8);
    await writer.writeTileWM(5, 2, 9, uint8_2);
    // finish
    await writer.commit({ metadata: true } as unknown as Metadata);
    // Get the result Uint8Array
    const resultData = bufWriter.commit();
    import { S2PMTilesWriter, TileType } from 'gis-tools-ts';
    import { FileWriter } from 'gis-tools-ts/file';

    const writer = new S2PMTilesWriter(new FileWriter('./output.pmtiles'), TileType.Pbf);
    // SAME AS ABOVE

    Implements

    Index

    Constructors

    Properties

    internalCompression: Compression = Compression.Gzip

    the compression algorithm to use for internal data like the header, directories, and metadata

    type: TileType

    the tile type

    writer: Writer

    the writer to append to

    Methods

    • Finish writing by building the header with root and leaf directories

      Parameters

      • metadata: Metadata

        the metadata to store

      • tileCompression: Compression = Compression.None

        the compression algorithm that was used on the tiles [Default: None]

      Returns Promise<void>

    • Write a tile to the PMTiles file given its tile ID.

      Parameters

      • tileID: number

        the tile ID

      • data: Uint8Array

        the tile data

      • Optionalface: Face

        If it exists, then we are storing S2 data

      Returns Promise<void>

    • Write a tile to the PMTiles file given its (face, zoom, x, y) coordinates.

      Parameters

      • face: Face

        the Open S2 projection face

      • zoom: number

        the zoom level

      • x: number

        the tile X coordinate

      • y: number

        the tile Y coordinate

      • data: Uint8Array

        the tile data to store

      Returns Promise<void>

    • Write a tile to the PMTiles file given its (z, x, y) coordinates.

      Parameters

      • zoom: number

        the zoom level

      • x: number

        the tile X coordinate

      • y: number

        the tile Y coordinate

      • data: Uint8Array

        the tile data to store

      Returns Promise<void>