UNPKG

s2-tilejson

Version:

Backwards compatible JSON format for describing s2 map tilesets.

352 lines 11.5 kB
import S2TileJSONSchema from './s2tilejson.schema.json'; import ShapeSchema from './shape.schema.json'; import TileJSONSchema from './tilejson.schema.json'; export { ShapeSchema, TileJSONSchema, S2TileJSONSchema }; import type { Face } from 's2json-spec'; /** The Bounding box, whether the tile bounds or lon-lat bounds or whatever. */ export type BBox = [left: number, bottom: number, right: number, top: number]; /** * List of possible draw types: * 1: points, * 2: lines, * 3: polys, * 4: points3D, * 5: lines3D, * 6: polys3D, * 7: raster, * 8: grid data */ export declare const DrawType: { /** POINTS = 1 */ readonly Points: 1; /** LINES = 2 */ readonly Lines: 2; /** POLYS = 3 */ readonly Polys: 3; /** POINTS 3D = 4 */ readonly Points3D: 4; /** LINES 3D = 5 */ readonly Lines3D: 5; /** POLYS 3D = 6 */ readonly Polys3D: 6; /** RASTER = 7 */ readonly Raster: 7; /** GRID = 8 */ readonly Grid: 8; }; /** 1: points, 2: lines, 3: polys, 4: points3D, 5: lines3D, 6: polys3D, 7: raster, 8: grid data */ export type DrawType = (typeof DrawType)[keyof typeof DrawType]; /** Primitive types that can be found in a shape */ export type PrimitiveShapes = 'string' | 'f32' | 'f64' | 'u64' | 'i64' | 'bool' | 'null'; /** The Shape Object But the values can only be primitives */ export interface ShapePrimitive { [key: string]: PrimitiveShapes; } /** * Arrays may contain either a primitive or an object whose values are primitives */ export type ShapePrimitiveType = PrimitiveShapes | ShapePrimitive; /** * Shape types that can be found in a shapes object. * Either a primitive, an array containing any type, or a nested shape. * If the type is an array, all elements must be the same type */ export type ShapeType = PrimitiveShapes | [ShapePrimitiveType] | Shape; /** The Shape Object. Assume an empty shape if raster or grid data */ export interface Shape { [key: string]: ShapeType; } /** Each layer has metadata associated with it. Defined as blueprints pre-construction of vector data. */ export interface LayerMetaData { description?: string; minzoom: number; maxzoom: number; drawTypes: DrawType[]; shape: Shape; mShape?: Shape; } /** Each layer has metadata associated with it. Defined as blueprints pre-construction of vector data. */ export interface LayersMetaData { [layer: string]: LayerMetaData; } /** Tilestats is simply a tracker to see where most of the tiles live */ export interface TileStatsMetadata { total: number; 0: number; 1: number; 2: number; 3: number; 4: number; 5: number; 6: number; } /** * Attribution data is stored in an object. * The key is the name of the attribution, and the value is the link */ export type Attributions = Record<string, string>; /** Track the S2 tile bounds of each face and zoom */ export interface S2Bounds { 0: { [zoom: number]: BBox; }; 1: { [zoom: number]: BBox; }; 2: { [zoom: number]: BBox; }; 3: { [zoom: number]: BBox; }; 4: { [zoom: number]: BBox; }; 5: { [zoom: number]: BBox; }; 6: { [zoom: number]: BBox; }; } /** Track the WM tile bounds of each zoom */ export interface WMBounds { [zoom: number]: BBox; } /** Types of image extensions */ export type ImageExtensions = 'raw' | 'png' | 'jpg' | 'jpeg' | 'jpe' | 'webp' | 'avif' | 'gif' | 'svg' | 'bmp' | 'tiff' | 'ico' | 'cur'; /** All supported extensions */ export type Extensions = 'geojson' | 'json' | 's2json' | 'pbf' | ImageExtensions | string; /** * Check the source type of the layer. * If "overlay" then an old engine was used */ export type SourceType = 'vector' | 'json' | 'raster' | 'raster-dem' | 'grid' | 'markers' | 'overlay'; /** Store the encoding of the data */ export type Encoding = 'gz' | 'br' | 'none' | 'zstd'; /** Old spec tracks basic vector data */ export interface VectorLayer { /** Unique identifier of the layer */ id: string; /** Description of the layer */ description?: string; /** Minimum zoom level for the layer */ minzoom?: number; /** Maximum zoom level for the layer */ maxzoom?: number; /** Field metadata for the layer. */ fields: Record<string, string>; /** Allow additional properties */ [key: string]: unknown; } /** * Default S2 tile scheme is `fzxy` * Default Web Mercator tile scheme is `xyz` * Adding a t prefix to the scheme will change the request to be time sensitive * TMS is an oudated version that is not supported by s2maps-gpu */ export type Scheme = 'fzxy' | 'tfzxy' | 'xyz' | 'txyz' | 'tms'; /** Store where the center of the data lives */ export interface Center { /** the center longitude */ lon: number; /** the center latitude */ lat: number; /** the zoom level */ zoom: number; } /** * # S2 TileJSON Metadata * Metadata describing a collection of S2 or WM tiles and how to access them. */ export interface Metadata { /** The version of the s2-tilejson spec */ s2tilejson: string; /** The type of the tileset */ type: SourceType; /** The extension when requesting a tile */ extension: Extensions; /** List of faces that have tileset */ faces: Face[]; /** minzoom at which to request tiles. [default=0] */ minzoom: number; /** maxzoom at which to request tiles. [default=27] */ maxzoom: number; /** Track layer metadata */ layers: LayersMetaData; /** WM Tile fetching bounds. Helpful to not make unecessary requests for tiles we know don't exist */ wmbounds?: WMBounds; /** S2 Tile fetching bounds. Helpful to not make unecessary requests for tiles we know don't exist */ s2bounds?: S2Bounds; /** Floating point bounding box array [west, south, east, north]. */ bounds?: BBox; /** { ['human readable string']: 'href' } */ attributions?: Attributions; /** The version of the tileset. Matches the pattern: `\d+\.\d+\.\d+\w?[\w\d]*`. */ version?: string; /** The name of the tileset */ name?: string; /** The scheme of the tileset */ scheme?: Scheme; /** The description of the tileset */ description?: string; /** The encoding of the tileset */ encoding?: Encoding; /** The center of the tileset */ centerpoint?: Center; /** Track tile stats for each face and total overall */ tilestats?: TileStatsMetadata; /** Allow additional properties */ [key: string]: unknown; /** track basic layer metadata */ vector_layers: VectorLayer[]; /** * Version of the TileJSON spec used. * Matches the pattern: `\d+\.\d+\.\d+\w?[\w\d]*`. */ tilejson?: string; /** Array of tile URL templates. */ tiles?: string[]; /** Attribution string. */ attribution?: string; /** Center coordinate array [longitude, latitude, zoom]. */ center?: [lon: number, lat: number, zoom: number]; /** Array of data source URLs. */ data?: string[]; /** Fill zoom level. Must be between 0 and 30. */ fillzoom?: number; /** Array of UTFGrid URL templates. */ grids?: string[]; /** Legend of the tileset. */ legend?: string; /** Template for interactivity. */ template?: string; } /** * # TileJSON V3.0.0 * * Represents a TileJSON metadata object. * ## Links * [TileJSON Spec](https://github.com/mapbox/tilejson-spec/blob/master/3.0.0/schema.json) */ export interface MapboxTileJSONMetadata { /** * Version of the TileJSON spec used. * Matches the pattern: `\d+\.\d+\.\d+\w?[\w\d]*`. */ tilejson: string; /** Array of tile URL templates. */ tiles: string[]; /** Array of vector layer metadata. */ vector_layers: VectorLayer[]; /** Attribution string. */ attribution?: string; /** Bounding box array [west, south, east, north]. */ bounds?: BBox; /** Center coordinate array [longitude, latitude, zoom]. */ center?: [lon: number, lat: number, zoom: number]; /** Array of data source URLs. */ data?: string[]; /** Description of the tileset. */ description?: string; /** Fill zoom level. Must be between 0 and 30. */ fillzoom?: number; /** Array of UTFGrid URL templates. */ grids?: string[]; /** Legend of the tileset. */ legend?: string; /** Maximum zoom level. Must be between 0 and 30. */ maxzoom?: number; /** Minimum zoom level. Must be between 0 and 30. */ minzoom?: number; /** Name of the tileset. */ name?: string; /** Tile scheme, e.g., `xyz` or `tms`. */ scheme?: Scheme; /** Template for interactivity. */ template?: string; /** Version of the tileset. Matches the pattern: `\d+\.\d+\.\d+\w?[\w\d]*`. */ version?: string; /** Allow additional properties */ [key: string]: unknown; } /** When the input is unknown, it can be either an S2 TileJSON or a Mapbox TileJSON */ export type Metadatas = Metadata | MapboxTileJSONMetadata; /** Builder class to help build the metadata */ export declare class MetadataBuilder { #private; /** @returns - resultant metadata */ commit(): Metadata; /** * Set the name * @param name - name of the data */ setName(name: string): void; /** * Set the extension * @param extension - extension of the data */ setExtension(extension: Extensions): void; /** * Set the scheme of the data. [default=fzxy] * @param scheme - scheme of the data */ setScheme(scheme: Scheme): void; /** * Set the type of the data. [default=vector] * @param type - type of the data */ setType(type: SourceType): void; /** * Set the version of the data * @param version - version of the data */ setVersion(version: string): void; /** * Describe the data * @param description - description of the data */ setDescription(description: string): void; /** * Set the encoding of each vector tile. [default=none] * @param encoding - encoding of each tile */ setEncoding(encoding: Encoding): void; /** * Add an attribution * @param displayName - name of the attribution * @param href - link to the attribution */ addAttribution(displayName: string, href: string): void; /** * Add the layer metadata * @param name - name of the layer * @param layer - layer metadata */ addLayer(name: string, layer: LayerMetaData): void; /** * Add the WM tile metadata * @param zoom - zoom of the tile * @param x - x position of the tile * @param y - y position of the tile * @param llBounds - the lon-lat bounds of the tile */ addTileWM(zoom: number, x: number, y: number, llBounds: BBox): void; /** * Add the S2 tile metadata * @param face - face of the tile * @param zoom - zoom of the tile * @param x - x position of the tile * @param y - y position of the tile * @param llBounds - the lon-lat bounds of the tile */ addTileS2(face: Face, zoom: number, x: number, y: number, llBounds: BBox): void; } /** * If you're not sure which tilejson you are reading (Mapbox's spec or S2's spec), you can treat * the input as either and ensure the output is the same * @param metadatas - the S2 TileJSON or Mapbox TileJSON * @returns - S2 TileJSON */ export declare function toMetadata(metadatas: Metadatas): Metadata; //# sourceMappingURL=index.d.ts.map