UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

90 lines (89 loc) 3.88 kB
import type { Session } from './index.js'; import type { Attributions, Encoding, LayerDefinition, LayersMetaData, Projection, Scheme, SourceMetadata, SourceType } from 'style/style.spec.js'; import type { SourceFlushMessage, TileRequest } from '../worker.spec.js'; /** * # Generic Data Source Container * * This class is wrapped by many other source types. It serves to handle all the generic cases * of data sources like fetching metadata, handling flushes, and so on. */ export default class Source { #private; active: boolean; /** Resolver letting us know when the source is built */ resolve: (value: void | PromiseLike<void>) => void; ready: Promise<void>; name: string; path: string; type: SourceType; extension: string; encoding: Encoding; scheme: Scheme; projection: Projection; isTimeFormat: boolean; attributions: Attributions; styleLayers: LayerDefinition[]; layers?: LayersMetaData; minzoom: number; maxzoom: number; size: number; faces: Set<number>; needsToken: boolean; time?: number; session: Session; textEncoder: TextEncoder; /** * @param name - name of the source * @param projection - the projection used * @param layers - the style layers that are associated with this source * @param path - the path to the source to fetch data * @param needsToken - flag indicating if the source requires a token in the fetch * @param session - the session that works with the token to make valid fetch requests on source data behind an API */ constructor(name: string, projection: Projection, layers: LayerDefinition[], path: string, needsToken: boolean | undefined, session: Session); /** * If this function runs, we assume a default quad-tree tile source * @param mapID - the id of the map that is requesting data * @param metadata - the metadata for the source */ build(mapID: string, metadata?: SourceMetadata): Promise<void>; /** * Internal tool to builds the metadata for the source * @param metadata - the source metadata * @param mapID - the id of the map that we will be shipping the render data to */ _buildMetadata(metadata: SourceMetadata, mapID: string): void; /** * All tile requests undergo a basic check on whether that data exists * within the metadata boundaries. layerIndexes exists to set a boundary * of what layers the map is interested in (caused by style change add/edit layer) * @param mapID - the id of the map * @param tile - the tile * @param flushMessage - the flush message */ tileRequest(mapID: string, tile: TileRequest, flushMessage: SourceFlushMessage): Promise<void>; /** * If this function runs, we assume default quad-tree tile source. * In the default case, we want the worker to process the data * @param mapID - the id of the map to ship the eventual render data back to * @param tile - the tile request * @param sourceName - the source name the data to belongs to */ _tileRequest(mapID: string, tile: TileRequest, sourceName: string): Promise<void>; /** * If no data, we still have to let the tile worker know so it can prepare a proper flush * as well as manage cases like "invert" type data. * @param mapID - the id of the map * @param tile - the tile request * @param sourceName - the source name the data to belongs to */ _flush(mapID: string, tile: TileRequest, sourceName: string): void; /** * Fetch a tile * @param path - the base path to the tile data * @param mapID - the id of the map * @param json - flag indicating if the data is json * @returns the raw data or JSON metadata if found */ _fetch<T>(path: string, mapID: string, json?: boolean): Promise<T | undefined>; }