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.
Files changed (130) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +20 -0
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +404 -0
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +47 -0
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +44 -0
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +147 -0
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.d.ts +3 -0
  13. package/api/index.js +1 -1
  14. package/api/typedefs.d.ts +76 -0
  15. package/api/typedefs.js +27 -42
  16. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  17. package/common/controls/StopFinderControlCommon.js +32 -32
  18. package/common/index.d.ts +2 -0
  19. package/common/index.js +1 -1
  20. package/common/styles/index.d.ts +4 -0
  21. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  22. package/common/styles/realtimeDefaultStyle.js +6 -11
  23. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  24. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.js +5 -10
  26. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  27. package/common/styles/realtimeSimpleStyle.js +0 -1
  28. package/common/typedefs.d.ts +102 -0
  29. package/common/typedefs.js +6 -31
  30. package/common/utils/RealtimeEngine.d.ts +214 -0
  31. package/common/utils/RealtimeEngine.js +554 -0
  32. package/common/utils/compareDepartures.d.ts +10 -0
  33. package/common/utils/compareDepartures.js +2 -2
  34. package/common/utils/constants.d.ts +5 -0
  35. package/common/utils/createCanvas.d.ts +10 -0
  36. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  37. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  38. package/common/utils/createRealtimeFilters.d.ts +12 -0
  39. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  40. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  41. package/common/utils/getLayersAsFlatArray.d.ts +2 -0
  42. package/common/utils/getLayersAsFlatArray.js +0 -1
  43. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  44. package/common/utils/getMapGlCopyrights.js +3 -3
  45. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  46. package/common/utils/getRealtimeModeSuffix.js +1 -0
  47. package/common/utils/getUrlWithParams.d.ts +8 -0
  48. package/common/utils/getVehiclePosition.d.ts +17 -0
  49. package/common/utils/getVehiclePosition.js +6 -3
  50. package/common/utils/index.d.ts +16 -0
  51. package/common/utils/realtimeConfig.d.ts +64 -0
  52. package/common/utils/realtimeConfig.js +0 -1
  53. package/common/utils/removeDuplicate.d.ts +9 -0
  54. package/common/utils/renderTrajectories.d.ts +17 -0
  55. package/common/utils/renderTrajectories.js +7 -6
  56. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  57. package/common/utils/sortAndFilterDepartures.js +2 -1
  58. package/common/utils/sortByDelay.d.ts +3 -0
  59. package/common/utils/sortByDelay.js +5 -1
  60. package/common/utils/timeUtils.d.ts +23 -0
  61. package/common/utils/toMercatorExtent.d.ts +5 -0
  62. package/iife.d.ts +2 -0
  63. package/index.d.ts +9 -0
  64. package/maplibre/controls/CopyrightControl.d.ts +38 -0
  65. package/maplibre/controls/CopyrightControl.js +11 -8
  66. package/maplibre/controls/index.d.ts +1 -0
  67. package/maplibre/index.d.ts +5 -0
  68. package/maplibre/layers/Layer.d.ts +29 -0
  69. package/maplibre/layers/Layer.js +2 -3
  70. package/maplibre/layers/RealtimeLayer.d.ts +124 -0
  71. package/maplibre/layers/RealtimeLayer.js +154 -118
  72. package/maplibre/layers/index.d.ts +2 -0
  73. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  74. package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
  75. package/maplibre/utils/getSourceCoordinates.js +6 -5
  76. package/maplibre/utils/index.d.ts +2 -0
  77. package/mbt.js +14585 -14557
  78. package/mbt.js.map +4 -4
  79. package/mbt.min.js +75 -75
  80. package/mbt.min.js.map +4 -4
  81. package/ol/controls/CopyrightControl.d.ts +39 -0
  82. package/ol/controls/CopyrightControl.js +13 -5
  83. package/ol/controls/RoutingControl.d.ts +213 -0
  84. package/ol/controls/RoutingControl.js +250 -264
  85. package/ol/controls/StopFinderControl.d.ts +56 -0
  86. package/ol/controls/StopFinderControl.js +24 -5
  87. package/ol/controls/index.d.ts +3 -0
  88. package/ol/index.d.ts +6 -0
  89. package/ol/layers/Layer.d.ts +26 -0
  90. package/ol/layers/Layer.js +39 -0
  91. package/ol/layers/MaplibreLayer.d.ts +91 -0
  92. package/ol/layers/MaplibreLayer.js +154 -31
  93. package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
  94. package/ol/layers/MaplibreStyleLayer.js +281 -210
  95. package/ol/layers/RealtimeLayer.d.ts +150 -0
  96. package/ol/layers/RealtimeLayer.js +210 -206
  97. package/ol/layers/VectorLayer.d.ts +17 -0
  98. package/ol/layers/VectorLayer.js +33 -0
  99. package/ol/layers/index.d.ts +5 -0
  100. package/ol/layers/index.js +3 -0
  101. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  102. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  103. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  104. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  105. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  106. package/ol/renderers/RealtimeLayerRenderer.js +50 -70
  107. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  108. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  109. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  110. package/ol/styles/fullTrajectoryStyle.js +5 -7
  111. package/ol/styles/index.d.ts +3 -0
  112. package/ol/styles/routingStyle.d.ts +3 -0
  113. package/ol/styles/routingStyle.js +13 -10
  114. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  115. package/ol/utils/defineDeprecatedProperties.js +180 -0
  116. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  117. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  118. package/ol/utils/index.d.ts +1 -0
  119. package/package.json +44 -44
  120. package/setupTests.d.ts +1 -0
  121. package/setupTests.js +17 -4
  122. package/types/common.d.ts +53 -69
  123. package/types/index.d.ts +1 -1
  124. package/types/realtime.d.ts +98 -95
  125. package/types/routing.d.ts +60 -60
  126. package/types/stops.d.ts +62 -62
  127. package/common/mixins/RealtimeLayerMixin.js +0 -743
  128. package/ol/layers/MapGlLayer.js +0 -142
  129. package/ol/mixins/MobilityLayerMixin.js +0 -9
  130. package/ol/mixins/PropertiesLayerMixin.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
  *
@@ -96,7 +71,6 @@ class WebSocketAPI {
96
71
  this.websocket.close();
97
72
  }
98
73
  }
99
- /** @private */
100
74
  this.websocket = new WebSocket(url);
101
75
  if (!this.open) {
102
76
  this.websocket.addEventListener('open', () => {
@@ -109,65 +83,94 @@ class WebSocketAPI {
109
83
  this.subscribePreviousSubscriptions();
110
84
  }
111
85
  }
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
- }
86
+ defineProperties() {
87
+ Object.defineProperties(this, {
88
+ closed: {
89
+ get: () => !!(!this.websocket ||
90
+ this.websocket.readyState === this.websocket.CLOSED),
91
+ },
92
+ closing: {
93
+ get: () => !!(this.websocket &&
94
+ this.websocket.readyState === this.websocket.CLOSING),
95
+ },
96
+ connecting: {
97
+ get: () => !!(this.websocket &&
98
+ this.websocket.readyState === this.websocket.CONNECTING),
99
+ },
100
+ /**
101
+ * Array of message to send on open.
102
+ * @type {Array<string>}
103
+ * @private
104
+ */
105
+ messagesOnOpen: {
106
+ value: [],
107
+ writable: true,
108
+ },
109
+ open: {
110
+ get: () => !!(this.websocket && this.websocket.readyState === this.websocket.OPEN),
111
+ },
112
+ /**
113
+ * List of channels subscribed.
114
+ * @type {WebSocketSubscribed}
115
+ * @private
116
+ */
117
+ subscribed: {
118
+ value: {},
119
+ writable: true,
120
+ },
121
+ /**
122
+ * Array of subscriptions.
123
+ * @type {Array<WebSocketSubscription>}
124
+ * @private
125
+ */
126
+ subscriptions: {
127
+ value: [],
128
+ writable: true,
129
+ },
130
+ });
123
131
  }
124
132
  /**
125
- * Sends a message to the websocket.
133
+ * Sends a get request to the websocket.
134
+ * The callback is called only once, when the response is received or when the call returns an error.
126
135
  *
127
- * @param {message} message Message to send.
136
+ * @param {Object} params Parameters for the websocket get request
137
+ * @param {function} cb callback on message event
138
+ * @param {function} errorCb Callback on error and close event
128
139
  * @private
129
140
  */
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);
141
+ get(params, cb, errorCb) {
142
+ const requestString = WebSocketAPI.getRequestString('GET', params);
143
+ this.send(requestString);
144
+ // We wrap the callbacks to make sure they are called only once.
145
+ const once = (callback) =>
146
+ // @ts-expect-error : Spread error
147
+ (...args) => {
148
+ // @ts-expect-error : Spread error
149
+ callback(...args);
150
+ const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
151
+ const { onErrorCb, onMessageCb } = this.requests[index];
152
+ this.removeEvents(onMessageCb, onErrorCb);
153
+ this.requests.splice(index, 1);
137
154
  };
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();
155
+ const { onErrorCb, onMessageCb } = this.listen(params, once(cb), errorCb && once(errorCb));
156
+ // Store requests and callbacks to be able to remove them.
157
+ if (!this.requests) {
158
+ this.requests = [];
153
159
  }
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
- }
160
+ const index = this.requests.findIndex((request) => requestString === request.requestString && cb === request.cb);
161
+ const newReq = {
162
+ cb,
163
+ errorCb,
164
+ onErrorCb,
165
+ onMessageCb,
166
+ params,
167
+ requestString,
168
+ };
169
+ if (index > -1) {
170
+ this.requests[index] = newReq;
162
171
  }
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
- }
172
+ else {
173
+ this.requests.push(newReq);
171
174
  }
172
175
  }
173
176
  /**
@@ -213,64 +216,46 @@ class WebSocketAPI {
213
216
  });
214
217
  };
215
218
  this.addEvents(onMessage, errorCb);
216
- return { onMessageCb: onMessage, onErrorCb: errorCb };
219
+ return { onErrorCb: errorCb, onMessageCb: onMessage };
217
220
  }
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
- });
221
+ removeEvents(onMessage, onError) {
222
+ if (this.websocket) {
223
+ this.websocket.removeEventListener('message', onMessage);
224
+ if (onError) {
225
+ this.websocket.removeEventListener('error', onError);
226
+ this.websocket.removeEventListener('close', onError);
227
+ }
228
+ }
231
229
  }
232
230
  /**
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.
231
+ * Sends a message to the websocket.
235
232
  *
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
233
+ * @param {message} message Message to send.
239
234
  * @private
240
235
  */
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 = [];
236
+ send(message) {
237
+ if (!this.websocket || this.closed || this.closing) {
238
+ return;
259
239
  }
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,
240
+ const send = () => {
241
+ var _a;
242
+ (_a = this.websocket) === null || _a === void 0 ? void 0 : _a.send(message);
268
243
  };
269
- if (index > -1) {
270
- this.requests[index] = newReq;
244
+ if (!this.open) {
245
+ // This 'if' avoid sending 2 identical BBOX message on open,
246
+ if (!this.messagesOnOpen.includes(message)) {
247
+ this.messagesOnOpen.push(message);
248
+ this.websocket.addEventListener('open', () => {
249
+ this.messagesOnOpen = [];
250
+ send();
251
+ });
252
+ this.websocket.addEventListener('close', () => {
253
+ this.messagesOnOpen = [];
254
+ });
255
+ }
271
256
  }
272
- else {
273
- this.requests.push(newReq);
257
+ else if (!this.messagesOnOpen.includes(message)) {
258
+ send();
274
259
  }
275
260
  }
276
261
  /**
@@ -283,10 +268,10 @@ class WebSocketAPI {
283
268
  * @private
284
269
  */
285
270
  subscribe(params, cb, errorCb, quiet = false) {
286
- const { onMessageCb, onErrorCb } = this.listen(params, cb, errorCb);
271
+ const { onErrorCb, onMessageCb } = this.listen(params, cb, errorCb);
287
272
  const reqStr = WebSocketAPI.getRequestString('', params);
288
273
  const index = this.subscriptions.findIndex((subcr) => params.channel === subcr.params.channel && cb === subcr.cb);
289
- const newSubscr = { params, cb, errorCb, onMessageCb, onErrorCb, quiet };
274
+ const newSubscr = { cb, errorCb, onErrorCb, onMessageCb, params, quiet };
290
275
  if (index > -1) {
291
276
  this.subscriptions[index] = newSubscr;
292
277
  }
@@ -301,6 +286,35 @@ class WebSocketAPI {
301
286
  this.subscribed[reqStr] = true;
302
287
  }
303
288
  }
289
+ /**
290
+ * After an auto reconnection we need to re-subscribe to the channels.
291
+ */
292
+ subscribePreviousSubscriptions() {
293
+ // Before to subscribe previous subscriptions we make sure they
294
+ // are all defined as unsubscribed, because this code is asynchrone
295
+ // and a subscription could have been added in between.
296
+ Object.keys(this.subscribed).forEach((key) => {
297
+ this.subscribed[key] = false;
298
+ });
299
+ // Subscribe all previous subscriptions.
300
+ [...this.subscriptions].forEach((s) => {
301
+ this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
302
+ });
303
+ }
304
+ /**
305
+ * Unlisten websocket messages.
306
+ *
307
+ * @param {Object} params Parameters for the websocket get request.
308
+ * @param {function} cb Callback used when listen.
309
+ * @private
310
+ */
311
+ unlisten(params, cb) {
312
+ [...(this.subscriptions || []), ...(this.requests || [])]
313
+ .filter((s) => s.params.channel === params.channel && (!cb || s.cb === cb))
314
+ .forEach(({ onErrorCb, onMessageCb }) => {
315
+ this.removeEvents(onMessageCb, onErrorCb);
316
+ });
317
+ }
304
318
  /**
305
319
  * Unsubscribe from a channel.
306
320
  * @param {string} source source to unsubscribe from
@@ -309,7 +323,7 @@ class WebSocketAPI {
309
323
  */
310
324
  unsubscribe(source, cb) {
311
325
  const toRemove = this.subscriptions.filter((s) => s.params.channel === source && (!cb || s.cb === cb));
312
- toRemove.forEach(({ onMessageCb, onErrorCb }) => {
326
+ toRemove.forEach(({ onErrorCb, onMessageCb }) => {
313
327
  this.removeEvents(onMessageCb, onErrorCb);
314
328
  });
315
329
  this.subscriptions = this.subscriptions.filter((s) => s.params.channel !== source || (cb && s.cb !== cb));
@@ -323,20 +337,5 @@ class WebSocketAPI {
323
337
  this.subscribed[source] = false;
324
338
  }
325
339
  }
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
340
  }
342
341
  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/stops/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;