mobility-toolbox-js 3.0.0-beta.7 → 3.0.0-beta.9
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.d.ts +31 -0
- package/api/RealtimeAPI.d.ts +359 -0
- package/api/RealtimeAPI.js +96 -89
- package/api/RoutingAPI.d.ts +37 -0
- package/api/StopsAPI.d.ts +38 -0
- package/api/WebSocketAPI.d.ts +153 -0
- package/api/index.d.ts +3 -0
- package/api/typedefs.d.ts +178 -0
- package/common/controls/StopFinderControlCommon.d.ts +53 -0
- package/common/index.d.ts +2 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +273 -0
- package/common/styles/index.d.ts +4 -0
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/typedefs.d.ts +212 -0
- package/common/utils/compareDepartures.d.ts +10 -0
- 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 +3 -0
- package/common/utils/getLayersAsFlatArray.js +5 -1
- package/common/utils/getMapGlCopyrights.d.ts +17 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts +8 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/index.d.ts +16 -0
- package/common/utils/realtimeConfig.d.ts +64 -0
- package/common/utils/removeDuplicate.d.ts +9 -0
- package/common/utils/renderTrajectories.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts +15 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- 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 +35 -0
- package/maplibre/controls/index.d.ts +1 -0
- package/maplibre/index.d.ts +5 -0
- package/maplibre/layers/Layer.d.ts +28 -0
- package/maplibre/layers/RealtimeLayer.d.ts +160 -0
- package/maplibre/layers/RealtimeLayer.js +2 -2
- package/maplibre/layers/index.d.ts +2 -0
- package/maplibre/utils/getMercatorResolution.d.ts +7 -0
- package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
- package/maplibre/utils/index.d.ts +2 -0
- package/mbt.js +137 -114
- package/mbt.js.map +3 -3
- package/mbt.min.js +13 -13
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.js +18 -8
- package/ol/controls/RoutingControl.d.ts +209 -0
- package/ol/controls/RoutingControl.js +3 -0
- package/ol/controls/StopFinderControl.d.ts +37 -0
- package/ol/controls/StopFinderControl.js +3 -0
- package/ol/controls/index.d.ts +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/layers/MapGlLayer.d.ts +144 -0
- package/ol/layers/MapGlLayer.js +3 -1
- package/ol/layers/MaplibreLayer.d.ts +63 -0
- package/ol/layers/MaplibreStyleLayer.d.ts +235 -0
- package/ol/layers/MaplibreStyleLayer.js +1 -1
- package/ol/layers/RealtimeLayer.d.ts +285 -0
- package/ol/layers/RealtimeLayer.js +13 -7
- package/ol/layers/index.d.ts +3 -0
- package/ol/mixins/MobilityLayerMixin.d.ts +98 -0
- package/ol/mixins/MobilityLayerMixin.js +1 -4
- package/ol/mixins/PropertiesLayerMixin.d.ts +127 -0
- package/ol/mixins/PropertiesLayerMixin.js +5 -4
- package/ol/renderers/MaplibreLayerRenderer.d.ts +20 -0
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
- package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
- package/ol/renderers/RealtimeLayerRenderer.js +9 -9
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/routingStyle.d.ts +4 -0
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
- package/ol/utils/getFeatureInfoAtCoordinate.js +1 -1
- package/ol/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/setupTests.d.ts +1 -0
package/api/HttpAPI.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type HttpAPIOptions = {
|
|
2
|
+
url: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Common class to access to a geOps api using http.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { API } from 'mobility-toolbox-js/api';
|
|
10
|
+
*
|
|
11
|
+
* const api = new HttpApi({
|
|
12
|
+
* url: [yourUrl],
|
|
13
|
+
* apiKey: [yourApiKey]
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @classproperty {string} url Url of the service.
|
|
17
|
+
* @classproperty {string} apiKey Api key to access the service.
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
declare class HttpAPI {
|
|
21
|
+
url: string;
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
constructor(options: HttpAPIOptions);
|
|
24
|
+
/**
|
|
25
|
+
* Append the apiKey before sending the request.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
fetch(path: string, params: Object, config: RequestInit): Promise<any>;
|
|
30
|
+
}
|
|
31
|
+
export default HttpAPI;
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import WebSocketAPI, { WebSocketAPIMessageCallback, WebSocketAPIMessageEventData, WebSocketAPIParameters } from './WebSocketAPI';
|
|
2
|
+
import type { RealtimeMode, RealtimeDeparture, RealtimeNews, RealtimeStation, RealtimeExtraGeom, RealtimeTrainId, RealtimeGeneralizationLevel, RealtimeFullTrajectory, RealtimeTrajectoryResponse, RealtimeStationId, RealtimeVersion, RealtimeTrajectory, RealtimeTenant, RealtimeBbox } from '../types';
|
|
3
|
+
import { StopSequence } from './typedefs';
|
|
4
|
+
/**
|
|
5
|
+
* @typedef RealtimeAPIOptions
|
|
6
|
+
*/
|
|
7
|
+
export type RealtimeAPIOptions = {
|
|
8
|
+
url?: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
version?: RealtimeVersion;
|
|
11
|
+
bbox?: RealtimeBbox;
|
|
12
|
+
buffer?: number[];
|
|
13
|
+
pingIntervalMs?: number;
|
|
14
|
+
reconnectTimeoutMs?: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type RealtimeAPIExtraGeomsById = {
|
|
17
|
+
[index: string]: RealtimeExtraGeom;
|
|
18
|
+
};
|
|
19
|
+
export type RealtimeAPIDeparturesById = {
|
|
20
|
+
[index: string]: RealtimeDeparture;
|
|
21
|
+
};
|
|
22
|
+
export type RealtimeModesType = {
|
|
23
|
+
RAW: RealtimeMode;
|
|
24
|
+
TOPOGRAPHIC: RealtimeMode;
|
|
25
|
+
SCHEMATIC: RealtimeMode;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Enum for Realtime modes.
|
|
29
|
+
* @readonly
|
|
30
|
+
* @typedef {string} RealtimeMode
|
|
31
|
+
* @property {string} RAW "raw"
|
|
32
|
+
* @property {string} SCHEMATIC "schematic"
|
|
33
|
+
* @property {string} TOPOGRAPHIC "topographic"
|
|
34
|
+
* @enum {RealtimeMode}
|
|
35
|
+
*/
|
|
36
|
+
export declare const RealtimeModes: {
|
|
37
|
+
RAW: RealtimeMode;
|
|
38
|
+
TOPOGRAPHIC: RealtimeMode;
|
|
39
|
+
SCHEMATIC: RealtimeMode;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* This class provides convenience methods to use to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* import { RealtimeAPI } from 'mobility-toolbox-js/api';
|
|
46
|
+
*
|
|
47
|
+
* const api = new RealtimeAPI({
|
|
48
|
+
* apiKey: "yourApiKey",
|
|
49
|
+
* bbox: [782001, 5888803, 923410, 5923660, 11, "mots=rail"],
|
|
50
|
+
* // url: "wss://api.geops.io/tracker-ws/v1/",
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* api.open();
|
|
54
|
+
*
|
|
55
|
+
* api.subscribeTrajectory('topographic', (data) => {
|
|
56
|
+
* console.log('Log trajectories:', JSON.stringify(data.content));
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
declare class RealtimeAPI {
|
|
62
|
+
_url: string;
|
|
63
|
+
get url(): string;
|
|
64
|
+
set url(newUrl: string);
|
|
65
|
+
_bbox?: RealtimeBbox;
|
|
66
|
+
/**
|
|
67
|
+
* The bounding box to receive data from.\
|
|
68
|
+
* Example: [minX, minY, maxX, maxY, zoom, mots , gen_level, tenant, ...]\
|
|
69
|
+
* \
|
|
70
|
+
* Where:
|
|
71
|
+
* - **minX**: a string representation of an integer (not a float) representing the minimal X coordinate (in EPSG:3857) of a bounding box\
|
|
72
|
+
*
|
|
73
|
+
* - **minY**: a string representation of an integer (not a float) representing the minimal Y coordinate (in EPSG:3857) of a bounding box\
|
|
74
|
+
*
|
|
75
|
+
* - **maxX**: a string representation of an integer (not a float) representing the maximal X coordinate (in EPSG:3857) of a bounding box\
|
|
76
|
+
*
|
|
77
|
+
* - **maxY**: a string representation of an integer (not a float) representing the maximal Y coordinate (in EPSG:3857) of a bounding box\
|
|
78
|
+
*
|
|
79
|
+
* - **zoom**: a string representation of an integer representing the zoom level (from 4 to 22). When zoom < 8 only the trains are displayed for performance reasons.\
|
|
80
|
+
*
|
|
81
|
+
* - **mots**: A comma separated list of modes of transport. **Optional**.\
|
|
82
|
+
* Example: "mots=rail,subway".\
|
|
83
|
+
*
|
|
84
|
+
* - **gen_level**: An integer representing the generalization level. **Optional**.\
|
|
85
|
+
* Example: "gen_level=5"\
|
|
86
|
+
*
|
|
87
|
+
* - **tenant**: A string representing the tenant. **Optional**.\
|
|
88
|
+
* Example: "tenant=sbb"\
|
|
89
|
+
*
|
|
90
|
+
* - ...: Any other values added to the bbox will be send to the server
|
|
91
|
+
*
|
|
92
|
+
* @type {string[]}
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
get bbox(): RealtimeBbox | undefined;
|
|
97
|
+
set bbox(newBbox: RealtimeBbox | undefined);
|
|
98
|
+
_buffer?: number[];
|
|
99
|
+
get buffer(): number[] | undefined;
|
|
100
|
+
set buffer(newBuffer: number[] | undefined);
|
|
101
|
+
version: RealtimeVersion;
|
|
102
|
+
wsApi: WebSocketAPI;
|
|
103
|
+
private pingInterval;
|
|
104
|
+
private pingIntervalMs;
|
|
105
|
+
private reconnectTimeout?;
|
|
106
|
+
private reconnectTimeoutMs?;
|
|
107
|
+
/**
|
|
108
|
+
* Constructor
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} options A string representing the url of the service or an object containing the url and the apiKey.
|
|
111
|
+
* @param {string} options.url Url to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
|
|
112
|
+
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
113
|
+
* @param {string[]} options.bbox The bounding box to receive data from.
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
constructor(options?: RealtimeAPIOptions);
|
|
117
|
+
/**
|
|
118
|
+
* Open the websocket connection.
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
open(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Close the websocket connection without reconnection.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
close(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
|
|
131
|
+
*/
|
|
132
|
+
reset(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Callback when the websocket is opened and ready.
|
|
135
|
+
* It applies the bbox and the projection.
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
138
|
+
onOpen(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Callback when the websocket is closed by the server.
|
|
141
|
+
* It auto reconnects after a timeout.
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
onClose(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Send GET to a channel.
|
|
147
|
+
*
|
|
148
|
+
* @param {string | WebSocketAPIParameters} channelOrParams Name of the websocket channel to send GET or an object representing parameters to send
|
|
149
|
+
* @return {Promise<WebSocketAPIMessageEventData<?>>} A websocket response.
|
|
150
|
+
*/
|
|
151
|
+
get(channelOrParams: string | WebSocketAPIParameters): Promise<WebSocketAPIMessageEventData<any>>;
|
|
152
|
+
/**
|
|
153
|
+
* Subscribe to a channel.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} channel Name of the websocket channel to subscribe.
|
|
156
|
+
* @param {function} onSuccess Callback when the subscription succeeds.
|
|
157
|
+
* @param {function} onError Callback when the subscription fails.
|
|
158
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
subscribe(channel: string, onSuccess: WebSocketAPIMessageCallback<any>, onError?: EventListener, quiet?: boolean): void;
|
|
162
|
+
/**
|
|
163
|
+
* Unsubscribe both modes of a channel.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} channel Name of the websocket channel to unsubscribe.
|
|
166
|
+
* @param {string} suffix Suffix to add to the channel name.
|
|
167
|
+
* @param {function} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
unsubscribe(channel: string, suffix?: string, onMessage?: WebSocketAPIMessageCallback<any>): void;
|
|
171
|
+
/**
|
|
172
|
+
* Subscribe to departures channel of a given station.
|
|
173
|
+
*
|
|
174
|
+
* @param {number} stationId UIC of the station.
|
|
175
|
+
* @param {Boolean} sortByMinArrivalTime Sort by minimum arrival time
|
|
176
|
+
* @param {function(departures:Departure[])} onMessage Function called on each message of the channel.
|
|
177
|
+
* @param {function} onError Callback when the subscription fails.
|
|
178
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
subscribeDepartures(stationId: number, onMessage: WebSocketAPIMessageCallback<RealtimeDeparture>, onError?: EventListener, quiet?: boolean): void;
|
|
182
|
+
/**
|
|
183
|
+
* Unsubscribe from current departures channel.
|
|
184
|
+
* @param {RealtimeStationId} id Station's id
|
|
185
|
+
* @param {function(data: { content: RealtimeDeparture[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
186
|
+
* @public
|
|
187
|
+
*/
|
|
188
|
+
unsubscribeDepartures(id: RealtimeStationId, onMessage?: WebSocketAPIMessageCallback<RealtimeDeparture>): void;
|
|
189
|
+
/**
|
|
190
|
+
* Subscribe to the disruptions channel for tenant.
|
|
191
|
+
*
|
|
192
|
+
* @param {function(data: { content: RealtimeNews[] })} onMessage Function called on each message of the channel.
|
|
193
|
+
* @param {function} onError Callback when the subscription fails.
|
|
194
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
subscribeDisruptions(tenant: RealtimeTenant, onMessage: WebSocketAPIMessageCallback<RealtimeNews>, onError?: EventListener, quiet?: boolean): void;
|
|
198
|
+
/**
|
|
199
|
+
* Unsubscribe disruptions.
|
|
200
|
+
*
|
|
201
|
+
* @param {function(data: { content: RealtimeNews[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
202
|
+
* @public
|
|
203
|
+
*/
|
|
204
|
+
unsubscribeDisruptions(tenant: RealtimeTenant, onMessage?: WebSocketAPIMessageCallback<RealtimeNews>): void;
|
|
205
|
+
/**
|
|
206
|
+
* Return a station with a given uic number and a mode.
|
|
207
|
+
*
|
|
208
|
+
* @param {number} uic UIC of the station.
|
|
209
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
210
|
+
* @return {Promise<{data: { content: RealtimeStation }}>} A station.
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
getStation(uic: RealtimeStationId, mode: RealtimeMode): Promise<WebSocketAPIMessageEventData<RealtimeStation>>;
|
|
214
|
+
/**
|
|
215
|
+
* Get the list of ststions available for a specifc mode. The promise is resolved every 100ms
|
|
216
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
217
|
+
* @param {number} timeout = 100 Duration in ms between each promise resolve calls.
|
|
218
|
+
* @return {Promise<RealtimeStation[]>} An array of stations.
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
getStations(mode: RealtimeMode, timeout?: number): Promise<RealtimeStation[]>;
|
|
222
|
+
/**
|
|
223
|
+
* Subscribe to stations channel.
|
|
224
|
+
* One message pro station.
|
|
225
|
+
*
|
|
226
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
227
|
+
* @param {function(data: { content: RealtimeStation })} onMessage Function called on each message of the channel.
|
|
228
|
+
* @param {function} onError Callback when the subscription fails.
|
|
229
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
230
|
+
* @public
|
|
231
|
+
*/
|
|
232
|
+
subscribeStations(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeStation>, onError?: EventListener, quiet?: boolean): void;
|
|
233
|
+
/**
|
|
234
|
+
* Unsubscribe to stations channel.
|
|
235
|
+
* @param {function(data: { content: RealtimeStation })} onMessage The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
|
|
236
|
+
* @public
|
|
237
|
+
*/
|
|
238
|
+
unsubscribeStations(onMessage?: WebSocketAPIMessageCallback<RealtimeStation>): void;
|
|
239
|
+
/**
|
|
240
|
+
* Subscribe to extra_geoms channel.
|
|
241
|
+
*
|
|
242
|
+
* @param {function(data: { content: RealtimeExtraGeom })} onMessage Function called on each message of the channel.
|
|
243
|
+
* @param {function} onError Callback when the subscription fails.
|
|
244
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
245
|
+
*/
|
|
246
|
+
subscribeExtraGeoms(onMessage: WebSocketAPIMessageCallback<RealtimeExtraGeom>, onError?: EventListener, quiet?: boolean): void;
|
|
247
|
+
/**
|
|
248
|
+
* Unsubscribe to extra_geoms channel.
|
|
249
|
+
* @param {function(data: { content: RealtimeExtraGeom })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
250
|
+
*/
|
|
251
|
+
unsubscribeExtraGeoms(onMessage: WebSocketAPIMessageCallback<RealtimeExtraGeom>): void;
|
|
252
|
+
/**
|
|
253
|
+
* Return a partial trajectory with a given id and a mode.
|
|
254
|
+
*
|
|
255
|
+
* @param {number} trainId The identifier of a trajectory.
|
|
256
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
257
|
+
* @return {Promise<{data: { content: RealtimeTrajectory }}>} A trajectory.
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
getTrajectory(id: RealtimeTrainId, mode: RealtimeMode): Promise<WebSocketAPIMessageEventData<RealtimeTrajectory>>;
|
|
261
|
+
/**
|
|
262
|
+
* Subscribe to trajectory channel.
|
|
263
|
+
*
|
|
264
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
265
|
+
* @param {function(data: { content: RealtimeTrajectoryResponse[] })} onMessage Function called on each message of the channel.
|
|
266
|
+
* @param {function} onError Callback when the subscription fails.
|
|
267
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
268
|
+
* @public
|
|
269
|
+
*/
|
|
270
|
+
subscribeTrajectory(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeTrajectoryResponse[] | RealtimeTrajectoryResponse>, onError?: EventListener, quiet?: boolean): void;
|
|
271
|
+
/**
|
|
272
|
+
* Unsubscribe to trajectory channels.
|
|
273
|
+
* @param {function(data: { content: RealtimeTrajectoryResponse[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
unsubscribeTrajectory(onMessage: WebSocketAPIMessageCallback<RealtimeTrajectoryResponse[]>): void;
|
|
277
|
+
/**
|
|
278
|
+
* Subscribe to deleted_vhicles channel.
|
|
279
|
+
*
|
|
280
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
281
|
+
* @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
282
|
+
* @param {function} onError Callback when the subscription fails.
|
|
283
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
284
|
+
*/
|
|
285
|
+
subscribeDeletedVehicles(mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeTrainId>, onError?: EventListener, quiet?: boolean): void;
|
|
286
|
+
/**
|
|
287
|
+
* Unsubscribe to deleted_vhicles channels.
|
|
288
|
+
* @param {function(data: { content: RealtimeTrainId })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
289
|
+
*/
|
|
290
|
+
unsubscribeDeletedVehicles(onMessage: WebSocketAPIMessageCallback<RealtimeTrainId>): void;
|
|
291
|
+
/**
|
|
292
|
+
* Get a full trajectory of a vehicule .
|
|
293
|
+
*
|
|
294
|
+
* @param {string} id A vehicle id.
|
|
295
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
296
|
+
* @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
|
|
297
|
+
* @return {Promise<{ data: { content: RealtimeFullTrajectory } }>} Return a full trajectory.
|
|
298
|
+
* @public
|
|
299
|
+
*/
|
|
300
|
+
getFullTrajectory(id: RealtimeTrainId, mode: RealtimeMode, generalizationLevel: RealtimeGeneralizationLevel | undefined): Promise<WebSocketAPIMessageEventData<RealtimeFullTrajectory>>;
|
|
301
|
+
/**
|
|
302
|
+
* Subscribe to full_trajectory channel of a given vehicle.
|
|
303
|
+
*
|
|
304
|
+
* @param {string} id A vehicle id.
|
|
305
|
+
* @param {RealtimeMode} mode Realtime mode.
|
|
306
|
+
* @param {function(data: { content: RealtimeFullTrajectory })} onMessage Function called on each message of the channel.
|
|
307
|
+
* @param {function} onError Callback when the subscription fails.
|
|
308
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
309
|
+
* @public
|
|
310
|
+
*/
|
|
311
|
+
subscribeFullTrajectory(id: RealtimeTrainId, mode: RealtimeMode, onMessage: WebSocketAPIMessageCallback<RealtimeFullTrajectory>, onError?: EventListener, quiet?: boolean): void;
|
|
312
|
+
/**
|
|
313
|
+
* Unsubscribe from full_trajectory channel
|
|
314
|
+
*
|
|
315
|
+
* @param {string} id A vehicle id.
|
|
316
|
+
* @param {function(data: { content: RealtimeFullTrajectory })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
317
|
+
* @public
|
|
318
|
+
*/
|
|
319
|
+
unsubscribeFullTrajectory(id: RealtimeTrainId, onMessage?: WebSocketAPIMessageCallback<RealtimeFullTrajectory>): void;
|
|
320
|
+
/**
|
|
321
|
+
* Get the list of stops for this vehicle.
|
|
322
|
+
*
|
|
323
|
+
* @param {string} id A vehicle id.
|
|
324
|
+
* @return {Promise<{ data: { content: StopSequence[] } }>} Returns a stop sequence object.
|
|
325
|
+
* @public
|
|
326
|
+
*/
|
|
327
|
+
getStopSequence(id: RealtimeTrainId): Promise<WebSocketAPIMessageEventData<StopSequence[]>>;
|
|
328
|
+
/**
|
|
329
|
+
* Subscribe to stopsequence channel of a given vehicle.
|
|
330
|
+
*
|
|
331
|
+
* @param {string} id A vehicle id.
|
|
332
|
+
* @param {function(data: { content: StopSequence[] })} onMessage Function called on each message of the channel.
|
|
333
|
+
* @param {function} onError Callback when the subscription fails.
|
|
334
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
335
|
+
* @public
|
|
336
|
+
*/
|
|
337
|
+
subscribeStopSequence(id: RealtimeTrainId, onMessage: WebSocketAPIMessageCallback<StopSequence[]>, onError?: EventListener, quiet?: boolean): void;
|
|
338
|
+
/**
|
|
339
|
+
* Unsubscribe from stopsequence channel
|
|
340
|
+
*
|
|
341
|
+
* @param {string} id A vehicle id.
|
|
342
|
+
* @param {function(data: { content: StopSequence[] })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
unsubscribeStopSequence(id: RealtimeTrainId, onMessage?: WebSocketAPIMessageCallback<StopSequence[]>): void;
|
|
346
|
+
/**
|
|
347
|
+
* Subscribe to healthcheck channel.
|
|
348
|
+
* @param {function(data: { content: string })} onMessage Callback when the subscribe to healthcheck channel succeeds.
|
|
349
|
+
* @param {function} onError Callback when the subscription fails.
|
|
350
|
+
* @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
|
|
351
|
+
*/
|
|
352
|
+
subscribeHealthCheck(onMessage: WebSocketAPIMessageCallback<string>, onError?: EventListener, quiet?: boolean): void;
|
|
353
|
+
/**
|
|
354
|
+
* Unsubscribe to healthcheck channel.
|
|
355
|
+
* @param {function(data: { content: string })} onMessage Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
|
|
356
|
+
*/
|
|
357
|
+
unsubscribeHealthCheck(onMessage?: WebSocketAPIMessageCallback<string>): void;
|
|
358
|
+
}
|
|
359
|
+
export default RealtimeAPI;
|
package/api/RealtimeAPI.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
1
2
|
/* eslint-disable class-methods-use-this */
|
|
2
3
|
import WebSocketAPI from './WebSocketAPI';
|
|
3
4
|
import debounceWebsocketMessages from '../common/utils/debounceWebsocketMessages';
|
|
@@ -17,14 +18,14 @@ export const RealtimeModes = {
|
|
|
17
18
|
SCHEMATIC: 'schematic',
|
|
18
19
|
};
|
|
19
20
|
/**
|
|
20
|
-
* This class provides convenience methods to use to the [geOps
|
|
21
|
+
* This class provides convenience methods to use to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
|
|
21
22
|
*
|
|
22
23
|
* @example
|
|
23
24
|
* import { RealtimeAPI } from 'mobility-toolbox-js/api';
|
|
24
25
|
*
|
|
25
26
|
* const api = new RealtimeAPI({
|
|
26
27
|
* apiKey: "yourApiKey",
|
|
27
|
-
* bbox: [782001, 5888803, 923410, 5923660, 11, "mots=rail],
|
|
28
|
+
* bbox: [782001, 5888803, 923410, 5923660, 11, "mots=rail"],
|
|
28
29
|
* // url: "wss://api.geops.io/tracker-ws/v1/",
|
|
29
30
|
* });
|
|
30
31
|
*
|
|
@@ -34,106 +35,113 @@ export const RealtimeModes = {
|
|
|
34
35
|
* console.log('Log trajectories:', JSON.stringify(data.content));
|
|
35
36
|
* });
|
|
36
37
|
*
|
|
37
|
-
* @classproperty {string} apiKey - Access key for [geOps APIs](https://developer.geops.io/)
|
|
38
|
-
* @classproperty {RealtimeBbox} bbox - The bounding box to receive data from. \ Example: \ [ minX, minY, maxX, maxY, zoom, "tenant=tenant1", "gen_level=5", "mots=mot1,mot2" ]. \ tenant, gen_level and mots are optional.
|
|
39
|
-
* @classproperty {string} url - The [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
|
|
40
38
|
* @public
|
|
41
39
|
*/
|
|
42
40
|
class RealtimeAPI {
|
|
41
|
+
get url() {
|
|
42
|
+
return this._url;
|
|
43
|
+
}
|
|
44
|
+
set url(newUrl) {
|
|
45
|
+
if (this._url !== newUrl) {
|
|
46
|
+
this._url = newUrl;
|
|
47
|
+
// Update the websocket only if the url has changed and the websocket is already open or is opening.
|
|
48
|
+
if (this.wsApi.open || this.wsApi.connecting) {
|
|
49
|
+
this.open();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The bounding box to receive data from.\
|
|
55
|
+
* Example: [minX, minY, maxX, maxY, zoom, mots , gen_level, tenant, ...]\
|
|
56
|
+
* \
|
|
57
|
+
* Where:
|
|
58
|
+
* - **minX**: a string representation of an integer (not a float) representing the minimal X coordinate (in EPSG:3857) of a bounding box\
|
|
59
|
+
*
|
|
60
|
+
* - **minY**: a string representation of an integer (not a float) representing the minimal Y coordinate (in EPSG:3857) of a bounding box\
|
|
61
|
+
*
|
|
62
|
+
* - **maxX**: a string representation of an integer (not a float) representing the maximal X coordinate (in EPSG:3857) of a bounding box\
|
|
63
|
+
*
|
|
64
|
+
* - **maxY**: a string representation of an integer (not a float) representing the maximal Y coordinate (in EPSG:3857) of a bounding box\
|
|
65
|
+
*
|
|
66
|
+
* - **zoom**: a string representation of an integer representing the zoom level (from 4 to 22). When zoom < 8 only the trains are displayed for performance reasons.\
|
|
67
|
+
*
|
|
68
|
+
* - **mots**: A comma separated list of modes of transport. **Optional**.\
|
|
69
|
+
* Example: "mots=rail,subway".\
|
|
70
|
+
*
|
|
71
|
+
* - **gen_level**: An integer representing the generalization level. **Optional**.\
|
|
72
|
+
* Example: "gen_level=5"\
|
|
73
|
+
*
|
|
74
|
+
* - **tenant**: A string representing the tenant. **Optional**.\
|
|
75
|
+
* Example: "tenant=sbb"\
|
|
76
|
+
*
|
|
77
|
+
* - ...: Any other values added to the bbox will be send to the server
|
|
78
|
+
*
|
|
79
|
+
* @type {string[]}
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
get bbox() {
|
|
84
|
+
return this._bbox;
|
|
85
|
+
}
|
|
86
|
+
set bbox(newBbox) {
|
|
87
|
+
if (JSON.stringify(newBbox) !== JSON.stringify(this._bbox)) {
|
|
88
|
+
this._bbox = newBbox;
|
|
89
|
+
if (this.wsApi && this._bbox) {
|
|
90
|
+
this.wsApi.send(`BBOX ${this._bbox.join(' ')}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
get buffer() {
|
|
95
|
+
return this._buffer;
|
|
96
|
+
}
|
|
97
|
+
set buffer(newBuffer) {
|
|
98
|
+
if (JSON.stringify(newBuffer) !== JSON.stringify(this._buffer)) {
|
|
99
|
+
this._buffer = newBuffer;
|
|
100
|
+
if (this.wsApi && this._buffer) {
|
|
101
|
+
this.wsApi.send(`BUFFER ${this._buffer.join(' ')}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
43
105
|
/**
|
|
44
106
|
* Constructor
|
|
45
107
|
*
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {string} options.url Url to the [geOps realtime
|
|
108
|
+
* @param {Object} options A string representing the url of the service or an object containing the url and the apiKey.
|
|
109
|
+
* @param {string} options.url Url to the [geOps realtime API](https://developer.geops.io/apis/realtime/).
|
|
48
110
|
* @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
|
|
49
|
-
* @param {
|
|
111
|
+
* @param {string[]} options.bbox The bounding box to receive data from.
|
|
112
|
+
* @public
|
|
50
113
|
*/
|
|
51
114
|
constructor(options = {}) {
|
|
52
115
|
this.version = '2';
|
|
53
|
-
|
|
54
|
-
this.onOpen = this.onOpen.bind(this);
|
|
55
|
-
}
|
|
56
|
-
defineProperties(options = {}) {
|
|
57
|
-
let opt = options || {};
|
|
116
|
+
let opt = options;
|
|
58
117
|
if (typeof options === 'string') {
|
|
59
118
|
opt = { url: options };
|
|
60
119
|
}
|
|
61
|
-
const { apiKey
|
|
62
|
-
|
|
120
|
+
const { apiKey } = opt;
|
|
121
|
+
const { url } = opt;
|
|
63
122
|
const wsApi = new WebSocketAPI();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (apiKey) {
|
|
68
|
-
url = `${url}?key=${apiKey}`;
|
|
123
|
+
let suffix = '';
|
|
124
|
+
if (apiKey && !(url === null || url === void 0 ? void 0 : url.includes('key='))) {
|
|
125
|
+
suffix = `?key=${apiKey}`;
|
|
69
126
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (this.wsApi && bbox) {
|
|
89
|
-
this.wsApi.send(`BBOX ${bbox.join(' ')}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
buffer: {
|
|
95
|
-
get: () => buffer,
|
|
96
|
-
set: (newBuffer) => {
|
|
97
|
-
if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
|
|
98
|
-
buffer = newBuffer;
|
|
99
|
-
if (this.wsApi) {
|
|
100
|
-
this.wsApi.send(`BUFFER ${buffer.join(' ')}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
version: {
|
|
106
|
-
value: version,
|
|
107
|
-
writable: true,
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* The websocket helper class to connect the websocket.
|
|
111
|
-
*
|
|
112
|
-
* @private
|
|
113
|
-
*/
|
|
114
|
-
wsApi: {
|
|
115
|
-
value: wsApi,
|
|
116
|
-
writable: true,
|
|
117
|
-
},
|
|
118
|
-
/**
|
|
119
|
-
* Interval between PING request in ms.
|
|
120
|
-
* If equal to 0, no PING request are sent.
|
|
121
|
-
* @type {number}
|
|
122
|
-
* @private
|
|
123
|
-
*/
|
|
124
|
-
pingIntervalMs: {
|
|
125
|
-
value: options.pingIntervalMs || 10000,
|
|
126
|
-
writable: true,
|
|
127
|
-
},
|
|
128
|
-
/**
|
|
129
|
-
* Timeout in ms after an automatic reconnection when the websoscket has been closed by the server.
|
|
130
|
-
* @type {number}
|
|
131
|
-
*/
|
|
132
|
-
reconnectTimeoutMs: {
|
|
133
|
-
value: options.pingIntervalMs || 100,
|
|
134
|
-
writable: true,
|
|
135
|
-
},
|
|
136
|
-
});
|
|
127
|
+
this._url = (url || 'wss://api.geops.io/tracker-ws/v1/') + suffix;
|
|
128
|
+
this._buffer = opt.buffer || [100, 100];
|
|
129
|
+
this.version = opt.version || '2';
|
|
130
|
+
/**
|
|
131
|
+
* Interval between PING request in ms.
|
|
132
|
+
* If equal to 0, no PING request are sent.
|
|
133
|
+
* @type {number}
|
|
134
|
+
*/
|
|
135
|
+
this.pingIntervalMs = opt.pingIntervalMs || 10000;
|
|
136
|
+
/**
|
|
137
|
+
* Timeout in ms after an automatic reconnection when the websoscket has been closed by the server.
|
|
138
|
+
* @type {number}
|
|
139
|
+
*/
|
|
140
|
+
this.reconnectTimeoutMs = opt.reconnectTimeoutMs || 100;
|
|
141
|
+
/**
|
|
142
|
+
* The websocket helper class to connect the websocket.
|
|
143
|
+
*/
|
|
144
|
+
this.wsApi = wsApi;
|
|
137
145
|
}
|
|
138
146
|
/**
|
|
139
147
|
* Open the websocket connection.
|
|
@@ -141,7 +149,7 @@ class RealtimeAPI {
|
|
|
141
149
|
* @public
|
|
142
150
|
*/
|
|
143
151
|
open() {
|
|
144
|
-
this.wsApi.connect(this.url, this.onOpen);
|
|
152
|
+
this.wsApi.connect(this.url, this.onOpen.bind(this));
|
|
145
153
|
// Register reconnection on close.
|
|
146
154
|
if (this.wsApi.websocket) {
|
|
147
155
|
this.wsApi.websocket.onclose = () => {
|
|
@@ -160,7 +168,6 @@ class RealtimeAPI {
|
|
|
160
168
|
/**
|
|
161
169
|
* Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
|
|
162
170
|
*/
|
|
163
|
-
// eslint-disable-next-line class-methods-use-this
|
|
164
171
|
reset() {
|
|
165
172
|
this.wsApi.send('RESET');
|
|
166
173
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import HttpAPI from './HttpAPI';
|
|
2
|
+
import { RoutingParameters, RoutingResponse } from '../types';
|
|
3
|
+
export type RoutingAPIOptions = {
|
|
4
|
+
url?: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Access to the [geOps Routing API](https://developer.geops.io/apis/routing).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { RoutingAPI } from 'mobility-toolbox-js';
|
|
12
|
+
*
|
|
13
|
+
* const api = new RoutingAPI({
|
|
14
|
+
* apiKey: [yourApiKey]
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
declare class RoutingAPI extends HttpAPI {
|
|
20
|
+
/**
|
|
21
|
+
* Constructor
|
|
22
|
+
*
|
|
23
|
+
* @param {RoutingAPIOptions} options Options.
|
|
24
|
+
* @param {string} [options.url='https://api.geops.io/routing/v1/'] Service url.
|
|
25
|
+
* @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/).
|
|
26
|
+
*/
|
|
27
|
+
constructor(options?: RoutingAPIOptions);
|
|
28
|
+
/**
|
|
29
|
+
* Route.
|
|
30
|
+
*
|
|
31
|
+
* @param {RoutingParameters} params Request parameters. See [Routing service documentation](https://developer.geops.io/apis/routing/).
|
|
32
|
+
* @param {RequestInit} config Options for the fetch request.
|
|
33
|
+
* @return {Promise<RoutingResponse>} An GeoJSON feature collection with coordinates in [EPSG:4326](http://epsg.io/4326).
|
|
34
|
+
*/
|
|
35
|
+
route(params: RoutingParameters, config: RequestInit): Promise<RoutingResponse>;
|
|
36
|
+
}
|
|
37
|
+
export default RoutingAPI;
|