UNPKG

gis-tools-ts

Version:

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

96 lines 3.77 kB
import { Compression } from '../../util/index.js'; import type { TileType } from '../../readers/pmtiles/index.js'; import type { Face, Metadata } from 's2-tilejson'; import type { TileWriter, Writer } from '../index.js'; /** * # S2 PMTiles Writer * * ## Description * 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 * ```ts * 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(); * ``` * * ### Node/Deno/Bun using the filesystem * ```ts * 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 * ``` * * ## Links * - https://github.com/Open-S2/s2-pmtiles/blob/master/s2-pmtiles-spec/1.0.0/README.md * - https://github.com/protomaps/PMTiles */ export declare class S2PMTilesWriter implements TileWriter { #private; readonly writer: Writer; readonly type: TileType; readonly internalCompression: Compression; /** * @param writer - the writer to append to * @param type - the tile type * @param internalCompression - the compression algorithm to use for internal data like the * header, directories, and metadata */ constructor(writer: Writer, type: TileType, internalCompression?: 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 * @param tileCompression - the compression algorithm that was used on the tiles [Default: None] */ commit(metadata: Metadata, tileCompression?: Compression): Promise<void>; } //# sourceMappingURL=writer.d.ts.map