UNPKG

s2maps-gpu

Version:

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

88 lines (87 loc) 3.06 kB
import Cache from './cache.js'; import type Camera from './index.js'; import type { S2CellId } from 's2/gis-tools/index.js'; import type { SensorSource } from 'gl/workflows/workflow.spec.js'; import type { TimeSeriesStyle } from 'style/style.spec.js'; /** Tracker for time sources */ export interface TimeSource { step: number; interval: number; } /** * Animation states * play -> animation based upon startTime -> endTime using cursor * pause -> running through pause duration * stop -> do nothing */ export type TimeLayerState = 'play' | 'pause' | 'stop'; /** Time Series object */ export interface TimeSeries { startTime: number; endTime: number; speed: number; pauseDuration: number; autoPlay: boolean; loop: boolean; cursor: number; state: TimeLayerState; } /** An input texture to a specific time stamp that also points to the next texture if it exists */ export interface SensorTextureDefinition { time?: number; texture?: WebGLTexture; textureNext?: WebGLTexture; } /** * # Time Cache * * Stores and manages time source raster data. */ export default class TimeCache extends Cache<string, SensorSource> { #private; camera: Camera; sources: Record<string, TimeSource>; lastFrame?: number; webworker: boolean; timeSeries: TimeSeries; /** * @param camera - parent camera * @param webworker - true if running in a webworker * @param timeSeries - user defined time series style object */ constructor(camera: Camera, webworker: boolean, timeSeries: TimeSeriesStyle); /** * Add a time source * @param sourceName - the name of the source * @param interval - the interval of the source relative to the starting point of the source */ addSource(sourceName: string, interval: number): void; /** * Add source data to the cache and update the time series * @param id - the id of the tile * @param time - the time of the source * @param sourceName - the name of the source * @param source - the source to add the data to */ addSourceData(id: S2CellId, time: number, sourceName: string, source: SensorSource): void; /** * Get source data * @param id - the id of the tile * @param sourceName - the name of the source * @returns the source texture information and data */ getTextures(id: S2CellId, sourceName: string): SensorTextureDefinition; /** * update layer positions. * play state: increment cursor by speed * deltaTime. If cursor >= endTime, set cursor to pause state or startTime. * pause state: increment cursor by deltaTime. If cursor > pauseDuration, set state to play * @param now - current time * @param render - render function to call after animation state is updated */ animate(now: number, render: () => void): void; /** * rather than animate, the user can specify a time, and this will update to current time * @param time - the time to set */ setTime(time: number): void; }