mobility-toolbox-js 3.0.0-beta.3 → 3.0.0-beta.32

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.
Files changed (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +17 -11
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +39819 -32088
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +5 -2
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +103 -0
  87. package/ol/layers/Layer.js +38 -0
  88. package/ol/layers/MaplibreLayer.d.ts +167 -0
  89. package/ol/layers/MaplibreLayer.js +115 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +315 -265
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +32 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +136 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +122 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -8,52 +8,6 @@ class WebSocketAPI {
8
8
  constructor() {
9
9
  this.defineProperties();
10
10
  }
11
- defineProperties() {
12
- Object.defineProperties(this, {
13
- closed: {
14
- get: () => !!(!this.websocket ||
15
- this.websocket.readyState === this.websocket.CLOSED),
16
- },
17
- closing: {
18
- get: () => !!(this.websocket &&
19
- this.websocket.readyState === this.websocket.CLOSING),
20
- },
21
- connecting: {
22
- get: () => !!(this.websocket &&
23
- this.websocket.readyState === this.websocket.CONNECTING),
24
- },
25
- open: {
26
- get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN),
27
- },
28
- /**
29
- * Array of message to send on open.
30
- * @type {Array<string>}
31
- * @private
32
- */
33
- messagesOnOpen: {
34
- value: [],
35
- writable: true,
36
- },
37
- /**
38
- * Array of subscriptions.
39
- * @type {Array<WebSocketSubscription>}
40
- * @private
41
- */
42
- subscriptions: {
43
- value: [],
44
- writable: true,
45
- },
46
- /**
47
- * List of channels subscribed.
48
- * @type {WebSocketSubscribed}
49
- * @private
50
- */
51
- subscribed: {
52
- value: {},
53
- writable: true,
54
- },
55
- });
56
- }
57
11
  /**
58
12
  * Get the websocket request string.
59
13
  *
@@ -71,6 +25,27 @@ class WebSocketAPI {
71
25
  reqStr += params.id ? ` ${params.id}` : '';
72
26
  return reqStr.trim();
73
27
  }
28
+ addEvents(onMessage, onError) {
29
+ if (this.websocket) {
30
+ this.websocket.addEventListener('message', onMessage);
31
+ if (onError) {
32
+ this.websocket.addEventListener('error', onError);
33
+ this.websocket.addEventListener('close', onError);
34
+ }
35
+ }
36
+ }
37
+ /**
38
+ * Close the websocket definitively.
39
+ *
40
+ * @private
41
+ */
42
+ close() {
43
+ if (this.websocket && (this.open || this.connecting)) {
44
+ this.websocket.onclose = () => { };
45
+ this.websocket.close();
46
+ this.messagesOnOpen = [];
47
+ }
48
+ }
74
49
  /**
75
50
  * (Re)connect the websocket.
76
51
  *
@@ -109,65 +84,94 @@ class WebSocketAPI {
109
84
  this.subscribePreviousSubscriptions();
110
85
  }
111
86
  }
112
- /**
113
- * Close the websocket definitively.
114
- *
115
- * @private
116
- */
117
- close() {
118
- if (this.websocket && (this.open || this.connecting)) {
119
- this.websocket.onclose = () => { };
120
- this.websocket.close();
121
- this.messagesOnOpen = [];
122
- }
87
+ defineProperties() {
88
+ Object.defineProperties(this, {
89
+ closed: {
90
+ get: () => !!(!this.websocket ||
91
+ this.websocket.readyState === this.websocket.CLOSED),
92
+ },
93
+ closing: {
94
+ get: () => !!(this.websocket &&
95
+ this.websocket.readyState === this.websocket.CLOSING),
96
+ },
97
+ connecting: {
98
+ get: () => !!(this.websocket &&
99
+ this.websocket.readyState === this.websocket.CONNECTING),
100
+ },
101
+ /**
102
+ * Array of message to send on open.
103
+ * @type {Array<string>}
104
+ * @private
105
+ */
106
+ messagesOnOpen: {
107
+ value: [],
108
+ writable: true,
109
+ },
110
+ open: {
111
+ get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN),
112
+ },
113
+ /**
114
+ * List of channels subscribed.
115
+ * @type {WebSocketSubscribed}
116
+ * @private
117
+ */
118
+ subscribed: {
119
+ value: {},
120
+ writable: true,
121
+ },
122
+ /**
123
+ * Array of subscriptions.
124
+ * @type {Array<WebSocketSubscription>}
125
+ * @private
126
+ */
127
+ subscriptions: {
128
+ value: [],
129
+ writable: true,
130
+ },
131
+ });
123
132
  }
124
133
  /**
125
- * Sends a message to the websocket.
134
+ * Sends a get request to the websocket.
135
+ * The callback is called only once, when the response is received or when the call returns an error.
126
136
  *
127
- * @param {message} message Message to send.
137
+ * @param {Object} params Parameters for the websocket get request
138
+ * @param {function} cb callback on message event
139
+ * @param {function} errorCb Callback on error and close event
128
140
  * @private
129
141
  */
130
- send(message) {
131
- if (!this.websocket || this.closed || this.closing) {
132
- return;
133
- }
134
- const send = () => {
135
- var _a;
136
- (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(message);
142
+ get(params, cb, errorCb) {
143
+ const requestString = WebSocketAPI.getRequestString('GET', params);
144
+ this.send(requestString);
145
+ // We wrap the callbacks to make sure they are called only once.
146
+ const once = (callback) =>
147
+ // @ts-expect-error : Spread error
148
+ (...args) => {
149
+ // @ts-expect-error : Spread error
150
+ callback(...args);
151
+ const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
152
+ const { onErrorCb, onMessageCb } = this.requests[index];
153
+ this.removeEvents(onMessageCb, onErrorCb);
154
+ this.requests.splice(index, 1);
137
155
  };
138
- if (!this.open) {
139
- // This 'if' avoid sending 2 identical BBOX message on open,
140
- if (!this.messagesOnOpen.includes(message)) {
141
- this.messagesOnOpen.push(message);
142
- this.websocket.addEventListener('open', () => {
143
- this.messagesOnOpen = [];
144
- send();
145
- });
146
- this.websocket.addEventListener('close', () => {
147
- this.messagesOnOpen = [];
148
- });
149
- }
150
- }
151
- else if (!this.messagesOnOpen.includes(message)) {
152
- send();
156
+ const { onErrorCb, onMessageCb } = this.listen(params, once(cb), errorCb && once(errorCb));
157
+ // Store requests and callbacks to be able to remove them.
158
+ if (!this.requests) {
159
+ this.requests = [];
153
160
  }
154
- }
155
- addEvents(onMessage, onError) {
156
- if (this.websocket) {
157
- this.websocket.addEventListener('message', onMessage);
158
- if (onError) {
159
- this.websocket.addEventListener('error', onError);
160
- this.websocket.addEventListener('close', onError);
161
- }
161
+ const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
162
+ const newReq = {
163
+ cb,
164
+ errorCb,
165
+ onErrorCb,
166
+ onMessageCb,
167
+ params,
168
+ requestString,
169
+ };
170
+ if (index > -1) {
171
+ this.requests[index] = newReq;
162
172
  }
163
- }
164
- removeEvents(onMessage, onError) {
165
- if (this.websocket) {
166
- this.websocket.removeEventListener('message', onMessage);
167
- if (onError) {
168
- this.websocket.removeEventListener('error', onError);
169
- this.websocket.removeEventListener('close', onError);
170
- }
173
+ else {
174
+ this.requests.push(newReq);
171
175
  }
172
176
  }
173
177
  /**
@@ -213,64 +217,46 @@ class WebSocketAPI {
213
217
  });
214
218
  };
215
219
  this.addEvents(onMessage, errorCb);
216
- return { onMessageCb: onMessage, onErrorCb: errorCb };
220
+ return { onErrorCb: errorCb, onMessageCb: onMessage };
217
221
  }
218
- /**
219
- * Unlisten websocket messages.
220
- *
221
- * @param {Object} params Parameters for the websocket get request.
222
- * @param {function} cb Callback used when listen.
223
- * @private
224
- */
225
- unlisten(params, cb) {
226
- [...(this.subscriptions || []), ...(this.requests || [])]
227
- .filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb))
228
- .forEach(({ onMessageCb, onErrorCb }) => {
229
- this.removeEvents(onMessageCb, onErrorCb);
230
- });
222
+ removeEvents(onMessage, onError) {
223
+ if (this.websocket) {
224
+ this.websocket.removeEventListener('message', onMessage);
225
+ if (onError) {
226
+ this.websocket.removeEventListener('error', onError);
227
+ this.websocket.removeEventListener('close', onError);
228
+ }
229
+ }
231
230
  }
232
231
  /**
233
- * Sends a get request to the websocket.
234
- * The callback is called only once, when the response is received or when the call returns an error.
232
+ * Sends a message to the websocket.
235
233
  *
236
- * @param {Object} params Parameters for the websocket get request
237
- * @param {function} onMessage callback on message event
238
- * @param {function} onError Callback on error and close event
234
+ * @param {message} message Message to send.
239
235
  * @private
240
236
  */
241
- get(params, cb, errorCb) {
242
- const requestString = WebSocketAPI.getRequestString('GET', params);
243
- this.send(requestString);
244
- // We wrap the callbacks to make sure they are called only once.
245
- const once = (callback) =>
246
- // @ts-ignore: Spread error
247
- (...args) => {
248
- // @ts-ignore: Spread error
249
- callback(...args);
250
- const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
251
- const { onMessageCb, onErrorCb } = this.requests[index];
252
- this.removeEvents(onMessageCb, onErrorCb);
253
- this.requests.splice(index, 1);
254
- };
255
- const { onMessageCb, onErrorCb } = this.listen(params, once(cb), errorCb && once(errorCb));
256
- // Store requests and callbacks to be able to remove them.
257
- if (!this.requests) {
258
- this.requests = [];
237
+ send(message) {
238
+ if (!this.websocket || this.closed || this.closing) {
239
+ return;
259
240
  }
260
- const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
261
- const newReq = {
262
- params,
263
- requestString,
264
- cb,
265
- errorCb,
266
- onMessageCb,
267
- onErrorCb,
241
+ const send = () => {
242
+ var _a;
243
+ (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(message);
268
244
  };
269
- if (index > -1) {
270
- this.requests[index] = newReq;
245
+ if (!this.open) {
246
+ // This 'if' avoid sending 2 identical BBOX message on open,
247
+ if (!this.messagesOnOpen.includes(message)) {
248
+ this.messagesOnOpen.push(message);
249
+ this.websocket.addEventListener('open', () => {
250
+ this.messagesOnOpen = [];
251
+ send();
252
+ });
253
+ this.websocket.addEventListener('close', () => {
254
+ this.messagesOnOpen = [];
255
+ });
256
+ }
271
257
  }
272
- else {
273
- this.requests.push(newReq);
258
+ else if (!this.messagesOnOpen.includes(message)) {
259
+ send();
274
260
  }
275
261
  }
276
262
  /**
@@ -283,10 +269,10 @@ class WebSocketAPI {
283
269
  * @private
284
270
  */
285
271
  subscribe(params, cb, errorCb, quiet = false) {
286
- const { onMessageCb, onErrorCb } = this.listen(params, cb, errorCb);
272
+ const { onErrorCb, onMessageCb } = this.listen(params, cb, errorCb);
287
273
  const reqStr = WebSocketAPI.getRequestString('', params);
288
274
  const index = this.subscriptions.findIndex((subcr) => params.channel === subcr.params.channel && cb === subcr.cb);
289
- const newSubscr = { params, cb, errorCb, onMessageCb, onErrorCb, quiet };
275
+ const newSubscr = { cb, errorCb, onErrorCb, onMessageCb, params, quiet };
290
276
  if (index > -1) {
291
277
  this.subscriptions[index] = newSubscr;
292
278
  }
@@ -301,6 +287,35 @@ class WebSocketAPI {
301
287
  this.subscribed[reqStr] = true;
302
288
  }
303
289
  }
290
+ /**
291
+ * After an auto reconnection we need to re-subscribe to the channels.
292
+ */
293
+ subscribePreviousSubscriptions() {
294
+ // Before to subscribe previous subscriptions we make sure they
295
+ // are all defined as unsubscribed, because this code is asynchrone
296
+ // and a subscription could have been added in between.
297
+ Object.keys(this.subscribed).forEach((key) => {
298
+ this.subscribed[key] = false;
299
+ });
300
+ // Subscribe all previous subscriptions.
301
+ [...this.subscriptions].forEach((s) => {
302
+ this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
303
+ });
304
+ }
305
+ /**
306
+ * Unlisten websocket messages.
307
+ *
308
+ * @param {Object} params Parameters for the websocket get request.
309
+ * @param {function} cb Callback used when listen.
310
+ * @private
311
+ */
312
+ unlisten(params, cb) {
313
+ [...(this.subscriptions || []), ...(this.requests || [])]
314
+ .filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb))
315
+ .forEach(({ onErrorCb, onMessageCb }) => {
316
+ this.removeEvents(onMessageCb, onErrorCb);
317
+ });
318
+ }
304
319
  /**
305
320
  * Unsubscribe from a channel.
306
321
  * @param {string} source source to unsubscribe from
@@ -309,7 +324,7 @@ class WebSocketAPI {
309
324
  */
310
325
  unsubscribe(source, cb) {
311
326
  const toRemove = this.subscriptions.filter((s) => s.params.channel === source && (!cb || s.cb === cb));
312
- toRemove.forEach(({ onMessageCb, onErrorCb }) => {
327
+ toRemove.forEach(({ onErrorCb, onMessageCb }) => {
313
328
  this.removeEvents(onMessageCb, onErrorCb);
314
329
  });
315
330
  this.subscriptions = this.subscriptions.filter((s) => s.params.channel !== source || (cb && s.cb !== cb));
@@ -323,20 +338,5 @@ class WebSocketAPI {
323
338
  this.subscribed[source] = false;
324
339
  }
325
340
  }
326
- /**
327
- * After an auto reconnection we need to re-subscribe to the channels.
328
- */
329
- subscribePreviousSubscriptions() {
330
- // Before to subscribe previous subscriptions we make sure they
331
- // are all defined as unsubscribed, because this code is asynchrone
332
- // and a subscription could have been added in between.
333
- Object.keys(this.subscribed).forEach((key) => {
334
- this.subscribed[key] = false;
335
- });
336
- // Subscribe all previous subscriptions.
337
- [...this.subscriptions].forEach((s) => {
338
- this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
339
- });
340
- }
341
341
  }
342
342
  export default WebSocketAPI;
package/api/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as RoutingAPI } from "./RoutingAPI";
2
+ export { default as StopsAPI } from "./StopsAPI";
3
+ export { default as RealtimeAPI, RealtimeModes } from "./RealtimeAPI";
package/api/index.js CHANGED
@@ -1,3 +1,3 @@
1
+ export { default as RealtimeAPI, RealtimeModes } from './RealtimeAPI';
1
2
  export { default as RoutingAPI } from './RoutingAPI';
2
3
  export { default as StopsAPI } from './StopsAPI';
3
- export { default as RealtimeAPI, RealtimeModes } from './RealtimeAPI';
@@ -0,0 +1,76 @@
1
+ export default dummy;
2
+ export type Station = GeoJSONFeature;
3
+ export type StationProperties = {
4
+ transfers: Transfer[];
5
+ elevatorOutOfOrder: boolean;
6
+ uic: number;
7
+ name: string;
8
+ networkLines: NetworkLine[];
9
+ hasElevator: boolean;
10
+ hasZOB: boolean;
11
+ hasAccessibility: boolean;
12
+ type: string;
13
+ };
14
+ export type NetworkLine = {
15
+ /**
16
+ * Identifier of the line.
17
+ */
18
+ id: number;
19
+ /**
20
+ * Color of the line (CSS color string).
21
+ */
22
+ color: string;
23
+ /**
24
+ * Stroke color of the line (CSS color string).
25
+ */
26
+ stroke: string;
27
+ /**
28
+ * Name of the line.
29
+ */
30
+ name: string;
31
+ /**
32
+ * Text color of the line (CSS color string).
33
+ */
34
+ text_color: string;
35
+ };
36
+ export type Transfer = {
37
+ /**
38
+ * Mode of transportation (ex: U-Bahn).
39
+ */
40
+ mot: string;
41
+ /**
42
+ * Array of lines name (ex: ["U4", "U5"]).
43
+ */
44
+ lines: string[];
45
+ };
46
+ /**
47
+ * @typedef {GeoJSONFeature} Station
48
+ * @property {StationProperties} properties Returns the station's properties.
49
+ * @property {GeoJSONPoint} geometry Returns a point.
50
+ */
51
+ /**
52
+ * @typedef {Object} StationProperties
53
+ * @property {Transfer[]} transfers
54
+ * @property {boolean} elevatorOutOfOrder
55
+ * @property {number} uic
56
+ * @property {string} name
57
+ * @property {NetworkLine[]} networkLines
58
+ * @property {boolean} hasElevator
59
+ * @property {boolean} hasZOB
60
+ * @property {boolean} hasAccessibility
61
+ * @property {string} type
62
+ */
63
+ /**
64
+ * @typedef {Object} NetworkLine
65
+ * @property {number} id Identifier of the line.
66
+ * @property {string} color Color of the line (CSS color string).
67
+ * @property {string} stroke Stroke color of the line (CSS color string).
68
+ * @property {string} name Name of the line.
69
+ * @property {string} text_color Text color of the line (CSS color string).
70
+ */
71
+ /**
72
+ * @typedef {Object} Transfer
73
+ * @property {string} mot Mode of transportation (ex: U-Bahn).
74
+ * @property {string[]} lines Array of lines name (ex: ["U4", "U5"]).
75
+ */
76
+ declare function dummy(): void;
package/api/typedefs.js CHANGED
@@ -1,30 +1,30 @@
1
- /**
2
- * @typedef {Object} Departure
3
- * @property {number} time Timestamp in ms.
4
- * @property {boolean} no_stop_between
5
- * @property {number} train_number
6
- * @property {string[]} to
7
- * @property {number} ris_aimed_time Timestamp in ms.
8
- * @property {number} updated_at Timestamp in ms.
9
- * @property {boolean} new_to
10
- * @property {number} min_arrival_time Timestamp in ms.
11
- * @property {string[]} next_stoppoints List of next stops. Like value in at_station_ds100.
12
- * @property {number} ris_estimated_time Timestamp in ms.
13
- * @property {NetworkLine} line
14
- * @property {boolean} has_fzo if true this departure has realtime data.
15
- * @property {number} train_id
16
- * @property {string} platform
17
- * @property {?*} state
18
- * @property {number} fzo_estimated_time Timestamp in ms.
19
- * @property {?*} formation
20
- * @property {?*} no_stop_till
21
- * @property {number} train_type
22
- * @property {number} call_id
23
- * @property {string} created_at Timestamp in ms.
24
- * @property {string} at_station_ds100
25
- * @property {number} timediff Timestamp in ms.
26
- *
27
- */
1
+ // /**
2
+ // * @typedef {Object} Departure
3
+ // * @property {number} time Timestamp in ms.
4
+ // * @property {boolean} no_stop_between
5
+ // * @property {number} train_number
6
+ // * @property {string[]} to
7
+ // * @property {number} ris_aimed_time Timestamp in ms.
8
+ // * @property {number} updated_at Timestamp in ms.
9
+ // * @property {boolean} new_to
10
+ // * @property {number} min_arrival_time Timestamp in ms.
11
+ // * @property {string[]} next_stoppoints List of next stops. Like value in at_station_ds100.
12
+ // * @property {number} ris_estimated_time Timestamp in ms.
13
+ // * @property {NetworkLine} line
14
+ // * @property {boolean} has_fzo if true this departure has realtime data.
15
+ // * @property {number} train_id
16
+ // * @property {string} platform
17
+ // * @property {?*} state
18
+ // * @property {number} fzo_estimated_time Timestamp in ms.
19
+ // * @property {?*} formation
20
+ // * @property {?*} no_stop_till
21
+ // * @property {number} train_type
22
+ // * @property {number} call_id
23
+ // * @property {string} created_at Timestamp in ms.
24
+ // * @property {string} at_station_ds100
25
+ // * @property {number} timediff Timestamp in ms.
26
+ // *
27
+ // */
28
28
  /**
29
29
  * @typedef {GeoJSONFeature} Station
30
30
  * @property {StationProperties} properties Returns the station's properties.
@@ -55,21 +55,6 @@
55
55
  * @property {string} mot Mode of transportation (ex: U-Bahn).
56
56
  * @property {string[]} lines Array of lines name (ex: ["U4", "U5"]).
57
57
  */
58
- /**
59
- * @typedef {GeoJSONFeature} StopSequence
60
- */
61
- /**
62
- * @typedef {GeoJSONFeature} RealtimeTrajectory
63
- */
64
- /**
65
- * @typedef {GeoJSONFeature} FullTrajectory
66
- */
67
- /**
68
- * @typedef {GeoJSONFeature} Vehicle
69
- */
70
- /**
71
- * @typedef {GeoJSONFeature} ExtraGeom
72
- */
73
58
  // These lines is to block TypeScript to add "use strict;" in the outputed file.
74
59
  const dummy = () => { };
75
60
  export default dummy;
@@ -0,0 +1,53 @@
1
+ import { Feature, FeatureCollection } from 'geojson';
2
+ import { StopsAPI } from '../../api';
3
+ import { StopsAPIOptions } from '../../api/StopsAPI';
4
+ import { StopsParameters } from '../../types';
5
+ export type StopFinderControlCommonOptions = {
6
+ apiParams: StopsParameters;
7
+ element: HTMLElement;
8
+ onSuggestionClick?: (suggestion: Feature, evt: MouseEvent) => void;
9
+ placeholder?: string;
10
+ } & StopsAPIOptions;
11
+ /**
12
+ * A class representing a stop finder control to display on map.
13
+ * This class only draw the html elements.
14
+ * The geographic logic must be implemented by subclasses.
15
+ *
16
+ * @private
17
+ */
18
+ declare class StopFinderControlCommon {
19
+ abortController?: AbortController;
20
+ api: StopsAPI;
21
+ apiParams: StopsParameters;
22
+ clearElt?: HTMLDivElement;
23
+ inputElt?: HTMLInputElement;
24
+ options?: StopFinderControlCommonOptions;
25
+ placeholder: string;
26
+ suggestionsElt?: HTMLElement;
27
+ /**
28
+ * Constructor.
29
+ *
30
+ * @param {Object} options Options
31
+ * @param {HTMLElement} options.element HTML element where to attach input and suggestions.
32
+ * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/). See StopsAPI.
33
+ * @param {string} [options.url='https://api.geops.io/tracker/v1'] Stops service url. See StopsAPI.
34
+ * @param {string} [options.placeholder='Search for a stop...'] Input field placeholder.
35
+ * @param {StopsSearchParams} [options.apiParams={ limit: 20 }] Request parameters. See [Stops service documentation](https://developer.geops.io/apis/5dcbd702a256d90001cf1361/).
36
+ */
37
+ constructor(options: StopFinderControlCommonOptions);
38
+ /**
39
+ * Clear the search field and close the control.
40
+ */
41
+ clear(): void;
42
+ createElement({ element }: StopFinderControlCommonOptions): void;
43
+ render(featureCollection?: FeatureCollection): void;
44
+ /**
45
+ * Launch a search.
46
+ *
47
+ * @param {String} q The query to search for.
48
+ * @param {AbortController} abortController Abort controller used to cancel the request.
49
+ * @return {Promise<Array<GeoJSONFeature>>} An array of GeoJSON features with coordinates in [EPSG:4326](http://epsg.io/4326).
50
+ */
51
+ search(q: string, abortController: AbortController): Promise<void>;
52
+ }
53
+ export default StopFinderControlCommon;