mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37

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 (195) hide show
  1. package/README.md +14 -8
  2. package/api/RealtimeAPI.d.ts +6 -6
  3. package/api/RealtimeAPI.d.ts.map +1 -1
  4. package/api/RealtimeAPI.js +170 -197
  5. package/api/RealtimeAPI.test.d.ts +2 -0
  6. package/api/RealtimeAPI.test.d.ts.map +1 -0
  7. package/api/RealtimeAPI.test.js +67 -0
  8. package/api/RoutingAPI.d.ts +6 -2
  9. package/api/RoutingAPI.d.ts.map +1 -1
  10. package/api/RoutingAPI.js +8 -38
  11. package/api/RoutingAPI.test.d.ts +2 -0
  12. package/api/RoutingAPI.test.d.ts.map +1 -0
  13. package/api/RoutingAPI.test.js +29 -0
  14. package/api/StopsAPI.d.ts +1 -1
  15. package/api/StopsAPI.d.ts.map +1 -1
  16. package/api/StopsAPI.js +8 -40
  17. package/api/StopsAPI.test.d.ts +2 -0
  18. package/api/StopsAPI.test.d.ts.map +1 -0
  19. package/api/StopsAPI.test.js +26 -0
  20. package/api/index.d.ts +3 -4
  21. package/api/index.d.ts.map +1 -1
  22. package/api/index.js +3 -10
  23. package/api/typedefs.js +1 -0
  24. package/common/api/HttpAPI.d.ts +2 -2
  25. package/common/api/HttpAPI.d.ts.map +1 -1
  26. package/common/api/HttpAPI.js +21 -48
  27. package/common/api/HttpAPI.test.d.ts +2 -0
  28. package/common/api/HttpAPI.test.d.ts.map +1 -0
  29. package/common/api/HttpAPI.test.js +54 -0
  30. package/common/api/WebSocketAPI.d.ts +8 -4
  31. package/common/api/WebSocketAPI.d.ts.map +1 -1
  32. package/common/api/WebSocketAPI.js +125 -129
  33. package/common/api/WebSocketAPI.test.d.ts +2 -0
  34. package/common/api/WebSocketAPI.test.d.ts.map +1 -0
  35. package/common/api/WebSocketAPI.test.js +380 -0
  36. package/common/controls/Control.d.ts +5 -5
  37. package/common/controls/Control.d.ts.map +1 -1
  38. package/common/controls/Control.js +44 -77
  39. package/common/controls/Control.test.d.ts +2 -0
  40. package/common/controls/Control.test.d.ts.map +1 -0
  41. package/common/controls/Control.test.js +89 -0
  42. package/common/index.js +2 -18
  43. package/common/layers/Layer.d.ts +11 -11
  44. package/common/layers/Layer.d.ts.map +1 -1
  45. package/common/layers/Layer.js +70 -104
  46. package/common/layers/Layer.test.d.ts +2 -0
  47. package/common/layers/Layer.test.d.ts.map +1 -0
  48. package/common/layers/Layer.test.js +137 -0
  49. package/common/mixins/CopyrightMixin.js +23 -52
  50. package/common/mixins/MapboxLayerMixin.js +162 -204
  51. package/common/mixins/RealtimeLayerMixin.js +580 -635
  52. package/common/mixins/StopFinderMixin.d.ts +3 -3
  53. package/common/mixins/StopFinderMixin.d.ts.map +1 -1
  54. package/common/mixins/StopFinderMixin.js +115 -157
  55. package/common/mixins/UserInteractionsLayerMixin.js +142 -175
  56. package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
  57. package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
  58. package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
  59. package/common/styles/index.js +4 -24
  60. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
  61. package/common/styles/realtimeDefaultStyle.js +67 -78
  62. package/common/styles/realtimeDelayStyle.js +4 -17
  63. package/common/styles/realtimeSimpleStyle.js +5 -7
  64. package/common/typedefs.js +1 -0
  65. package/common/utils/cleanStopTime.js +3 -5
  66. package/common/utils/compareDepartures.d.ts +1 -1
  67. package/common/utils/compareDepartures.d.ts.map +1 -1
  68. package/common/utils/compareDepartures.js +8 -11
  69. package/common/utils/createCanvas.js +3 -5
  70. package/common/utils/createTrackerFilters.d.ts +1 -1
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -1
  72. package/common/utils/createTrackerFilters.js +22 -32
  73. package/common/utils/createTrackerFilters.test.d.ts +2 -0
  74. package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
  75. package/common/utils/createTrackerFilters.test.js +79 -0
  76. package/common/utils/getLayersAsFlatArray.js +6 -8
  77. package/common/utils/getMapboxMapCopyrights.js +9 -11
  78. package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
  79. package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
  80. package/common/utils/getMapboxMapCopyrights.test.js +40 -0
  81. package/common/utils/getMapboxRender.js +12 -15
  82. package/common/utils/getMaplibreRender.js +10 -13
  83. package/common/utils/getRealtimeModeSuffix.js +2 -6
  84. package/common/utils/getUrlWithParams.js +5 -8
  85. package/common/utils/getVehiclePosition.js +20 -23
  86. package/common/utils/index.js +12 -37
  87. package/common/utils/removeDuplicate.d.ts +1 -1
  88. package/common/utils/removeDuplicate.d.ts.map +1 -1
  89. package/common/utils/removeDuplicate.js +6 -21
  90. package/common/utils/removeDuplicate.test.d.ts +2 -0
  91. package/common/utils/removeDuplicate.test.d.ts.map +1 -0
  92. package/common/utils/removeDuplicate.test.js +19 -0
  93. package/common/utils/renderTrajectories.js +31 -43
  94. package/common/utils/sortByDelay.js +4 -6
  95. package/common/utils/timeUtils.js +14 -24
  96. package/common/utils/timeUtils.test.d.ts +2 -0
  97. package/common/utils/timeUtils.test.d.ts.map +1 -0
  98. package/common/utils/timeUtils.test.js +10 -0
  99. package/common/utils/trackerConfig.js +27 -39
  100. package/common/utils/trackerConfig.test.d.ts +2 -0
  101. package/common/utils/trackerConfig.test.d.ts.map +1 -0
  102. package/common/utils/trackerConfig.test.js +23 -0
  103. package/iife.js +3 -5
  104. package/index.d.ts +4 -0
  105. package/index.js +9 -10
  106. package/mapbox/controls/CopyrightControl.d.ts +0 -1
  107. package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
  108. package/mapbox/controls/CopyrightControl.js +18 -38
  109. package/mapbox/controls/index.js +1 -5
  110. package/mapbox/index.js +4 -20
  111. package/mapbox/layers/Layer.d.ts +1 -1
  112. package/mapbox/layers/Layer.d.ts.map +1 -1
  113. package/mapbox/layers/Layer.js +29 -71
  114. package/mapbox/layers/Layer.test.d.ts +2 -0
  115. package/mapbox/layers/Layer.test.d.ts.map +1 -0
  116. package/mapbox/layers/Layer.test.js +204 -0
  117. package/mapbox/layers/RealtimeLayer.d.ts +4 -4
  118. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
  119. package/mapbox/layers/RealtimeLayer.js +83 -125
  120. package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
  121. package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
  122. package/mapbox/layers/RealtimeLayer.test.js +10 -0
  123. package/mapbox/layers/index.js +2 -7
  124. package/mapbox/utils.js +19 -33
  125. package/mbt.js +59 -37
  126. package/mbt.js.map +2 -2
  127. package/mbt.min.js +10 -10
  128. package/mbt.min.js.map +2 -2
  129. package/ol/controls/CopyrightControl.js +26 -47
  130. package/ol/controls/CopyrightControl.test.d.ts +2 -0
  131. package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
  132. package/ol/controls/CopyrightControl.test.js +177 -0
  133. package/ol/controls/RoutingControl.d.ts +6 -5
  134. package/ol/controls/RoutingControl.d.ts.map +1 -1
  135. package/ol/controls/RoutingControl.js +209 -270
  136. package/ol/controls/RoutingControl.test.d.ts +2 -0
  137. package/ol/controls/RoutingControl.test.d.ts.map +1 -0
  138. package/ol/controls/RoutingControl.test.js +150 -0
  139. package/ol/controls/StopFinderControl.js +9 -32
  140. package/ol/controls/StopFinderControl.test.d.ts +2 -0
  141. package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
  142. package/ol/controls/StopFinderControl.test.js +49 -0
  143. package/ol/controls/index.js +3 -9
  144. package/ol/index.js +5 -21
  145. package/ol/layers/Layer.d.ts +1 -1
  146. package/ol/layers/Layer.d.ts.map +1 -1
  147. package/ol/layers/Layer.js +40 -72
  148. package/ol/layers/Layer.test.d.ts +2 -0
  149. package/ol/layers/Layer.test.d.ts.map +1 -0
  150. package/ol/layers/Layer.test.js +196 -0
  151. package/ol/layers/MapboxLayer.d.ts +7 -7
  152. package/ol/layers/MapboxLayer.d.ts.map +1 -1
  153. package/ol/layers/MapboxLayer.js +30 -66
  154. package/ol/layers/MapboxLayer.test.d.ts +2 -0
  155. package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
  156. package/ol/layers/MapboxLayer.test.js +164 -0
  157. package/ol/layers/MapboxStyleLayer.d.ts +3 -3
  158. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
  159. package/ol/layers/MapboxStyleLayer.js +92 -135
  160. package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
  161. package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
  162. package/ol/layers/MapboxStyleLayer.test.js +232 -0
  163. package/ol/layers/MaplibreLayer.d.ts +1 -1
  164. package/ol/layers/MaplibreLayer.d.ts.map +1 -1
  165. package/ol/layers/MaplibreLayer.js +14 -48
  166. package/ol/layers/RealtimeLayer.d.ts +2 -2
  167. package/ol/layers/RealtimeLayer.d.ts.map +1 -1
  168. package/ol/layers/RealtimeLayer.js +111 -147
  169. package/ol/layers/RealtimeLayer.test.d.ts +2 -0
  170. package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
  171. package/ol/layers/RealtimeLayer.test.js +71 -0
  172. package/ol/layers/RoutingLayer.d.ts +2 -2
  173. package/ol/layers/RoutingLayer.d.ts.map +1 -1
  174. package/ol/layers/RoutingLayer.js +29 -61
  175. package/ol/layers/RoutingLayer.test.d.ts +2 -0
  176. package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
  177. package/ol/layers/RoutingLayer.test.js +39 -0
  178. package/ol/layers/VectorLayer.d.ts +1 -1
  179. package/ol/layers/VectorLayer.d.ts.map +1 -1
  180. package/ol/layers/VectorLayer.js +14 -48
  181. package/ol/layers/VectorLayer.test.d.ts +2 -0
  182. package/ol/layers/VectorLayer.test.d.ts.map +1 -0
  183. package/ol/layers/VectorLayer.test.js +87 -0
  184. package/ol/layers/WMSLayer.d.ts +1 -1
  185. package/ol/layers/WMSLayer.d.ts.map +1 -1
  186. package/ol/layers/WMSLayer.js +34 -68
  187. package/ol/layers/WMSLayer.test.d.ts +2 -0
  188. package/ol/layers/WMSLayer.test.d.ts.map +1 -0
  189. package/ol/layers/WMSLayer.test.js +66 -0
  190. package/ol/layers/index.js +8 -19
  191. package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
  192. package/ol/styles/fullTrajectoryStyle.js +16 -18
  193. package/ol/styles/index.js +2 -7
  194. package/package.json +5 -2
  195. package/setupTests.js +12 -14
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RealtimeModes = void 0;
4
- var WebSocketAPI_1 = require("../common/api/WebSocketAPI");
5
- var cleanStopTime_1 = require("../common/utils/cleanStopTime");
6
- var getRealtimeModeSuffix_1 = require("../common/utils/getRealtimeModeSuffix");
7
- var compareDepartures_1 = require("../common/utils/compareDepartures");
1
+ import WebSocketAPI from '../common/api/WebSocketAPI';
2
+ import cleanStopTime from '../common/utils/cleanStopTime';
3
+ import getModeSuffix from '../common/utils/getRealtimeModeSuffix';
4
+ import compareDepartures from '../common/utils/compareDepartures';
8
5
  /**
9
6
  * Enum for Realtime modes.
10
7
  * @readonly
@@ -14,7 +11,7 @@ var compareDepartures_1 = require("../common/utils/compareDepartures");
14
11
  * @property {string} TOPOGRAPHIC "topographic"
15
12
  * @enum {RealtimeMode}
16
13
  */
17
- exports.RealtimeModes = {
14
+ export const RealtimeModes = {
18
15
  RAW: 'raw',
19
16
  TOPOGRAPHIC: 'topographic',
20
17
  SCHEMATIC: 'schematic',
@@ -35,7 +32,7 @@ exports.RealtimeModes = {
35
32
  *
36
33
  * const api = new RealtimeAPI("yourUrl");
37
34
  */
38
- var RealtimeAPI = /** @class */ (function () {
35
+ class RealtimeAPI {
39
36
  /**
40
37
  * Constructor
41
38
  *
@@ -46,8 +43,7 @@ var RealtimeAPI = /** @class */ (function () {
46
43
  * @param {string} [options.projection] The epsg code of the projection for features. Default to EPSG:3857.
47
44
  * @param {number[4]} [options.bbox=[minX, minY, maxX, maxY, zoom, tenant] The bounding box to receive data from.
48
45
  */
49
- function RealtimeAPI(options) {
50
- if (options === void 0) { options = {}; }
46
+ constructor(options = {}) {
51
47
  this.defineProperties(options);
52
48
  /** @ignore */
53
49
  this.subscribedStationUic = null;
@@ -62,55 +58,54 @@ var RealtimeAPI = /** @class */ (function () {
62
58
  /** @ignore */
63
59
  this.onOpen = this.onOpen.bind(this);
64
60
  }
65
- RealtimeAPI.prototype.defineProperties = function (options) {
66
- var _this = this;
67
- var opt = options;
61
+ defineProperties(options) {
62
+ let opt = options;
68
63
  if (typeof options === 'string') {
69
64
  opt = { url: options };
70
65
  }
71
- var apiKey = opt.apiKey;
72
- var url = opt.url, projection = opt.projection, bbox = opt.bbox, _a = opt.buffer, buffer = _a === void 0 ? [100, 100] : _a;
73
- var wsApi = new WebSocketAPI_1.default();
66
+ const { apiKey } = opt;
67
+ let { url, projection, bbox, buffer = [100, 100] } = opt;
68
+ const wsApi = new WebSocketAPI();
74
69
  if (apiKey) {
75
- url = "".concat(url || 'wss://api.geops.io/tracker-ws/v1/', "?key=").concat(apiKey);
70
+ url = `${url || 'wss://api.geops.io/tracker-ws/v1/'}?key=${apiKey}`;
76
71
  }
77
72
  Object.defineProperties(this, {
78
73
  url: {
79
- get: function () { return url; },
80
- set: function (newUrl) {
74
+ get: () => url,
75
+ set: (newUrl) => {
81
76
  url = newUrl;
82
- _this.open();
77
+ this.open();
83
78
  },
84
79
  },
85
80
  projection: {
86
- get: function () { return projection; },
87
- set: function (newProjection) {
81
+ get: () => projection,
82
+ set: (newProjection) => {
88
83
  if (newProjection !== projection) {
89
84
  projection = newProjection;
90
- if (_this.wsApi) {
91
- _this.wsApi.send("PROJECTION ".concat(projection));
85
+ if (this.wsApi) {
86
+ this.wsApi.send(`PROJECTION ${projection}`);
92
87
  }
93
88
  }
94
89
  },
95
90
  },
96
91
  bbox: {
97
- get: function () { return bbox; },
98
- set: function (newBbox) {
92
+ get: () => bbox,
93
+ set: (newBbox) => {
99
94
  if (JSON.stringify(newBbox) !== JSON.stringify(bbox)) {
100
95
  bbox = newBbox;
101
- if (_this.wsApi) {
102
- _this.wsApi.send("BBOX ".concat(bbox.join(' ')));
96
+ if (this.wsApi) {
97
+ this.wsApi.send(`BBOX ${bbox.join(' ')}`);
103
98
  }
104
99
  }
105
100
  },
106
101
  },
107
102
  buffer: {
108
- get: function () { return buffer; },
109
- set: function (newBuffer) {
103
+ get: () => buffer,
104
+ set: (newBuffer) => {
110
105
  if (JSON.stringify(newBuffer) !== JSON.stringify(buffer)) {
111
106
  buffer = newBuffer;
112
- if (_this.wsApi) {
113
- _this.wsApi.send("BUFFER ".concat(buffer.join(' ')));
107
+ if (this.wsApi) {
108
+ this.wsApi.send(`BUFFER ${buffer.join(' ')}`);
114
109
  }
115
110
  }
116
111
  },
@@ -143,44 +138,42 @@ var RealtimeAPI = /** @class */ (function () {
143
138
  writable: true,
144
139
  },
145
140
  });
146
- };
147
- RealtimeAPI.prototype.open = function () {
148
- var _this = this;
141
+ }
142
+ open() {
149
143
  this.close();
150
144
  // Register BBOX and PROJECTION messages must be send before previous subscriptions.
151
145
  this.wsApi.connect(this.url, this.onOpen);
152
146
  // Register reconnection on close.
153
- this.wsApi.websocket.onclose = function () {
154
- _this.onClose();
147
+ this.wsApi.websocket.onclose = () => {
148
+ this.onClose();
155
149
  };
156
- };
150
+ }
157
151
  /**
158
152
  * Close the websocket connection without reconnection.
159
153
  */
160
- RealtimeAPI.prototype.close = function () {
154
+ close() {
161
155
  this.wsApi.close();
162
- };
156
+ }
163
157
  /**
164
158
  * Unsubscribe trajectory and deleted_vehicles channels. To resubscribe you have to set a new BBOX.
165
159
  */
166
160
  // eslint-disable-next-line class-methods-use-this
167
- RealtimeAPI.prototype.reset = function () {
161
+ reset() {
168
162
  this.wsApi.send('RESET');
169
- };
163
+ }
170
164
  /**
171
165
  * Callback when the websocket is opened and ready.
172
166
  * It applies the bbox and the projection.
173
167
  */
174
- RealtimeAPI.prototype.onOpen = function () {
175
- var _this = this;
168
+ onOpen() {
176
169
  if (this.projection) {
177
- this.wsApi.send("PROJECTION ".concat(this.projection));
170
+ this.wsApi.send(`PROJECTION ${this.projection}`);
178
171
  }
179
172
  if (this.bbox) {
180
- this.wsApi.send("BBOX ".concat(this.bbox.join(' ')));
173
+ this.wsApi.send(`BBOX ${this.bbox.join(' ')}`);
181
174
  }
182
175
  if (this.buffer) {
183
- this.wsApi.send("BUFFER ".concat(this.buffer.join(' ')));
176
+ this.wsApi.send(`BUFFER ${this.buffer.join(' ')}`);
184
177
  }
185
178
  /**
186
179
  * Keep websocket alive
@@ -188,24 +181,23 @@ var RealtimeAPI = /** @class */ (function () {
188
181
  if (this.pingIntervalMs) {
189
182
  window.clearInterval(this.pingInterval);
190
183
  /** @ignore */
191
- this.pingInterval = setInterval(function () {
192
- _this.wsApi.send('PING');
184
+ this.pingInterval = setInterval(() => {
185
+ this.wsApi.send('PING');
193
186
  }, this.pingIntervalMs);
194
187
  }
195
- };
188
+ }
196
189
  /**
197
190
  * Callback when the websocket is closed by the server.
198
191
  * It auto reconnects after a timeout.
199
192
  */
200
- RealtimeAPI.prototype.onClose = function () {
201
- var _this = this;
193
+ onClose() {
202
194
  window.clearTimeout(this.pingInterval);
203
195
  window.clearTimeout(this.reconnectTimeout);
204
196
  if (this.reconnectTimeoutMs) {
205
197
  /** @ignore */
206
- this.reconnectTimeout = window.setTimeout(function () { return _this.open(); }, this.reconnectTimeoutMs);
198
+ this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
207
199
  }
208
- };
200
+ }
209
201
  /**
210
202
  * Subscribe to a channel.
211
203
  *
@@ -215,10 +207,9 @@ var RealtimeAPI = /** @class */ (function () {
215
207
  * @param {boolean} [quiet=false] If true avoid to store the subscription in the subscriptions list.
216
208
  * @private
217
209
  */
218
- RealtimeAPI.prototype.subscribe = function (channel, onSuccess, onError, quiet) {
219
- if (quiet === void 0) { quiet = false; }
220
- this.wsApi.subscribe({ channel: channel }, onSuccess, onError, quiet);
221
- };
210
+ subscribe(channel, onSuccess, onError, quiet = false) {
211
+ this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
212
+ }
222
213
  /**
223
214
  * Unsubscribe both modes of a channel.
224
215
  *
@@ -227,10 +218,10 @@ var RealtimeAPI = /** @class */ (function () {
227
218
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
228
219
  * @private
229
220
  */
230
- RealtimeAPI.prototype.unsubscribe = function (channel, suffix, cb) {
231
- this.wsApi.unsubscribe("".concat(channel).concat((0, getRealtimeModeSuffix_1.default)(exports.RealtimeModes.SCHEMATIC, exports.RealtimeModes)).concat(suffix), cb);
232
- this.wsApi.unsubscribe("".concat(channel).concat((0, getRealtimeModeSuffix_1.default)(exports.RealtimeModes.TOPOGRAPHIC, exports.RealtimeModes)).concat(suffix || ''), cb);
233
- };
221
+ unsubscribe(channel, suffix, cb) {
222
+ this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.SCHEMATIC, RealtimeModes)}${suffix}`, cb);
223
+ this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.TOPOGRAPHIC, RealtimeModes)}${suffix || ''}`, cb);
224
+ }
234
225
  /**
235
226
  * Filter departures and return an array.
236
227
  *
@@ -239,22 +230,21 @@ var RealtimeAPI = /** @class */ (function () {
239
230
  * @return {Array<departure>} Return departures array.
240
231
  * @private
241
232
  */
242
- RealtimeAPI.prototype.filterDepartures = function (depObject, sortByMinArrivalTime) {
243
- if (sortByMinArrivalTime === void 0) { sortByMinArrivalTime = false; }
244
- var departures = Object.keys(depObject).map(function (k) { return depObject[k]; });
245
- departures.sort(function (a, b) { return (0, compareDepartures_1.default)(a, b, sortByMinArrivalTime); });
246
- var future = new Date();
233
+ filterDepartures(depObject, sortByMinArrivalTime = false) {
234
+ const departures = Object.keys(depObject).map((k) => depObject[k]);
235
+ departures.sort((a, b) => compareDepartures(a, b, sortByMinArrivalTime));
236
+ let future = new Date();
247
237
  future.setMinutes(future.getMinutes() + this.maxDepartureAge);
248
238
  future = future.getTime();
249
- var past = new Date();
239
+ let past = new Date();
250
240
  past.setMinutes(past.getMinutes() - this.maxDepartureAge);
251
241
  past = past.getTime();
252
- var departureArray = [];
253
- var platformsBoarding = [];
254
- var previousDeparture = null;
255
- for (var i = departures.length - 1; i >= 0; i -= 1) {
256
- var d = departures[i];
257
- var t = new Date(d.time).getTime();
242
+ const departureArray = [];
243
+ const platformsBoarding = [];
244
+ let previousDeparture = null;
245
+ for (let i = departures.length - 1; i >= 0; i -= 1) {
246
+ const d = departures[i];
247
+ const t = new Date(d.time).getTime();
258
248
  // Only show departures within the next 30 minutes
259
249
  if (t > past && t < future) {
260
250
  // If 2 trains are boarding at the same platform,
@@ -284,7 +274,7 @@ var RealtimeAPI = /** @class */ (function () {
284
274
  }
285
275
  }
286
276
  return departureArray;
287
- };
277
+ }
288
278
  /**
289
279
  * Subscribe to departures channel of a given station.
290
280
  *
@@ -292,56 +282,55 @@ var RealtimeAPI = /** @class */ (function () {
292
282
  * @param {Boolean} sortByMinArrivalTime Sort by minimum arrival time
293
283
  * @param {function(departures:Departure[])} onMessage Function called on each message of the channel.
294
284
  */
295
- RealtimeAPI.prototype.subscribeDepartures = function (stationId, sortByMinArrivalTime, onMessage) {
296
- var _this = this;
285
+ subscribeDepartures(stationId, sortByMinArrivalTime, onMessage) {
297
286
  window.clearTimeout(this.departureUpdateTimeout);
298
287
  this.unsubscribeDepartures();
299
288
  this.subscribedStationUic = stationId;
300
- var channel = stationId ? "timetable_".concat(stationId) : null;
301
- var departureObject = {};
302
- this.subscribe(channel, function (data) {
289
+ const channel = stationId ? `timetable_${stationId}` : null;
290
+ const departureObject = {};
291
+ this.subscribe(channel, (data) => {
303
292
  if (data.source === channel) {
304
- var content = data.content || {};
305
- var tDiff = new Date(content.timestamp).getTime() - Date.now();
293
+ const content = data.content || {};
294
+ const tDiff = new Date(content.timestamp).getTime() - Date.now();
306
295
  content.timediff = tDiff;
307
296
  departureObject[content.call_id] = content;
308
- window.clearTimeout(_this.departureUpdateTimeout);
309
- _this.departureUpdateTimeout = window.setTimeout(function () {
310
- var departures = _this.filterDepartures(departureObject, sortByMinArrivalTime || false);
297
+ window.clearTimeout(this.departureUpdateTimeout);
298
+ this.departureUpdateTimeout = window.setTimeout(() => {
299
+ const departures = this.filterDepartures(departureObject, sortByMinArrivalTime || false);
311
300
  onMessage(departures);
312
301
  }, 100);
313
302
  }
314
- }, function () {
303
+ }, () => {
315
304
  onMessage([]);
316
305
  });
317
- };
306
+ }
318
307
  /**
319
308
  * Unsubscribe from current departures channel.
320
309
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
321
310
  */
322
- RealtimeAPI.prototype.unsubscribeDepartures = function (cb) {
311
+ unsubscribeDepartures(cb) {
323
312
  if (this.subscribedStationUic) {
324
- this.unsubscribe("timetable_".concat(this.subscribedStationUic), '', cb);
313
+ this.unsubscribe(`timetable_${this.subscribedStationUic}`, '', cb);
325
314
  this.subscribedStationUic = null;
326
315
  }
327
- };
316
+ }
328
317
  /**
329
318
  * Subscribe to the disruptions channel for tenant.
330
319
  *
331
320
  * @param {function} onMessage Function called on each message of the channel.
332
321
  */
333
- RealtimeAPI.prototype.subscribeDisruptions = function (onMessage) {
334
- this.subscribe("".concat(this.prefix, "newsticker"), function (data) {
322
+ subscribeDisruptions(onMessage) {
323
+ this.subscribe(`${this.prefix}newsticker`, (data) => {
335
324
  onMessage(data.content);
336
325
  });
337
- };
326
+ }
338
327
  /**
339
328
  * Unsubscribe disruptions.
340
329
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
341
330
  */
342
- RealtimeAPI.prototype.unsubscribeDisruptions = function (cb) {
343
- this.unsubscribe("".concat(this.prefix, "newsticker"), '', cb);
344
- };
331
+ unsubscribeDisruptions(cb) {
332
+ this.unsubscribe(`${this.prefix}newsticker`, '', cb);
333
+ }
345
334
  /**
346
335
  * Return a station with a given uic number and a mode.
347
336
  *
@@ -349,14 +338,13 @@ var RealtimeAPI = /** @class */ (function () {
349
338
  * @param {RealtimeMode} mode Realtime mode.
350
339
  * @return {Promise<Station>} A station.
351
340
  */
352
- RealtimeAPI.prototype.getStation = function (uic, mode) {
353
- var _this = this;
354
- var params = {
355
- channel: "station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)),
341
+ getStation(uic, mode) {
342
+ const params = {
343
+ channel: `station${getModeSuffix(mode, RealtimeModes)}`,
356
344
  args: uic,
357
345
  };
358
- return new Promise(function (resolve, reject) {
359
- _this.wsApi.get(params, function (data) {
346
+ return new Promise((resolve, reject) => {
347
+ this.wsApi.get(params, (data) => {
360
348
  if (data.content) {
361
349
  resolve(data.content);
362
350
  }
@@ -365,27 +353,26 @@ var RealtimeAPI = /** @class */ (function () {
365
353
  }
366
354
  });
367
355
  });
368
- };
356
+ }
369
357
  /**
370
358
  * Update the model's station list for a given mode and a bbox.
371
359
  *
372
360
  * @param {RealtimeMode} mode Realtime mode.
373
361
  * @return {Promise<Array<Station>>} An array of stations.
374
362
  */
375
- RealtimeAPI.prototype.getStations = function (mode) {
376
- var _this = this;
377
- var stations = [];
378
- var params = {
379
- channel: "station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)),
363
+ getStations(mode) {
364
+ const stations = [];
365
+ const params = {
366
+ channel: `station${getModeSuffix(mode, RealtimeModes)}`,
380
367
  };
381
368
  window.clearTimeout(this.stationUpdateTimeout);
382
- return new Promise(function (resolve, reject) {
383
- _this.wsApi.get(params, function (data) {
369
+ return new Promise((resolve, reject) => {
370
+ this.wsApi.get(params, (data) => {
384
371
  if (data.content) {
385
372
  stations.push(data.content);
386
- window.clearTimeout(_this.stationUpdateTimeout);
373
+ window.clearTimeout(this.stationUpdateTimeout);
387
374
  /** @ignore */
388
- _this.stationUpdateTimeout = window.setTimeout(function () {
375
+ this.stationUpdateTimeout = window.setTimeout(() => {
389
376
  resolve(stations);
390
377
  }, 50);
391
378
  }
@@ -394,7 +381,7 @@ var RealtimeAPI = /** @class */ (function () {
394
381
  }
395
382
  });
396
383
  });
397
- };
384
+ }
398
385
  /**
399
386
  * Subscribe to stations channel.
400
387
  * One message pro station.
@@ -402,50 +389,49 @@ var RealtimeAPI = /** @class */ (function () {
402
389
  * @param {RealtimeMode} mode Realtime mode.
403
390
  * @param {function(station: Station)} onMessage Function called on each message of the channel.
404
391
  */
405
- RealtimeAPI.prototype.subscribeStations = function (mode, onMessage) {
392
+ subscribeStations(mode, onMessage) {
406
393
  this.unsubscribeStations();
407
- this.subscribe("station".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), function (data) {
394
+ this.subscribe(`station${getModeSuffix(mode, RealtimeModes)}`, (data) => {
408
395
  if (data.content) {
409
396
  onMessage(data.content);
410
397
  }
411
398
  });
412
- };
399
+ }
413
400
  /**
414
401
  * Unsubscribe to stations channel.
415
402
  * @param {function} cb The listener callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribe.
416
403
  */
417
- RealtimeAPI.prototype.unsubscribeStations = function (cb) {
404
+ unsubscribeStations(cb) {
418
405
  window.clearTimeout(this.stationUpdateTimeout);
419
406
  this.unsubscribe('station', '', cb);
420
- };
407
+ }
421
408
  /**
422
409
  * Subscribe to extra_geoms channel.
423
410
  *
424
411
  * @param {function(extraGeoms: GeosJSONFeature[])} onMessage Function called on each message of the channel.
425
412
  */
426
- RealtimeAPI.prototype.subscribeExtraGeoms = function (onMessage) {
427
- var _this = this;
428
- this.subscribe('extra_geoms', function (data) {
429
- var extraGeom = data.content;
413
+ subscribeExtraGeoms(onMessage) {
414
+ this.subscribe('extra_geoms', (data) => {
415
+ const extraGeom = data.content;
430
416
  if (extraGeom) {
431
- var ref = extraGeom.properties.ref;
417
+ const { ref } = extraGeom.properties;
432
418
  if (extraGeom.type === 'Feature') {
433
- _this.extraGeoms[ref] = extraGeom;
419
+ this.extraGeoms[ref] = extraGeom;
434
420
  }
435
421
  else {
436
- delete _this.extraGeoms[ref];
422
+ delete this.extraGeoms[ref];
437
423
  }
438
- onMessage(Object.keys(_this.extraGeoms).map(function (key) { return _this.extraGeoms[key]; }));
424
+ onMessage(Object.keys(this.extraGeoms).map((key) => this.extraGeoms[key]));
439
425
  }
440
426
  });
441
- };
427
+ }
442
428
  /**
443
429
  * Unsubscribe to extra_geoms channel.
444
430
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
445
431
  */
446
- RealtimeAPI.prototype.unsubscribeExtraGeoms = function (cb) {
432
+ unsubscribeExtraGeoms(cb) {
447
433
  this.unsubscribe('extra_geoms', '', cb);
448
- };
434
+ }
449
435
  /**
450
436
  * Subscribe to trajectory channel.
451
437
  *
@@ -453,18 +439,17 @@ var RealtimeAPI = /** @class */ (function () {
453
439
  * @param {function(trajectory: RealtimeTrajectory)} onMessage Function called on each message of the channel.
454
440
  * @param {boolean} quiet If true, the subscription will not send GET and SUB requests to the websocket.
455
441
  */
456
- RealtimeAPI.prototype.subscribeTrajectory = function (mode, onMessage, quiet) {
457
- if (quiet === void 0) { quiet = false; }
442
+ subscribeTrajectory(mode, onMessage, quiet = false) {
458
443
  this.unsubscribeTrajectory(onMessage);
459
- this.subscribe("trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), onMessage, null, quiet);
460
- };
444
+ this.subscribe(`trajectory${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
445
+ }
461
446
  /**
462
447
  * Unsubscribe to trajectory channels.
463
448
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
464
449
  */
465
- RealtimeAPI.prototype.unsubscribeTrajectory = function (cb) {
466
- this.unsubscribe("trajectory", '', cb);
467
- };
450
+ unsubscribeTrajectory(cb) {
451
+ this.unsubscribe(`trajectory`, '', cb);
452
+ }
468
453
  /**
469
454
  * Subscribe to deleted_vhicles channel.
470
455
  *
@@ -472,18 +457,17 @@ var RealtimeAPI = /** @class */ (function () {
472
457
  * @param {function(response: { content: Vehicle })} onMessage Function called on each message of the channel.
473
458
  * @param {boolean} quiet If true, the subscription will not send GET and SUB requests to the websocket.
474
459
  */
475
- RealtimeAPI.prototype.subscribeDeletedVehicles = function (mode, onMessage, quiet) {
476
- if (quiet === void 0) { quiet = false; }
460
+ subscribeDeletedVehicles(mode, onMessage, quiet = false) {
477
461
  this.unsubscribeDeletedVehicles(onMessage);
478
- this.subscribe("deleted_vehicles".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes)), onMessage, null, quiet);
479
- };
462
+ this.subscribe(`deleted_vehicles${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
463
+ }
480
464
  /**
481
465
  * Unsubscribe to deleted_vhicles channels.
482
466
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
483
467
  */
484
- RealtimeAPI.prototype.unsubscribeDeletedVehicles = function (cb) {
468
+ unsubscribeDeletedVehicles(cb) {
485
469
  this.unsubscribe('deleted_vehicles', '', cb);
486
- };
470
+ }
487
471
  /**
488
472
  * Get a full trajectory of a vehicule .
489
473
  *
@@ -492,26 +476,25 @@ var RealtimeAPI = /** @class */ (function () {
492
476
  * @param {string} generalizationLevel The generalization level to request. Can be one of 5 (more generalized), 10, 30, 100, undefined (less generalized).
493
477
  * @return {Promise<FullTrajectory>} Return a full trajectory.
494
478
  */
495
- RealtimeAPI.prototype.getFullTrajectory = function (id, mode, generalizationLevel) {
496
- var _this = this;
497
- var channel = ["full_trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes))];
479
+ getFullTrajectory(id, mode, generalizationLevel) {
480
+ const channel = [`full_trajectory${getModeSuffix(mode, RealtimeModes)}`];
498
481
  if (id) {
499
482
  channel.push(id);
500
483
  }
501
- if ((!mode || mode === exports.RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
502
- channel.push("gen".concat(generalizationLevel));
484
+ if ((!mode || mode === RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
485
+ channel.push(`gen${generalizationLevel}`);
503
486
  }
504
- var params = {
487
+ const params = {
505
488
  channel: channel.join('_'),
506
489
  };
507
- return new Promise(function (resolve) {
508
- _this.wsApi.get(params, function (data) {
490
+ return new Promise((resolve) => {
491
+ this.wsApi.get(params, (data) => {
509
492
  if (data.content) {
510
493
  resolve(data.content);
511
494
  }
512
495
  });
513
496
  });
514
- };
497
+ }
515
498
  /**
516
499
  * Get full trajectories of a vehicules .
517
500
  *
@@ -520,121 +503,111 @@ var RealtimeAPI = /** @class */ (function () {
520
503
  * @param {string} generalizationLevel The generalization level to request. Can be one of '', 'gen5', 'gen10', 'gen30', 'gen100'.
521
504
  * @return {Promise<Array<FullTrajectory>>} Return an array of full trajectories.
522
505
  */
523
- RealtimeAPI.prototype.getFullTrajectories = function (ids, mode, generalizationLevel) {
524
- var _this = this;
525
- var promises = ids.map(function (id) {
526
- return _this.getFullTrajectory(id, mode, generalizationLevel);
527
- });
506
+ getFullTrajectories(ids, mode, generalizationLevel) {
507
+ const promises = ids.map((id) => this.getFullTrajectory(id, mode, generalizationLevel));
528
508
  return Promise.all(promises);
529
- };
509
+ }
530
510
  /**
531
511
  * Subscribe to full_trajectory channel of a given vehicle.
532
512
  *
533
513
  * @param {string} id A vehicle id.
534
514
  * @param {RealtimeMode} mode Realtime mode.
535
515
  */
536
- RealtimeAPI.prototype.subscribeFullTrajectory = function (id, mode) {
516
+ subscribeFullTrajectory(id, mode) {
537
517
  // window.clearTimeout(this.fullTrajectoryUpdateTimeout);
538
518
  this.unsubscribeFullTrajectory(id);
539
- this.subscribe("full_trajectory".concat((0, getRealtimeModeSuffix_1.default)(mode, exports.RealtimeModes), "_").concat(id), function (data) {
519
+ this.subscribe(`full_trajectory${getModeSuffix(mode, RealtimeModes)}_${id}`, (data) => {
540
520
  // eslint-disable-next-line no-console
541
521
  console.log('subscribe full_trajectory', data);
542
- }, function (err) {
522
+ }, (err) => {
543
523
  // eslint-disable-next-line no-console
544
524
  console.log('subscribe full_trajectory error', err);
545
525
  });
546
- };
526
+ }
547
527
  /**
548
528
  * Unsubscribe from full_trajectory channel
549
529
  *
550
530
  * @param {string} id A vehicle id.
551
531
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
552
532
  */
553
- RealtimeAPI.prototype.unsubscribeFullTrajectory = function (id, cb) {
554
- this.unsubscribe('full_trajectory', "_".concat(id), cb);
555
- };
533
+ unsubscribeFullTrajectory(id, cb) {
534
+ this.unsubscribe('full_trajectory', `_${id}`, cb);
535
+ }
556
536
  /**
557
537
  * Get the list of stops for this vehicle.
558
538
  *
559
539
  * @param {string} id A vehicle id.
560
540
  * @return {Promise<StopSequence>} Returns a stop sequence object.
561
541
  */
562
- RealtimeAPI.prototype.getStopSequence = function (id) {
563
- var _this = this;
564
- var params = {
565
- channel: "stopsequence_".concat(id),
542
+ getStopSequence(id) {
543
+ const params = {
544
+ channel: `stopsequence_${id}`,
566
545
  };
567
- return new Promise(function (resolve, reject) {
568
- _this.wsApi.get(params, function (data) {
546
+ return new Promise((resolve, reject) => {
547
+ this.wsApi.get(params, (data) => {
569
548
  if (data.content && data.content.length) {
570
- var content = data.content.map(function (stopSequence) {
571
- return (0, cleanStopTime_1.default)(stopSequence);
572
- });
549
+ const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
573
550
  // Remove the delay from arrivalTime and departureTime
574
551
  resolve(content);
575
552
  }
576
553
  resolve([]);
577
- }, function (err) {
554
+ }, (err) => {
578
555
  reject(err);
579
556
  });
580
557
  });
581
- };
558
+ }
582
559
  /**
583
560
  * Get a list of stops for a list of vehicles.
584
561
  *
585
562
  * @param {string[]} ids List of vehicles ids.
586
563
  * @return {Promise<Array<StopSequence>>} Return an array of stop sequences.
587
564
  */
588
- RealtimeAPI.prototype.getStopSequences = function (ids) {
589
- var _this = this;
590
- var promises = ids.map(function (id) { return _this.getStopSequence(id); });
565
+ getStopSequences(ids) {
566
+ const promises = ids.map((id) => this.getStopSequence(id));
591
567
  return Promise.all(promises);
592
- };
568
+ }
593
569
  /**
594
570
  * Subscribe to stopsequence channel of a given vehicle.
595
571
  *
596
572
  * @param {string} id A vehicle id.
597
573
  * @param {function(stopSequence: StopSequence)} onMessage Function called on each message of the channel.
598
574
  */
599
- RealtimeAPI.prototype.subscribeStopSequence = function (id, onMessage) {
575
+ subscribeStopSequence(id, onMessage) {
600
576
  window.clearTimeout(this.fullTrajectoryUpdateTimeout);
601
577
  this.unsubscribeStopSequence(id);
602
- this.subscribe("stopsequence_".concat(id), function (data) {
578
+ this.subscribe(`stopsequence_${id}`, (data) => {
603
579
  if (data.content && data.content.length) {
604
- var content = data.content.map(function (stopSequence) {
605
- return (0, cleanStopTime_1.default)(stopSequence);
606
- });
580
+ const content = data.content.map((stopSequence) => cleanStopTime(stopSequence));
607
581
  // Remove the delay from arrivalTime and departureTime
608
582
  onMessage(content);
609
583
  }
610
- }, function (err) {
584
+ }, (err) => {
611
585
  // eslint-disable-next-line no-console
612
586
  console.log('subscribe stopsequence error', err);
613
587
  });
614
- };
588
+ }
615
589
  /**
616
590
  * Unsubscribe from stopsequence channel
617
591
  *
618
592
  * @param {string} id A vehicle id.
619
593
  * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
620
594
  */
621
- RealtimeAPI.prototype.unsubscribeStopSequence = function (id, cb) {
622
- this.unsubscribe("stopsequence", "_".concat(id), cb);
623
- };
595
+ unsubscribeStopSequence(id, cb) {
596
+ this.unsubscribe(`stopsequence`, `_${id}`, cb);
597
+ }
624
598
  /**
625
599
  * Subscribe to healthcheck channel.
626
600
  * @param {function} onMessage Callback when the subscribe to healthcheck channel succeeds.
627
601
  */
628
- RealtimeAPI.prototype.subscribeHealthCheck = function (onMessage) {
602
+ subscribeHealthCheck(onMessage) {
629
603
  this.unsubscribeHealthCheck();
630
604
  this.subscribe('healthcheck', onMessage);
631
- };
605
+ }
632
606
  /**
633
607
  * Unsubscribe to healthcheck channel.
634
608
  */
635
- RealtimeAPI.prototype.unsubscribeHealthCheck = function () {
609
+ unsubscribeHealthCheck() {
636
610
  this.unsubscribe('healthcheck');
637
- };
638
- return RealtimeAPI;
639
- }());
640
- exports.default = RealtimeAPI;
611
+ }
612
+ }
613
+ export default RealtimeAPI;