UNPKG

s2-tools

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

91 lines 3.38 kB
import { Compression } from '../../readers/pmtiles'; import type { TileType } from '../../readers/pmtiles'; import type { Face, Metadata } from 's2-tilejson'; import type { TileWriter, Writer } from '..'; /** * # S2 PMTiles Writer * * ## About * Writes data via the [S2-PMTiles specification](https://github.com/Open-S2/s2-pmtiles/blob/master/s2-pmtiles-spec/1.0.0/README.md). * * A Modified TypeScript implementation of the [PMTiles](https://github.com/protomaps/PMTiles) library. It is backwards compatible but * offers support for the S2 Projection. * * ## Usage * * ### Browser Compatible * ```typescript * import { TileType, BufferWriter, S2PMTilesWriter, Compression } from 's2-tools'; * * import type { Metadata } from 's2-tools'; * * // 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(); * ``` * * ### Node/Deno/Bun using the filesystem * ```typescript * import { S2PMTilesWriter, TileType } from 's2-tools'; * import { FileWriter } from 's2-tools/file'; * * const writer = new S2PMTilesWriter(new FileWriter('./output.pmtiles'), TileType.Pbf); * // SAME AS ABOVE * ``` */ export declare class S2PMTilesWriter implements TileWriter { #private; readonly writer: Writer; readonly type: TileType; readonly compression: Compression; /** * @param writer - the writer to append to * @param type - the tile type * @param compression - the compression algorithm */ constructor(writer: Writer, type: TileType, compression?: Compression); /** * Write a tile to the PMTiles file given its (z, x, y) coordinates. * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ writeTileWM(zoom: number, x: number, y: number, data: Uint8Array): Promise<void>; /** * Write a tile to the PMTiles file given its (face, zoom, x, y) coordinates. * @param face - the Open S2 projection face * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ writeTileS2(face: Face, zoom: number, x: number, y: number, data: Uint8Array): Promise<void>; /** * Write a tile to the PMTiles file given its tile ID. * @param tileID - the tile ID * @param data - the tile data * @param face - If it exists, then we are storing S2 data */ writeTile(tileID: number, data: Uint8Array, face?: Face): Promise<void>; /** * Finish writing by building the header with root and leaf directories * @param metadata - the metadata to store */ commit(metadata: Metadata): Promise<void>; } //# sourceMappingURL=writer.d.ts.map