UNPKG

gis-tools-ts

Version:

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

112 lines 4.31 kB
import { Compression } from '../../util/index.js'; import type { Metadata } from 's2-tilejson'; import type { Face, TileWriter, Writer } from '../../index.js'; /** * # S2 Tiles Writer * * ## Description * * 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](https://github.com/Open-S2/s2tiles/blob/master/s2tiles-spec/1.0.0/README.md). * * ## Usage * * ### Browser Compatible * ```ts * 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(); * ``` * * ### Node/Deno/Bun using the filesystem * ```ts * 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 * ``` * * ## Links * - https://github.com/Open-S2/s2tiles/blob/master/s2tiles-spec/1.0.0/README.md */ export declare class S2TilesWriter implements TileWriter { #private; readonly writer: Writer; readonly maxzoom: number; readonly compression: Compression; offset: number; version: number; encoder: TextEncoder; /** * @param writer - the writer to append to * @param maxzoom - the maximum zoom level to write to * @param compression - the compression algorithm to use for internal data like the */ constructor(writer: Writer, maxzoom: number, compression?: Compression); /** * Write a tile to the S2Tiles 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 S2Tiles 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>; /** * 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>; /** * Write a tile to the S2Tiles 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 */ putTileIJ(face: Face, zoom: number, x: number, y: number, data: Uint8Array): Promise<void>; /** * Inserts a tile into the S2Tiles store. * @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 */ putTile(face: Face, zoom: number, x: number, y: number, data: Uint8Array): Promise<void>; } //# sourceMappingURL=index.d.ts.map