mobility-toolbox-js 3.0.0-beta.32 → 3.0.0-beta.33
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/api/HttpAPI.js +1 -3
- package/api/RealtimeAPI.d.ts +3 -3
- package/api/WebSocketAPI.js +0 -1
- package/common/styles/realtimeDefaultStyle.js +0 -5
- package/common/styles/realtimeHeadingStyle.js +0 -5
- package/common/styles/realtimeSimpleStyle.d.ts +0 -1
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/utils/RealtimeEngine.d.ts +224 -0
- package/common/utils/RealtimeEngine.js +565 -0
- package/common/utils/getLayersAsFlatArray.d.ts +0 -1
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/realtimeConfig.d.ts +1 -1
- package/common/utils/realtimeConfig.js +0 -1
- package/maplibre/layers/RealtimeLayer.d.ts +50 -109
- package/maplibre/layers/RealtimeLayer.js +108 -111
- package/mbt.js +5122 -13362
- package/mbt.js.map +4 -4
- package/mbt.min.js +67 -70
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +5 -4
- package/ol/controls/RoutingControl.js +2 -29
- package/ol/controls/StopFinderControl.d.ts +2 -5
- package/ol/controls/StopFinderControl.js +0 -3
- package/ol/layers/MaplibreLayer.d.ts +18 -10
- package/ol/layers/MaplibreLayer.js +18 -10
- package/ol/layers/MaplibreStyleLayer.d.ts +39 -27
- package/ol/layers/MaplibreStyleLayer.js +33 -28
- package/ol/layers/RealtimeLayer.d.ts +72 -124
- package/ol/layers/RealtimeLayer.js +130 -168
- package/ol/mixins/PropertiesLayerMixin.d.ts +4 -6
- package/ol/mixins/PropertiesLayerMixin.js +0 -2
- package/ol/renderers/RealtimeLayerRenderer.js +6 -31
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/routingStyle.d.ts +0 -1
- package/ol/styles/routingStyle.js +2 -7
- package/package.json +31 -30
- package/types/common.d.ts +2 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
- package/common/mixins/RealtimeLayerMixin.js +0 -751
package/api/HttpAPI.js
CHANGED
|
@@ -14,9 +14,7 @@ import getUrlWithParams from '../common/utils/getUrlWithParams';
|
|
|
14
14
|
*/
|
|
15
15
|
class HttpAPI {
|
|
16
16
|
constructor(options) {
|
|
17
|
-
/** @private */
|
|
18
17
|
this.url = options.url;
|
|
19
|
-
/** @private */
|
|
20
18
|
this.apiKey = options.apiKey;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
@@ -29,7 +27,7 @@ class HttpAPI {
|
|
|
29
27
|
if (!this.url) {
|
|
30
28
|
throw new Error(`No url defined for request to ${this.url}/${path}`);
|
|
31
29
|
}
|
|
32
|
-
if (!this.url && !this.apiKey &&
|
|
30
|
+
if (!this.url && !this.apiKey && !this.url.includes('key=')) {
|
|
33
31
|
// eslint-disable-next-line no-console
|
|
34
32
|
throw new Error(`No apiKey defined for request to ${this.url}`);
|
|
35
33
|
}
|
package/api/RealtimeAPI.d.ts
CHANGED
|
@@ -60,13 +60,13 @@ export declare const RealtimeModes: {
|
|
|
60
60
|
* @public
|
|
61
61
|
*/
|
|
62
62
|
declare class RealtimeAPI {
|
|
63
|
-
_bbox?: RealtimeBbox;
|
|
64
|
-
_buffer?: number[];
|
|
65
|
-
_url: string;
|
|
66
63
|
private pingInterval;
|
|
67
64
|
private pingIntervalMs;
|
|
68
65
|
private reconnectTimeout?;
|
|
69
66
|
private reconnectTimeoutMs?;
|
|
67
|
+
_bbox?: RealtimeBbox;
|
|
68
|
+
_buffer?: number[];
|
|
69
|
+
_url: string;
|
|
70
70
|
version: RealtimeVersion;
|
|
71
71
|
wsApi: WebSocketAPI;
|
|
72
72
|
/**
|
package/api/WebSocketAPI.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import createCanvas from '../utils/createCanvas';
|
|
2
|
-
/** @private */
|
|
3
2
|
const cacheDelayBg = {};
|
|
4
3
|
/**
|
|
5
4
|
* Draw circle delay background
|
|
@@ -25,7 +24,6 @@ export const getDelayBgCanvas = (origin, radius, color) => {
|
|
|
25
24
|
}
|
|
26
25
|
return cacheDelayBg[key];
|
|
27
26
|
};
|
|
28
|
-
/** @private */
|
|
29
27
|
const cacheDelayText = {};
|
|
30
28
|
/**
|
|
31
29
|
* Draw delay text
|
|
@@ -55,7 +53,6 @@ export const getDelayTextCanvas = (text, fontSize, font, delayColor, delayOutlin
|
|
|
55
53
|
}
|
|
56
54
|
return cacheDelayText[key];
|
|
57
55
|
};
|
|
58
|
-
/** @private */
|
|
59
56
|
const cacheCircle = {};
|
|
60
57
|
/**
|
|
61
58
|
* Draw colored circle with black border
|
|
@@ -90,7 +87,6 @@ export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixel
|
|
|
90
87
|
}
|
|
91
88
|
return cacheCircle[key];
|
|
92
89
|
};
|
|
93
|
-
/** @private */
|
|
94
90
|
const cacheText = {};
|
|
95
91
|
/**
|
|
96
92
|
* Draw text in the circle
|
|
@@ -129,7 +125,6 @@ export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, ha
|
|
|
129
125
|
}
|
|
130
126
|
return cacheText[key];
|
|
131
127
|
};
|
|
132
|
-
/** @private */
|
|
133
128
|
const cache = {};
|
|
134
129
|
/**
|
|
135
130
|
* A tracker style that take in account the delay.
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import createCanvas from '../utils/createCanvas';
|
|
2
2
|
import { getBgColor } from '../utils/realtimeConfig';
|
|
3
3
|
import realtimeDefaultStyle from './realtimeDefaultStyle';
|
|
4
|
-
/** @private */
|
|
5
4
|
const rotateCanvas = (canvas, rotation) => {
|
|
6
5
|
const ctx = canvas.getContext('2d');
|
|
7
6
|
ctx === null || ctx === void 0 ? void 0 : ctx.translate(canvas.width / 2, canvas.height / 2);
|
|
8
7
|
ctx === null || ctx === void 0 ? void 0 : ctx.rotate(rotation);
|
|
9
8
|
ctx === null || ctx === void 0 ? void 0 : ctx.translate(-canvas.width / 2, -canvas.height / 2);
|
|
10
9
|
};
|
|
11
|
-
/** @private */
|
|
12
10
|
const arrowCache = {};
|
|
13
|
-
/** @private */
|
|
14
11
|
const getArrowCanvas = (fillColor) => {
|
|
15
12
|
const key = `${fillColor}`;
|
|
16
13
|
if (!arrowCache[key]) {
|
|
@@ -35,9 +32,7 @@ const getArrowCanvas = (fillColor) => {
|
|
|
35
32
|
}
|
|
36
33
|
return arrowCache[key];
|
|
37
34
|
};
|
|
38
|
-
/** @private */
|
|
39
35
|
const bufferArrowCache = {};
|
|
40
|
-
/** @private */
|
|
41
36
|
const getBufferArrowCanvas = (canvas, fillColor, rotation) => {
|
|
42
37
|
const margin = 20;
|
|
43
38
|
const bufferKey = `${fillColor},${canvas.width},${canvas.height},${rotation}`;
|
|
@@ -0,0 +1,224 @@
|
|
|
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, AnyLayer, AnyRealtimeLayer, 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?: (realtimeLayer: AnyRealtimeLayer) => void;
|
|
30
|
+
onStop?: (realtimeLayer: AnyRealtimeLayer) => 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: AnyLayer) => void;
|
|
80
|
+
onStop?: (realtimeLayer: AnyLayer) => 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
|
+
* @param {number} zoom
|
|
112
|
+
*/
|
|
113
|
+
getRefreshTimeInMs(): number;
|
|
114
|
+
/**
|
|
115
|
+
* Get vehicle.
|
|
116
|
+
* @param {function} filterFc A function use to filter results.
|
|
117
|
+
* @return {Array<Object>} Array of vehicle.
|
|
118
|
+
*/
|
|
119
|
+
getVehicle(filterFc: FilterFunction): RealtimeTrajectory[];
|
|
120
|
+
/**
|
|
121
|
+
* Request feature information for a given coordinate.
|
|
122
|
+
*
|
|
123
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate.
|
|
124
|
+
* @param {Object} options Options See child classes to see which options are supported.
|
|
125
|
+
* @param {number} [options.resolution=1] The resolution of the map.
|
|
126
|
+
* @param {number} [options.nb=Infinity] The max number of vehicles to return.
|
|
127
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
128
|
+
*/
|
|
129
|
+
getVehiclesAtCoordinate(coordinate: Coordinate, options?: LayerGetFeatureInfoOptions): FeatureCollection;
|
|
130
|
+
/**
|
|
131
|
+
* Callback on websocket's deleted_vehicles channel events.
|
|
132
|
+
* It removes the trajectory from the list.
|
|
133
|
+
*
|
|
134
|
+
* @private
|
|
135
|
+
* @override
|
|
136
|
+
*/
|
|
137
|
+
onDeleteTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrainId>): void;
|
|
138
|
+
onDocumentVisibilityChange(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Callback on websocket's trajectory channel events.
|
|
141
|
+
* It adds a trajectory to the list.
|
|
142
|
+
*
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
onTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrajectory>): void;
|
|
146
|
+
/**
|
|
147
|
+
* On zoomend we adjust the time interval of the update of vehicles positions.
|
|
148
|
+
*
|
|
149
|
+
* @param evt Event that triggered the function.
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
onZoomEnd(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Remove all trajectories that are in the past.
|
|
155
|
+
*/
|
|
156
|
+
purgeOutOfDateTrajectories(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Determine if the trajectory is useless and should be removed from the list or not.
|
|
159
|
+
* By default, this function exclude vehicles:
|
|
160
|
+
* - that have their trajectory outside the current extent and
|
|
161
|
+
* - that aren't in the MOT list.
|
|
162
|
+
*
|
|
163
|
+
* @param {RealtimeTrajectory} trajectory
|
|
164
|
+
* @param {Array<number>} extent
|
|
165
|
+
* @param {number} zoom
|
|
166
|
+
* @return {boolean} if the trajectory must be displayed or not.
|
|
167
|
+
* @private
|
|
168
|
+
*/
|
|
169
|
+
purgeTrajectory(trajectory: RealtimeTrajectory): boolean;
|
|
170
|
+
removeTrajectory(trajectoryOrId: RealtimeTrainId | RealtimeTrajectory): void;
|
|
171
|
+
/**
|
|
172
|
+
* Render the trajectories requesting an animation frame and cancelling the previous one.
|
|
173
|
+
* This function must be overrided by children to provide the correct parameters.
|
|
174
|
+
*
|
|
175
|
+
* @param {object} viewState The view state of the map.
|
|
176
|
+
* @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
|
|
177
|
+
* @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
|
|
178
|
+
* @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
|
|
179
|
+
* @param {number} [viewState.rotation = 0] Rotation of the map to render.
|
|
180
|
+
* @param {number} viewState.resolution Resolution of the map to render.
|
|
181
|
+
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
182
|
+
* drawn at the last known coordinate. Use this for performance optimization
|
|
183
|
+
* during map navigation.
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
renderTrajectories(noInterpolate?: boolean): void;
|
|
187
|
+
/**
|
|
188
|
+
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
|
|
189
|
+
*
|
|
190
|
+
* @param {object} viewState The view state of the map.
|
|
191
|
+
* @param {number[2]} viewState.center Center coordinate of the map in mercator coordinate.
|
|
192
|
+
* @param {number[4]} viewState.extent Extent of the map in mercator coordinates.
|
|
193
|
+
* @param {number[2]} viewState.size Size ([width, height]) of the canvas to render.
|
|
194
|
+
* @param {number} [viewState.rotation = 0] Rotation of the map to render.
|
|
195
|
+
* @param {number} viewState.resolution Resolution of the map to render.
|
|
196
|
+
* @param {boolean} noInterpolate If true trajectories are not interpolated but
|
|
197
|
+
* drawn at the last known coordinate. Use this for performance optimization
|
|
198
|
+
* during map navigation.
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
|
|
202
|
+
setBbox(): void;
|
|
203
|
+
start(): void;
|
|
204
|
+
/**
|
|
205
|
+
* Start the clock.
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
startUpdateTime(): void;
|
|
209
|
+
stop(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Stop the clock.
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
stopUpdateTime(): void;
|
|
215
|
+
get mode(): RealtimeMode;
|
|
216
|
+
set mode(newMode: RealtimeMode);
|
|
217
|
+
get speed(): number;
|
|
218
|
+
set speed(newSpeed: number);
|
|
219
|
+
get style(): RealtimeStyleFunction;
|
|
220
|
+
set style(newStyle: RealtimeStyleFunction);
|
|
221
|
+
get time(): Date;
|
|
222
|
+
set time(newTime: Date | number);
|
|
223
|
+
}
|
|
224
|
+
export default RealtimeEngine;
|