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

    Class S2TilesWriter

    S2 Tiles Writer

    An S2 Tile Writer to store tile and metadata in a cloud optimized format. Similar to PMTiles but simplified to have as few features as possible.

    Reads either a Web Mercator tile or an S2 tile to the folder location given its (zoom, x, y) or (face, zoom, x, y) coordinates.

    Writes data via the S2Tiles specification.

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

    // Setup the writers
    const bufWriter = new BufferWriter();
    const writer = new S2TilesWriter(bufWriter, 12, 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);
    // If S2 tiles:
    await writer.writeTileS2(1, 0, 0, 0, uint8);
    // finish
    await writer.commit({ metadata: true } as unknown as Metadata);
    // Get the result Uint8Array
    const resultData = bufWriter.commit();
    import { S2TilesWriter, Compression } from 'gis-tools-ts';
    import { FileWriter } from 'gis-tools-ts/file';

    const writer = new S2TilesWriter(new FileWriter('./output.s2tiles'), 10, Compression.Gzip);
    // SAME AS ABOVE

    Implements

    Index

    Constructors

    • Parameters

      • writer: Writer

        the writer to append to

      • maxzoom: number

        the maximum zoom level to write to

      • compression: Compression = Compression.Gzip

        the compression algorithm to use for internal data like the

      Returns S2TilesWriter

    Properties

    compression: Compression = Compression.Gzip

    the compression algorithm to use for internal data like the

    maxzoom: number

    the maximum zoom level to write to

    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

      • OptionaltileCompression: Compression

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

      Returns Promise<void>

    • Inserts a tile into the S2Tiles store.

      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

      Returns Promise<void>

    • Write a tile to the S2Tiles 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 S2Tiles 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 S2Tiles 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>