diff --git a/src/sources/index.ts b/src/sources/index.ts index 4be769f..99028fa 100644 --- a/src/sources/index.ts +++ b/src/sources/index.ts @@ -4,6 +4,11 @@ export {SOURCE_DEFAULTS} from './base-source'; export type { + VectorLayer, + RasterMetadataBandStats, + RasterBandColorinterp, + RasterMetadataBand, + RasterMetadata, TilejsonResult, GeojsonResult, JsonResult, diff --git a/src/sources/types.ts b/src/sources/types.ts index b039d18..50ec91c 100644 --- a/src/sources/types.ts +++ b/src/sources/types.ts @@ -191,16 +191,51 @@ export interface Tilejson { attribution: string; scheme: string; tiles: string[]; - properties_tiles: string[]; - minresolution: number; - maxresolution: number; minzoom: number; maxzoom: number; - bounds: [number, number, number, number]; - center: [number, number, number]; + bounds: [left: number, bottom: number, right: number, top: number]; + center: [longitute: number, latitude: number, zoom: number]; vector_layers: VectorLayer[]; + + // + // Carto additions over standard Tilejson properties + // + + minresolution: number; + maxresolution: number; + properties_tiles: string[]; tilestats: Tilestats; tileResolution?: TileResolution; + + /** + * Resolution of data in spatial-index dataset (e.g. H3, Quadbin). + * + * @internal + */ + dataresolution?: number; + + /** + * Array of ratios of dropped features per zoom level. + * + * Example: `[0,0,0.5]` - means that 50% of features are dropped at zoom 2 and bigger. + * + * @internal + */ + fraction_dropped_per_zoom?: number[]; + + /** + * Names of bands - rasters only. + * + * @internal + */ + raster_bands?: string[]; + + /** + * Raster metadata - rasters only. + * + * @internal + */ + raster_metadata?: RasterMetadata; } export interface Tilestats { @@ -221,12 +256,116 @@ export interface Attribute { } export interface VectorLayer { + // tilejson standard id: string; minzoom: number; maxzoom: number; fields: Record; + + // Carto additions over standard Tilejson properties + geometry_type?: string; } +export type RasterMetadataBandStats = { + approximated_stats?: boolean; + min: number; + max: number; + mean: number; + stddev: number; + sum: number; + sum_squares: number; + count: number; + + /** + * Quantiles by number of buckets. + * + * Example: + * ```ts + * { + * // for 3 buckets, first 1/3 of items lies in range [min, 20], second 1/3 is in [20, 40], and last 1/3 is in [40, max] + * 3: [20, 40], + * 4: [20, 30, 50], for 4 buckets ... + * } + * ``` + */ + quantiles?: Record; + + /** + * Top values by number of values. + * + * Key of dictionary is value, value is count. + * Key order is random. + * + * Example: + * ``` + * { + * 3: 5, // means there are 5 pixels with value 3 + * 11: 222, + * 12: 333, // means that 12 is most common value with count 333 + * ... // (assuming 333 was largest value in dict) + * } + * ``` + */ + top_values?: Record; + + /** + * Raster loader version. + */ + version?: string; +}; + +export enum RasterBandColorinterp { + Gray = 'gray', + Red = 'red', + Green = 'green', + Blue = 'blue', + Alpha = 'alpha', + Palette = 'palette', +} + +export type RasterMetadataBand = { + type: string; + name: string; + stats: RasterMetadataBandStats; + /** + * Known values: + * * `palette`: use unique value and `colortable` ad default mapping + * * `red`, `green`, `blue`: use the band as color channel + * * `gray`: use the band as grayscale + */ + colorinterp?: string | RasterBandColorinterp; // use RasterBandColorinterp, but it's external value, so let's use string + + /** + * Default color mapping for unique values (or if coloprinterp is `palette`) + */ + colortable?: Record; + + /** + * No value representation. + * Observed values: + * * `'nan'` for `NaN` + * * `number`: both as string as number, so parsing is needed + */ + nodata: string | number; // 255, '0', 'nan' +}; + +export type RasterMetadata = { + block_resolution: number; + minresolution: number; + maxresolution: number; + nodata: number | string; + bands: RasterMetadataBand[]; + bounds: [left: number, bottom: number, right: number, top: number]; + center: [longitute: number, latitude: number, zoom: number]; + width: number; + height: number; + block_width: number; + block_height: number; + num_blocks: number; + num_pixels: number; + pixel_resolution: number; +}; + export type TilejsonResult = Tilejson & {accessToken: string}; export type GeojsonResult = {type: 'FeatureCollection'; features: Feature[]}; export type JsonResult = any[];