UNPKG

mobility-toolbox-js

Version:

Toolbox for JavaScript applications in the domains of mobility and logistics.

197 lines (196 loc) 7.43 kB
import Layer from 'ol/layer/Layer'; import VectorLayer from 'ol/layer/Vector'; import { Vector as VectorSource } from 'ol/source'; import Source from 'ol/source/Source'; import RealtimeEngine from '../../common/utils/RealtimeEngine'; import { type RealtimeMode, type RealtimeRenderState, type RealtimeStopSequence, type RealtimeStyleFunction, type RealtimeTrainId, type RealtimeTrajectory, type ViewState } from '../../types'; import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer'; import type { DebouncedFunc } from 'lodash'; import type { Map, MapEvent } from 'ol'; import type { EventsKey } from 'ol/events'; import type { FeatureLike } from 'ol/Feature'; import type Feature from 'ol/Feature'; import type { ObjectEvent } from 'ol/Object'; import type { State } from 'ol/View'; import type { FilterFunction, SortFunction } from '../../common/typedefs'; import type { RealtimeEngineOptions } from '../../common/utils/RealtimeEngine'; import type { RealtimeAPI } from '../../maplibre'; import type { RealtimeStyleOptions } from '../../types'; import type { MobilityLayerOptions } from './Layer'; export type RealtimeLayerOptions = { allowRenderWhenAnimating?: boolean; fullTrajectoryStyle?: (feature: FeatureLike, resolution: number, layer: RealtimeLayer) => void; maxNbFeaturesRequested?: number; styleOptions?: Partial<RealtimeStyleOptions>; } & MobilityLayerOptions & Omit<RealtimeEngineOptions, 'styleOptions'>; /** * An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/). * * @example * import { RealtimeLayer } from 'mobility-toolbox-js/ol'; * * const layer = new RealtimeLayer({ * apiKey: "yourApiKey" * // allowRenderWhenAnimating: false, * // url: "wss://api.geops.io/tracker-ws/v1/", * }); * * * @see <a href="/doc/class/build/api/RealtimeAPI%20js~RealtimeAPI%20html-offset-anchor">RealtimeAPI</a> * @see <a href="/example/ol-realtime">OpenLayers Realtime layer example</a> * * * @extends {ol/layer/Layer~Layer} * * * @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating. * @public */ declare class RealtimeLayer extends Layer<Source> { allowRenderWhenAnimating?: boolean; currentZoom?: number; engine: RealtimeEngine; maxNbFeaturesRequested: number; olEventsKeys: EventsKey[]; onMoveEndDebounced: DebouncedFunc<(evt: MapEvent | ObjectEvent) => void>; onZoomEndDebounced: DebouncedFunc<(evt: MapEvent | ObjectEvent) => void>; renderedViewState: State | undefined; vectorLayer: VectorLayer<VectorSource>; get api(): RealtimeAPI; set api(api: RealtimeAPI); get canvas(): import("../../types").AnyCanvas | undefined; get filter(): FilterFunction | undefined; set filter(filter: FilterFunction); get hoverVehicleId(): RealtimeTrainId | undefined; set hoverVehicleId(id: RealtimeTrainId); get mode(): RealtimeMode; set mode(mode: RealtimeMode); get pixelRatio(): number | undefined; get selectedVehicleId(): RealtimeTrainId | undefined; set selectedVehicleId(id: RealtimeTrainId); get sort(): SortFunction | undefined; set sort(sort: SortFunction); get style(): RealtimeStyleFunction; set style(style: RealtimeStyleFunction); get styleOptions(): RealtimeStyleOptions; set styleOptions(options: RealtimeStyleOptions); get time(): Date; set time(time: Date); get trajectories(): Record<string, RealtimeTrajectory> | undefined; /** * Constructor. * * @param {RealtimeLayerOptions} options * @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating. * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/). * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The [geOps Realtime API](https://developer.geops.io/apis/realtime/) url. * @public */ constructor(options: RealtimeLayerOptions); /** * Add a trajectory. * @param trajectory */ addTrajectory(trajectory: RealtimeTrajectory): void; attachToMap(): void; cleanVectorLayer(): void; /** * Create a copy of the RealtimeLayer. * * @param {Object} newOptions Options to override. See constructor. * @return {RealtimeLayer} A RealtimeLayer * @public */ clone(newOptions: RealtimeLayerOptions): RealtimeLayer; createRenderer(): RealtimeLayerRenderer; /** * Destroy the container of the tracker. */ detachFromMap(): void; /** * Get the full trajectory of a vehicle as features. * * @param {string} id A vehicle's id. * @returns {Promise<Feature[]>} A list of features representing a full trajectory. * @public */ getFullTrajectory(id: RealtimeTrainId): Promise<Feature[]>; /** * Get the stop sequences of a vehicle. * * @param {string} id A vehicle's id. * @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences. * @public */ getStopSequences(id: RealtimeTrainId): Promise<RealtimeStopSequence[]>; /** * Get full trajectory and stop sequences of a vehicle. * * @param {RealtimeTrainId} id A vehicle's id. * @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences. */ getTrajectoryInfos(id: RealtimeTrainId): Promise<{ fullTrajectory: Feature[]; stopSequences: RealtimeStopSequence[]; }>; getVehicles(filterFunc: FilterFunction): RealtimeTrajectory[]; getViewState(): { center?: undefined; extent?: undefined; pixelRatio?: undefined; resolution?: undefined; rotation?: undefined; size?: undefined; visible?: undefined; zoom?: undefined; } | { center: import("ol/coordinate").Coordinate | undefined; extent: import("ol/extent").Extent; pixelRatio: number | undefined; resolution: number | undefined; rotation: number; size: import("ol/size").Size | undefined; visible: boolean; zoom: number | undefined; }; highlight(features: Feature | Feature[]): void; /** * Highlight the trajectory of journey. */ highlightTrajectory(id: RealtimeTrainId): Promise<Feature[] | undefined>; onMoveEnd(): void; onRealtimeEngineIdle(): void; /** * Callback when the RealtimeEngine has rendered successfully. */ onRealtimeEngineRender(renderState: RealtimeRenderState, viewState: ViewState): void; onZoomEnd(): void; /** * Remove a trajectory. * * @param trajectoryOrId */ removeTrajectory(trajectoryOrId: RealtimeTrainId | RealtimeTrajectory): void; /** * Render the trajectories of the vehicles. * @deprecated Use this.engine.renderTrajectories instead. */ renderTrajectories(noInterpolate?: boolean): void; select(features: Feature | Feature[]): void; setMapInternal(map: Map): void; shouldRender(): boolean | undefined; /** * Start the rendering. * * @public */ start(): void; /** * Stop the rendering. * * @public */ stop(): void; private updateHighlightFeatures; } export default RealtimeLayer;