mobility-toolbox-js 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -3
- package/api/HttpAPI.d.ts +20 -0
- package/api/HttpAPI.js +1 -14
- package/api/RealtimeAPI.d.ts +404 -0
- package/api/RealtimeAPI.js +265 -206
- package/api/RoutingAPI.d.ts +47 -0
- package/api/RoutingAPI.js +17 -7
- package/api/StopsAPI.d.ts +44 -0
- package/api/StopsAPI.js +17 -11
- package/api/WebSocketAPI.d.ts +147 -0
- package/api/WebSocketAPI.js +164 -165
- package/api/index.d.ts +3 -0
- package/api/index.js +1 -1
- package/api/typedefs.d.ts +76 -0
- package/api/typedefs.js +27 -42
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/controls/StopFinderControlCommon.js +32 -32
- package/common/index.d.ts +2 -0
- package/common/index.js +1 -1
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.js +6 -11
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.js +5 -10
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +102 -0
- package/common/typedefs.js +6 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/compareDepartures.d.ts +10 -0
- package/common/utils/compareDepartures.js +2 -2
- package/common/utils/constants.d.ts +5 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
- package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
- package/common/utils/createRealtimeFilters.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/getLayersAsFlatArray.d.ts +2 -0
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.js +1 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +17 -0
- package/common/utils/getVehiclePosition.js +6 -3
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.js +7 -6
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.js +2 -1
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.js +5 -1
- package/common/utils/timeUtils.d.ts +23 -0
- package/common/utils/toMercatorExtent.d.ts +5 -0
- package/iife.d.ts +2 -0
- package/index.d.ts +9 -0
- package/maplibre/controls/CopyrightControl.d.ts +38 -0
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +29 -0
- package/maplibre/layers/Layer.js +2 -3
- package/maplibre/layers/RealtimeLayer.d.ts +124 -0
- package/maplibre/layers/RealtimeLayer.js +154 -118
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
- package/maplibre/utils/getSourceCoordinates.js +6 -5
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +14585 -14557
- package/mbt.js.map +4 -4
- package/mbt.min.js +75 -75
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +39 -0
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +213 -0
- package/ol/controls/RoutingControl.js +250 -264
- package/ol/controls/StopFinderControl.d.ts +56 -0
- package/ol/controls/StopFinderControl.js +24 -5
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/Layer.d.ts +26 -0
- package/ol/layers/Layer.js +39 -0
- package/ol/layers/MaplibreLayer.d.ts +91 -0
- package/ol/layers/MaplibreLayer.js +154 -31
- package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
- package/ol/layers/MaplibreStyleLayer.js +281 -210
- package/ol/layers/RealtimeLayer.d.ts +150 -0
- package/ol/layers/RealtimeLayer.js +210 -206
- package/ol/layers/VectorLayer.d.ts +17 -0
- package/ol/layers/VectorLayer.js +33 -0
- package/ol/layers/index.d.ts +5 -0
- package/ol/layers/index.js +3 -0
- package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
- package/ol/renderers/MaplibreLayerRenderer.js +142 -114
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +50 -70
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +3 -0
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
- package/ol/utils/index.d.ts +1 -0
- package/package.json +44 -44
- package/setupTests.d.ts +1 -0
- package/setupTests.js +17 -4
- package/types/common.d.ts +53 -69
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +98 -95
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
- package/common/mixins/RealtimeLayerMixin.js +0 -743
- package/ol/layers/MapGlLayer.js +0 -142
- package/ol/mixins/MobilityLayerMixin.js +0 -9
- package/ol/mixins/PropertiesLayerMixin.js +0 -142
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { FeatureCollection } from 'geojson';
|
|
2
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
3
|
+
import { RealtimeAPI } from '../../api';
|
|
4
|
+
import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
|
|
5
|
+
import { AnyCanvas, LayerGetFeatureInfoOptions, RealtimeGeneralizationLevel, RealtimeMode, RealtimeMot, RealtimeRenderState, RealtimeStyleFunction, RealtimeStyleOptions, RealtimeTenant, RealtimeTrainId, RealtimeTrajectory, ViewState } from '../../types';
|
|
6
|
+
import { FilterFunction, SortFunction } from '../typedefs';
|
|
7
|
+
import type { Coordinate } from 'ol/coordinate';
|
|
8
|
+
export interface RealtimeEngineOptions {
|
|
9
|
+
api?: RealtimeAPI;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
bbox?: (number | string)[];
|
|
12
|
+
bboxParameters?: Record<string, boolean | boolean[] | number | number[] | string | string[]>;
|
|
13
|
+
buffer?: number[];
|
|
14
|
+
canvas?: HTMLCanvasElement;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
filter?: FilterFunction;
|
|
17
|
+
generalizationLevelByZoom?: RealtimeGeneralizationLevel[];
|
|
18
|
+
getGeneralizationLevelByZoom?: (zoom: number, generalizationLevelByZoom: RealtimeGeneralizationLevel[]) => RealtimeGeneralizationLevel;
|
|
19
|
+
getMotsByZoom?: (zoom: number, motsByZoom: RealtimeMot[][]) => RealtimeMot[];
|
|
20
|
+
getRenderTimeIntervalByZoom?: (zoom: number, renderTimeIntervalByZoom: number[]) => number;
|
|
21
|
+
getViewState?: () => ViewState;
|
|
22
|
+
hoverVehicleId?: RealtimeTrainId;
|
|
23
|
+
isUpdateBboxOnMoveEnd?: boolean;
|
|
24
|
+
live?: boolean;
|
|
25
|
+
minZoomInterpolation?: number;
|
|
26
|
+
mode?: RealtimeMode;
|
|
27
|
+
motsByZoom?: RealtimeMot[][];
|
|
28
|
+
onRender?: (renderState: RealtimeRenderState, viewState: ViewState) => void;
|
|
29
|
+
onStart?: (realtimeEngine: RealtimeEngine) => void;
|
|
30
|
+
onStop?: (realtimeEngine: RealtimeEngine) => void;
|
|
31
|
+
pingIntervalMs?: number;
|
|
32
|
+
pixelRatio?: number;
|
|
33
|
+
prefix?: string;
|
|
34
|
+
renderTimeIntervalByZoom?: number[];
|
|
35
|
+
selectedVehicleId?: RealtimeTrainId;
|
|
36
|
+
shouldRender?: () => boolean;
|
|
37
|
+
sort?: SortFunction;
|
|
38
|
+
speed?: number;
|
|
39
|
+
style?: RealtimeStyleFunction;
|
|
40
|
+
styleOptions?: RealtimeStyleOptions;
|
|
41
|
+
tenant?: RealtimeTenant;
|
|
42
|
+
time?: Date;
|
|
43
|
+
url?: string;
|
|
44
|
+
useDebounce?: boolean;
|
|
45
|
+
useRequestAnimationFrame?: boolean;
|
|
46
|
+
useThrottle?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* This class is responsible for drawing trajectories from a realtime API in a canvas,
|
|
50
|
+
* depending on the map's view state and at a specific time.
|
|
51
|
+
*
|
|
52
|
+
* This class is totally agnostic from Maplibre or OpenLayers and must stay taht way.
|
|
53
|
+
*/
|
|
54
|
+
declare class RealtimeEngine {
|
|
55
|
+
_mode: RealtimeMode;
|
|
56
|
+
_speed: number;
|
|
57
|
+
_style: RealtimeStyleFunction;
|
|
58
|
+
_time: Date;
|
|
59
|
+
api: RealtimeAPI;
|
|
60
|
+
bboxParameters?: Record<string, boolean | boolean[] | number | number[] | string | string[]>;
|
|
61
|
+
canvas?: AnyCanvas;
|
|
62
|
+
debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
|
|
63
|
+
debug: boolean;
|
|
64
|
+
filter?: FilterFunction;
|
|
65
|
+
format: GeoJSON;
|
|
66
|
+
generalizationLevel?: RealtimeGeneralizationLevel;
|
|
67
|
+
generalizationLevelByZoom: RealtimeGeneralizationLevel[];
|
|
68
|
+
getGeneralizationLevelByZoom: (zoom: number) => RealtimeGeneralizationLevel;
|
|
69
|
+
getMotsByZoom: (zoom: number) => RealtimeMot[];
|
|
70
|
+
getRenderTimeIntervalByZoom: (zoom: number) => number;
|
|
71
|
+
getViewState: () => ViewState;
|
|
72
|
+
hoverVehicleId?: RealtimeTrainId;
|
|
73
|
+
isUpdateBboxOnMoveEnd: boolean;
|
|
74
|
+
live?: boolean;
|
|
75
|
+
minZoomInterpolation: number;
|
|
76
|
+
mots?: RealtimeMot[];
|
|
77
|
+
motsByZoom: RealtimeMot[][];
|
|
78
|
+
onRender?: (renderState: RealtimeRenderState, viewState: ViewState) => void;
|
|
79
|
+
onStart?: (realtimeLayer: RealtimeEngine) => void;
|
|
80
|
+
onStop?: (realtimeLayer: RealtimeEngine) => void;
|
|
81
|
+
pixelRatio?: number;
|
|
82
|
+
renderState?: RealtimeRenderState;
|
|
83
|
+
renderTimeIntervalByZoom: number[];
|
|
84
|
+
requestId?: number;
|
|
85
|
+
selectedVehicle: RealtimeTrajectory;
|
|
86
|
+
selectedVehicleId?: RealtimeTrainId;
|
|
87
|
+
shouldRender: () => boolean;
|
|
88
|
+
sort?: SortFunction;
|
|
89
|
+
styleOptions?: RealtimeStyleOptions;
|
|
90
|
+
tenant: RealtimeTenant;
|
|
91
|
+
throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
|
|
92
|
+
trajectories?: Record<RealtimeTrainId, RealtimeTrajectory>;
|
|
93
|
+
updateTimeDelay?: number;
|
|
94
|
+
updateTimeInterval?: number;
|
|
95
|
+
useDebounce?: boolean;
|
|
96
|
+
useRequestAnimationFrame?: boolean;
|
|
97
|
+
useThrottle?: boolean;
|
|
98
|
+
constructor(options: RealtimeEngineOptions);
|
|
99
|
+
/**
|
|
100
|
+
* Add a trajectory.
|
|
101
|
+
* @param {RealtimeTrajectory} trajectory The trajectory to add.
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
addTrajectory(trajectory: RealtimeTrajectory): void;
|
|
105
|
+
attachToMap(): void;
|
|
106
|
+
detachFromMap(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Get the duration before the next update depending on zoom level.
|
|
109
|
+
*
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
getRefreshTimeInMs(): number;
|
|
113
|
+
/**
|
|
114
|
+
* Get vehicle.
|
|
115
|
+
* @param {function} filterFc A function use to filter results.
|
|
116
|
+
* @return {Array<Object>} Array of vehicle.
|
|
117
|
+
*/
|
|
118
|
+
getVehicles(filterFc: FilterFunction): RealtimeTrajectory[];
|
|
119
|
+
/**
|
|
120
|
+
* Request feature information for a given coordinate.
|
|
121
|
+
*
|
|
122
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate.
|
|
123
|
+
* @param {Object} options Options See child classes to see which options are supported.
|
|
124
|
+
* @param {number} [options.resolution=1] The resolution of the map.
|
|
125
|
+
* @param {number} [options.nb=Infinity] The max number of vehicles to return.
|
|
126
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
127
|
+
*/
|
|
128
|
+
getVehiclesAtCoordinate(coordinate: Coordinate, options?: LayerGetFeatureInfoOptions): FeatureCollection;
|
|
129
|
+
/**
|
|
130
|
+
* Callback on websocket's deleted_vehicles channel events.
|
|
131
|
+
* It removes the trajectory from the list.
|
|
132
|
+
*
|
|
133
|
+
* @private
|
|
134
|
+
* @override
|
|
135
|
+
*/
|
|
136
|
+
onDeleteTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrainId>): void;
|
|
137
|
+
onDocumentVisibilityChange(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Callback on websocket's trajectory channel events.
|
|
140
|
+
* It adds a trajectory to the list.
|
|
141
|
+
*
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
onTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrajectory>): void;
|
|
145
|
+
/**
|
|
146
|
+
* On zoomend we adjust the time interval of the update of vehicles positions.
|
|
147
|
+
*
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
onZoomEnd(): void;
|
|
151
|
+
/**
|
|
152
|
+
* Remove all trajectories that are in the past.
|
|
153
|
+
*/
|
|
154
|
+
purgeOutOfDateTrajectories(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Determine if the trajectory is useless and should be removed from the list or not.
|
|
157
|
+
* By default, this function exclude vehicles:
|
|
158
|
+
* - that have their trajectory outside the current extent and
|
|
159
|
+
* - that aren't in the MOT list.
|
|
160
|
+
*
|
|
161
|
+
* @param {RealtimeTrajectory} trajectory
|
|
162
|
+
* @return {boolean} if the trajectory must be displayed or not.
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
purgeTrajectory(trajectory: RealtimeTrajectory): boolean;
|
|
166
|
+
removeTrajectory(trajectoryOrId: RealtimeTrainId | RealtimeTrajectory): void;
|
|
167
|
+
/**
|
|
168
|
+
* Render the trajectories requesting an animation frame and cancelling the previous one.
|
|
169
|
+
* This function must be overrided by children to provide the correct parameters.
|
|
170
|
+
*
|
|
171
|
+
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
172
|
+
* drawn at the last known coordinate. Use this for performance optimization
|
|
173
|
+
* during map navigation.
|
|
174
|
+
* @private
|
|
175
|
+
*/
|
|
176
|
+
renderTrajectories(noInterpolate?: boolean): void;
|
|
177
|
+
/**
|
|
178
|
+
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
|
|
179
|
+
*
|
|
180
|
+
* @param {object} viewState The view state of the map.
|
|
181
|
+
* @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
|
|
182
|
+
* @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
|
|
183
|
+
* @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
|
|
184
|
+
* @param {number} [viewState.rotation = 0] Rotation of the map to render.
|
|
185
|
+
* @param {number} viewState.resolution Resolution of the map to render.
|
|
186
|
+
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
187
|
+
* drawn at the last known coordinate. Use this for performance optimization
|
|
188
|
+
* during map navigation.
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
|
|
192
|
+
setBbox(): void;
|
|
193
|
+
start(): void;
|
|
194
|
+
/**
|
|
195
|
+
* Start the clock.
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
startUpdateTime(): void;
|
|
199
|
+
stop(): void;
|
|
200
|
+
/**
|
|
201
|
+
* Stop the clock.
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
stopUpdateTime(): void;
|
|
205
|
+
get mode(): RealtimeMode;
|
|
206
|
+
set mode(newMode: RealtimeMode);
|
|
207
|
+
get speed(): number;
|
|
208
|
+
set speed(newSpeed: number);
|
|
209
|
+
get style(): RealtimeStyleFunction;
|
|
210
|
+
set style(newStyle: RealtimeStyleFunction);
|
|
211
|
+
get time(): Date;
|
|
212
|
+
set time(newTime: Date | number);
|
|
213
|
+
}
|
|
214
|
+
export default RealtimeEngine;
|