UNPKG

open-vector-tile

Version:

This library reads/writes Open Vector Tiles

95 lines 3.65 kB
import { MapboxVectorLayer } from './mapbox/index.js'; import { BaseVectorTile } from './base/index.js'; import { GridData, ImageData, OVectorLayer } from './open/index.js'; import type { GridInput, ImageDataInput } from './open/index.js'; /** * Layers are a storage structure for the vector tile. * It may contain either the old Mapbox layers or the new OpenVectorTile layers */ type Layers = Record<string, MapboxVectorLayer | OVectorLayer>; /** * # Open Vector Tile * * ## Description * A Vector Tile may parse either Mapbox or OpenVector Tile Layers * The input is a Uint8Array that has encoded protobuffer messages. * * Types of layers include: * - Vector data - vector points, lines, and polygons with 3D coordinates, properties, and/or m-values * - Image data - raster data that is RGB(A) encoded * - Grid data: data that has a max-min range, works much like an image but has floating/double * precision point values for each point on the grid * * ## Usage * * ```ts * const fs = from 'fs'; * import { VectorTile } from 'open-vector-tile'; * * // assume you can read (.pbf | .mvt | .ovt) * const fixture = fs.readFileSync('./x-y-z.vector.pbf'); * // Or load with bun: * const fixture = await Bun.file('./x-y-z.vector.pbf').arrayBuffer(); * // load the protobuf parsing it directly * const tile = new VectorTile(fixture); * * // VECTOR API: * * // example layer * const { landuse } = tile.layers; * * // grab the first feature * const firstFeature = landuse.feature(0); * // grab the geometry * const geometry = firstFeature.loadGeometry(); * // OR specifically ask for a geometry type * const points = firstFeature.loadPoints(); * const lines = firstFeature.loadLines(); * const polys = firstFeature.loadPolys(); * * // If you want to take advantage of the pre-tessellated and indexed geometries * // and you're loading the data for a renderer, you can grab the pre-tessellated geometry * const [flatGeometry, indices] = firstFeature.loadGeometryFlat(); * * // IMAGE API * * // example layer * const { satellite } = tile.images; * // grab the image data * const data = satellite.image(); // Uint8Array * * // GRIDDED API * * // example layer * const { elevation } = tile.grids; * // grab the grid data * const data = elevation.grid(); // number[] * ``` */ export declare class VectorTile { #private; readonly layers: Layers; images: Record<string, ImageData>; grids: Record<string, GridData>; /** * @param data - the input data to parse * @param end - the size of the data, leave blank to parse the entire data */ constructor(data: ArrayBuffer | Uint8Array, end?: number); } /** * Write a tile to a Protobuf. and return a buffer * You have the option to store: * - Vector data - vector points, lines, and polygons with 3D coordinates, properties, and/or m-values * - Image data - raster data that is RGB(A) encoded * - Grid data: data that has a max-min range, works much like an image but has floating/double * precision point values for each point on the grid * @param tile - the tile may be a base vector tile or a S2/Mapbox vector tile * @param images - if provided, the tile will include image(s) * @param griddedData - if provodied, the grid based data to encode with specs on how to encode * @param verbose - whether to print debug messages * @returns - a protobuffer encoded buffer using the Open Vector Tile Spec */ export declare function writeOVTile(tile?: BaseVectorTile | VectorTile, images?: ImageDataInput[], griddedData?: GridInput[], verbose?: boolean): Uint8Array; export {}; //# sourceMappingURL=vectorTile.d.ts.map