mobility-toolbox-js 2.0.0 → 2.0.1-beta.13

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 (102) hide show
  1. package/api/RoutingAPI.js +15 -0
  2. package/api/RoutingAPI.test.js +25 -0
  3. package/api/StopsAPI.js +12 -0
  4. package/api/StopsAPI.test.js +22 -0
  5. package/api/TralisAPI.js +359 -0
  6. package/api/TralisAPI.test.js +67 -0
  7. package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
  8. package/api/index.js +3 -3
  9. package/{ol/README.md → api/typedefs.js} +0 -0
  10. package/common/Tracker.js +14 -118
  11. package/common/api/HttpAPI.js +30 -0
  12. package/common/api/HttpAPI.test.js +50 -0
  13. package/common/api/WebSocketAPI.js +175 -0
  14. package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
  15. package/common/controls/Control.js +26 -91
  16. package/common/controls/Control.test.js +32 -43
  17. package/common/index.js +4 -0
  18. package/common/layers/Layer.js +53 -244
  19. package/common/layers/Layer.test.js +185 -244
  20. package/common/mixins/CopyrightMixin.js +20 -44
  21. package/common/mixins/SearchMixin.js +100 -166
  22. package/common/mixins/TralisLayerMixin.js +443 -894
  23. package/common/styles/index.js +4 -4
  24. package/common/styles/trackerDefaultStyle.js +39 -175
  25. package/common/styles/trackerDelayStyle.js +2 -11
  26. package/common/styles/trackerSimpleStyle.js +4 -8
  27. package/common/trackerConfig.js +61 -99
  28. package/common/trackerConfig.test.js +15 -17
  29. package/common/typedefs.js +0 -23
  30. package/common/utils/createTrackerFilters.js +10 -41
  31. package/common/utils/createTrackerFilters.test.js +40 -56
  32. package/common/utils/getMapboxMapCopyrights.js +3 -16
  33. package/common/utils/getMapboxMapCopyrights.test.js +32 -39
  34. package/common/utils/getMapboxStyleUrl.js +3 -13
  35. package/common/utils/getVehiclePosition.js +3 -33
  36. package/common/utils/index.js +5 -6
  37. package/common/utils/removeDuplicate.js +3 -17
  38. package/common/utils/removeDuplicate.test.js +17 -20
  39. package/common/utils/sortByDelay.js +2 -7
  40. package/common/utils/timeUtils.js +8 -32
  41. package/common/utils/timeUtils.test.js +7 -13
  42. package/index.js +8 -2
  43. package/mapbox/controls/CopyrightControl.js +9 -38
  44. package/mapbox/controls/index.js +1 -0
  45. package/mapbox/index.js +4 -3
  46. package/mapbox/layers/Layer.js +15 -76
  47. package/mapbox/layers/Layer.test.js +81 -101
  48. package/mapbox/layers/TralisLayer.js +46 -193
  49. package/mapbox/layers/TralisLayer.test.js +12 -14
  50. package/mapbox/layers/index.js +2 -0
  51. package/mapbox/utils.js +7 -21
  52. package/mbt.js +50444 -0
  53. package/mbt.js.map +7 -0
  54. package/mbt.min.js +1005 -0
  55. package/mbt.min.js.map +7 -0
  56. package/ol/controls/CopyrightControl.js +8 -46
  57. package/ol/controls/CopyrightControl.test.js +75 -121
  58. package/ol/controls/RoutingControl.js +167 -532
  59. package/ol/controls/RoutingControl.test.js +99 -164
  60. package/ol/controls/StopFinderControl.js +3 -31
  61. package/ol/controls/StopFinderControl.test.js +18 -29
  62. package/ol/controls/index.js +3 -0
  63. package/ol/index.js +5 -13
  64. package/ol/layers/Layer.js +23 -128
  65. package/ol/layers/Layer.test.js +79 -102
  66. package/ol/layers/MapboxLayer.js +62 -237
  67. package/ol/layers/MapboxLayer.test.js +58 -84
  68. package/ol/layers/MapboxStyleLayer.js +38 -268
  69. package/ol/layers/MapboxStyleLayer.test.js +97 -128
  70. package/ol/layers/MaplibreLayer.js +46 -187
  71. package/ol/layers/RoutingLayer.js +21 -51
  72. package/ol/layers/RoutingLayer.test.js +15 -24
  73. package/ol/layers/TralisLayer.js +102 -276
  74. package/ol/layers/TralisLayer.test.js +32 -50
  75. package/ol/layers/VectorLayer.js +3 -24
  76. package/ol/layers/VectorLayer.test.js +34 -45
  77. package/ol/layers/WMSLayer.js +15 -57
  78. package/ol/layers/WMSLayer.test.js +35 -43
  79. package/ol/layers/index.js +8 -0
  80. package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
  81. package/ol/styles/fullTrajectoryStyle.js +17 -25
  82. package/ol/styles/index.js +2 -2
  83. package/package.json +35 -62
  84. package/api/routing/RoutingAPI.js +0 -44
  85. package/api/routing/RoutingAPI.test.js +0 -41
  86. package/api/stops/StopsAPI.js +0 -41
  87. package/api/stops/StopsAPI.test.js +0 -34
  88. package/api/tralis/TralisAPI.js +0 -731
  89. package/api/tralis/TralisAPI.test.js +0 -75
  90. package/api/tralis/WebSocketConnector.js +0 -338
  91. package/api/tralis/typedefs.js +0 -81
  92. package/common/api/api.js +0 -64
  93. package/common/api/api.test.js +0 -68
  94. package/index.js.map +0 -1
  95. package/module.js +0 -23
  96. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  97. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  98. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  99. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  100. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  101. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  102. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
@@ -1,4 +1,4 @@
1
- export { default as trackerDefaultStyle } from './trackerDefaultStyle';
2
- export { default as trackerDelayStyle } from './trackerDelayStyle';
3
- export * from './trackerDefaultStyle';
4
- export { default as trackerSimpleStyle } from './trackerSimpleStyle';
1
+ export { default as trackerDefaultStyle } from "./trackerDefaultStyle";
2
+ export { default as trackerDelayStyle } from "./trackerDelayStyle";
3
+ export { default as trackerSimpleStyle } from "./trackerSimpleStyle";
4
+ export * from "./trackerDefaultStyle";
@@ -4,50 +4,37 @@ import {
4
4
  getDelayColor,
5
5
  getDelayText,
6
6
  getTextColor,
7
- getTextSize,
8
- } from '../trackerConfig';
9
-
7
+ getTextSize
8
+ } from "../trackerConfig";
10
9
  const createCanvas = (width, height) => {
11
- const canvas = document.createElement('canvas');
10
+ const canvas = document.createElement("canvas");
12
11
  canvas.width = width;
13
12
  canvas.height = height;
14
13
  return canvas;
15
14
  };
16
-
17
- // Draw circle delay background
18
15
  const cacheDelayBg = {};
19
16
  export const getDelayBgCanvas = (origin, radius, color) => {
20
17
  const key = `${origin}, ${radius}, ${color}`;
21
18
  if (!cacheDelayBg[key]) {
22
19
  const canvas = createCanvas(origin * 2, origin * 2);
23
- const ctx = canvas.getContext('2d');
20
+ const ctx = canvas.getContext("2d");
24
21
  ctx.beginPath();
25
22
  ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
26
23
  ctx.fillStyle = color;
27
- ctx.filter = 'blur(1px)';
24
+ ctx.filter = "blur(1px)";
28
25
  ctx.fill();
29
26
  cacheDelayBg[key] = canvas;
30
27
  }
31
28
  return cacheDelayBg[key];
32
29
  };
33
-
34
- // Draw delay text
35
30
  const cacheDelayText = {};
36
- export const getDelayTextCanvas = (
37
- width,
38
- text,
39
- fontSize,
40
- font,
41
- delayColor,
42
- delayOutlineColor,
43
- pixelRatio,
44
- ) => {
31
+ export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor, pixelRatio) => {
45
32
  const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
46
33
  if (!cacheDelayText[key]) {
47
34
  const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
48
- const ctx = canvas.getContext('2d');
49
- ctx.textAlign = 'left';
50
- ctx.textBaseline = 'middle';
35
+ const ctx = canvas.getContext("2d");
36
+ ctx.textAlign = "left";
37
+ ctx.textBaseline = "middle";
51
38
  ctx.font = font;
52
39
  ctx.fillStyle = delayColor;
53
40
  ctx.strokeStyle = delayOutlineColor;
@@ -59,94 +46,56 @@ export const getDelayTextCanvas = (
59
46
  }
60
47
  return cacheDelayText[key];
61
48
  };
62
-
63
- // Draw colored circle with black border
64
49
  const cacheCircle = {};
65
- export const getCircleCanvas = (
66
- origin,
67
- radius,
68
- color,
69
- hasStroke,
70
- hasDash,
71
- pixelRatio,
72
- ) => {
50
+ export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
73
51
  const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
74
52
  if (!cacheCircle[key]) {
75
53
  const canvas = createCanvas(origin * 2, origin * 2);
76
- const ctx = canvas.getContext('2d');
54
+ const ctx = canvas.getContext("2d");
77
55
  ctx.fillStyle = color;
78
-
79
56
  if (hasStroke) {
80
57
  ctx.lineWidth = 1 * pixelRatio;
81
- ctx.strokeStyle = '#000000';
58
+ ctx.strokeStyle = "#000000";
82
59
  }
83
-
84
60
  ctx.beginPath();
85
61
  ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
86
62
  ctx.fill();
87
-
88
63
  if (hasDash) {
89
64
  ctx.setLineDash([5, 3]);
90
65
  }
91
-
92
66
  if (hasStroke) {
93
67
  ctx.stroke();
94
68
  }
95
-
96
69
  cacheCircle[key] = canvas;
97
70
  }
98
71
  return cacheCircle[key];
99
72
  };
100
-
101
- // Draw text in the circle
102
73
  const cacheText = {};
103
- export const getTextCanvas = (
104
- text,
105
- origin,
106
- textSize,
107
- fillColor,
108
- strokeColor,
109
- hasStroke,
110
- pixelRatio,
111
- ) => {
74
+ export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
112
75
  const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
113
76
  if (!cacheText[key]) {
114
77
  const canvas = createCanvas(origin * 2, origin * 2);
115
- const ctx = canvas.getContext('2d');
116
-
117
- // Draw a stroke to the text only if a provider provides realtime but we don't use it.
78
+ const ctx = canvas.getContext("2d");
118
79
  if (hasStroke) {
119
80
  ctx.save();
120
- ctx.textBaseline = 'middle';
121
- ctx.textAlign = 'center';
81
+ ctx.textBaseline = "middle";
82
+ ctx.textAlign = "center";
122
83
  ctx.font = `bold ${textSize + 2}px Arial`;
123
84
  ctx.strokeStyle = strokeColor;
124
85
  ctx.strokeText(text, origin, origin);
125
86
  ctx.restore();
126
87
  }
127
-
128
- // Draw a text
129
- ctx.textBaseline = 'middle';
130
- ctx.textAlign = 'center';
88
+ ctx.textBaseline = "middle";
89
+ ctx.textAlign = "center";
131
90
  ctx.fillStyle = fillColor;
132
91
  ctx.font = `bold ${textSize}px Arial`;
133
92
  ctx.strokeStyle = strokeColor;
134
93
  ctx.strokeText(text, origin, origin);
135
94
  ctx.fillText(text, origin, origin);
136
-
137
95
  cacheText[key] = canvas;
138
96
  }
139
97
  return cacheText[key];
140
98
  };
141
-
142
- /**
143
- * A tracker style that take in account the delay.
144
- *
145
- * @param {*} trajectory The trajectory to render.
146
- * @param {*} viewState The view state of the map.
147
- * @param {*} options Some options to change the rendering
148
- * @return a canvas
149
- */
150
99
  const styleCache = {};
151
100
  const style = (trajectory, viewState, options) => {
152
101
  const {
@@ -154,9 +103,8 @@ const style = (trajectory, viewState, options) => {
154
103
  selectedVehicleId,
155
104
  useDelayStyle,
156
105
  delayOutlineColor,
157
- delayDisplay,
106
+ delayDisplay
158
107
  } = options;
159
-
160
108
  const { zoom, pixelRatio } = viewState;
161
109
  let { type, cancelled } = trajectory.properties;
162
110
  const {
@@ -164,170 +112,86 @@ const style = (trajectory, viewState, options) => {
164
112
  line,
165
113
  delay,
166
114
  state,
167
- operator_provides_realtime_journey: operatorProvidesRealtime,
115
+ operator_provides_realtime_journey: operatorProvidesRealtime
168
116
  } = trajectory.properties;
169
117
  let { name, text_color: textColor, color } = line || {};
170
-
171
- // In the future, the cancelled property will be removed we still managed it
172
- // until the backend change is on prod.
173
- cancelled = cancelled === true || state === 'JOURNEY_CANCELLED';
174
-
118
+ cancelled = cancelled === true || state === "JOURNEY_CANCELLED";
175
119
  if (!type) {
176
- type = 'Rail';
120
+ type = "Rail";
177
121
  }
178
-
179
122
  if (!name) {
180
- name = 'I';
123
+ name = "I";
181
124
  }
182
-
183
125
  if (!textColor) {
184
- textColor = '#000000';
126
+ textColor = "#000000";
185
127
  }
186
-
187
- if (color && color[0] !== '#') {
128
+ if (color && color[0] !== "#") {
188
129
  color = `#${color}`;
189
130
  }
190
-
191
- if (textColor[0] !== '#') {
131
+ if (textColor[0] !== "#") {
192
132
  textColor = `#${textColor}`;
193
133
  }
194
-
195
134
  const z = Math.min(Math.floor(zoom || 1), 16);
196
135
  const hover = hoverVehicleId && hoverVehicleId === id;
197
136
  const selected = selectedVehicleId && selectedVehicleId === id;
198
-
199
- // Calcul the radius of the circle
200
137
  let radius = getRadius(type, z) * pixelRatio;
201
138
  const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
202
139
  if (hover || selected) {
203
- radius = isDisplayStrokeAndDelay
204
- ? radius + 5 * pixelRatio
205
- : 14 * pixelRatio;
140
+ radius = isDisplayStrokeAndDelay ? radius + 5 * pixelRatio : 14 * pixelRatio;
206
141
  }
207
142
  const mustDrawText = radius > 10 * pixelRatio;
208
-
209
- // Optimize the cache key, very important in high zoom level
210
143
  let key = `${radius}${type}${color}${hover}${selected}${cancelled}${delay}`;
211
-
212
144
  if (useDelayStyle) {
213
145
  key += `${operatorProvidesRealtime}`;
214
146
  }
215
-
216
147
  if (mustDrawText) {
217
148
  key += `${name}${textColor}`;
218
149
  }
219
-
220
150
  if (!styleCache[key]) {
221
151
  if (radius === 0) {
222
152
  styleCache[key] = null;
223
153
  return null;
224
154
  }
225
-
226
155
  const margin = 1 * pixelRatio;
227
156
  const radiusDelay = radius + 2;
228
157
  const markerSize = radius * 2;
229
- const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio; // add space for delay information
158
+ const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio;
230
159
  const origin = size / 2;
231
-
232
- // Create the canvas
233
160
  const canvas = createCanvas(size, size);
234
- const ctx = canvas.getContext('2d');
235
-
161
+ const ctx = canvas.getContext("2d");
236
162
  if (isDisplayStrokeAndDelay && delay !== null) {
237
- // Draw circle delay background
238
- const delayBg = getDelayBgCanvas(
239
- origin,
240
- radiusDelay,
241
- getDelayColor(delay, cancelled),
242
- );
163
+ const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
243
164
  ctx.drawImage(delayBg, 0, 0);
244
165
  }
245
-
246
- // Show delay if feature is hovered or if delay is above 5mins.
247
- if (
248
- isDisplayStrokeAndDelay &&
249
- (hover || delay >= delayDisplay || cancelled)
250
- ) {
251
- // Draw delay text
252
- const fontSize =
253
- Math.max(
254
- cancelled ? 19 : 14,
255
- Math.min(cancelled ? 19 : 17, radius * 1.2),
256
- ) * pixelRatio;
166
+ if (isDisplayStrokeAndDelay && (hover || delay >= delayDisplay || cancelled)) {
167
+ const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
257
168
  const text = getDelayText(delay, cancelled);
258
-
259
169
  if (text) {
260
170
  const textWidth = text.length * fontSize;
261
- const delayText = getDelayTextCanvas(
262
- textWidth,
263
- text,
264
- fontSize,
265
- `bold ${fontSize}px arial, sans-serif`,
266
- getDelayColor(delay, cancelled, true),
267
- delayOutlineColor,
268
- pixelRatio,
269
- );
270
- ctx.drawImage(
271
- delayText,
272
- origin + radiusDelay + margin,
273
- origin - fontSize,
274
- );
171
+ const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
172
+ ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
275
173
  }
276
174
  }
277
-
278
- // Draw colored circle with black border
279
175
  let circleFillColor;
280
176
  if (useDelayStyle) {
281
177
  circleFillColor = getDelayColor(delay, cancelled);
282
178
  } else {
283
179
  circleFillColor = color || getBgColor(type);
284
180
  }
285
-
286
181
  const hasStroke = isDisplayStrokeAndDelay || hover || selected;
287
-
288
- const hasDash =
289
- isDisplayStrokeAndDelay &&
290
- useDelayStyle &&
291
- delay === null &&
292
- operatorProvidesRealtime === 'yes';
293
-
294
- const circle = getCircleCanvas(
295
- origin,
296
- radius,
297
- circleFillColor,
298
- hasStroke,
299
- hasDash,
300
- pixelRatio,
301
- );
302
-
182
+ const hasDash = isDisplayStrokeAndDelay && useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
183
+ const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
303
184
  ctx.drawImage(circle, 0, 0);
304
-
305
- // Draw text in the circle
306
185
  if (mustDrawText) {
307
186
  const fontSize = Math.max(radius, 10);
308
187
  const textSize = getTextSize(ctx, markerSize, name, fontSize);
309
- const textColor2 = !useDelayStyle
310
- ? textColor || getTextColor(type)
311
- : '#000000';
312
- const hasStroke2 =
313
- useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
314
-
315
- const text = getTextCanvas(
316
- name,
317
- origin,
318
- textSize,
319
- textColor2,
320
- circleFillColor,
321
- hasStroke2,
322
- pixelRatio,
323
- );
324
-
188
+ const textColor2 = !useDelayStyle ? textColor || getTextColor(type) : "#000000";
189
+ const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
190
+ const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
325
191
  ctx.drawImage(text, 0, 0);
326
192
  }
327
-
328
193
  styleCache[key] = canvas;
329
194
  }
330
-
331
195
  return styleCache[key];
332
196
  };
333
197
  export default style;
@@ -1,17 +1,8 @@
1
- import trackerDefaultStyle from './trackerDefaultStyle';
2
-
3
- /**
4
- * A tracker style that display the delay as backgroundColor.
5
- *
6
- * @param {*} trajectory The trajectory to render.
7
- * @param {*} viewState The view state of the map.
8
- * @param {*} options Some options to change the rendering
9
- * @return a canvas
10
- */
1
+ import trackerDefaultStyle from "./trackerDefaultStyle";
11
2
  const style = (trajectory, viewState, options) => {
12
3
  return trackerDefaultStyle(trajectory, viewState, {
13
4
  ...options,
14
- useDelayStyle: true,
5
+ useDelayStyle: true
15
6
  });
16
7
  };
17
8
  export default style;
@@ -1,19 +1,15 @@
1
- /**
2
- * A very simple tracker style.
3
- * Display blue point for each train.
4
- */
5
1
  let canvas;
6
2
  const style = () => {
7
3
  if (!canvas) {
8
- document.createElement('canvas');
4
+ document.createElement("canvas");
9
5
  canvas.width = 15;
10
6
  canvas.height = 15;
11
- const ctx = canvas.getContext('2d');
7
+ const ctx = canvas.getContext("2d");
12
8
  ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
13
- ctx.fillStyle = '#8ED6FF';
9
+ ctx.fillStyle = "#8ED6FF";
14
10
  ctx.fill();
15
11
  ctx.lineWidth = 3;
16
- ctx.strokeStyle = 'black';
12
+ ctx.strokeStyle = "black";
17
13
  ctx.stroke();
18
14
  ctx.lineWidth = 3;
19
15
  }
@@ -8,16 +8,8 @@ const trackerRadiusMapping = {
8
8
  6: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
9
9
  7: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
10
10
  8: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
11
- 9: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15],
11
+ 9: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15]
12
12
  };
13
-
14
- /**
15
- * Trajserv value: 'Tram', 'Subway / Metro / S-Bahn', 'Train', 'Bus', 'Ferry', 'Cable Car', 'Gondola', 'Funicular', 'Long distance bus', 'Rail',
16
- * New endpoint use Rail instead of Train.
17
- * New tracker values: null, "tram", "subway", "rail", "bus", "ferry", "cablecar", "gondola", "funicular", "coach".
18
- *
19
- * @ignore
20
- */
21
13
  export const types = [
22
14
  /^Tram/i,
23
15
  /^Subway( \/ Metro \/ S-Bahn)?/i,
@@ -28,62 +20,61 @@ export const types = [
28
20
  /^Gondola/i,
29
21
  /^Funicular/i,
30
22
  /^(Long distance bus|coach)/i,
31
- /^Rail/i, // New endpoint use Rail instead of Train.
23
+ /^Rail/i
32
24
  ];
33
-
34
- /**
35
- * @ignore
36
- */
37
25
  export const bgColors = [
38
- '#ffb400',
39
- '#ff5400',
40
- '#ff8080',
41
- '#ea0000',
42
- '#3000ff',
43
- '#ffb400',
44
- '#41a27b',
45
- '#00d237',
46
- '#b5b5b5',
47
- '#ff8080',
26
+ "#ffb400",
27
+ "#ff5400",
28
+ "#ff8080",
29
+ "#ea0000",
30
+ "#3000ff",
31
+ "#ffb400",
32
+ "#41a27b",
33
+ "#00d237",
34
+ "#b5b5b5",
35
+ "#ff8080"
48
36
  ];
49
-
50
- /**
51
- * @ignore
52
- */
53
37
  export const textColors = [
54
- '#000000',
55
- '#ffffff',
56
- '#000000',
57
- '#ffffff',
58
- '#ffffff',
59
- '#000000',
60
- '#ffffff',
61
- '#000000',
62
- '#000000',
63
- '#000000',
38
+ "#000000",
39
+ "#ffffff",
40
+ "#000000",
41
+ "#ffffff",
42
+ "#ffffff",
43
+ "#000000",
44
+ "#ffffff",
45
+ "#000000",
46
+ "#000000",
47
+ "#000000"
64
48
  ];
65
-
66
- /**
67
- * @ignore
68
- */
69
49
  export const timeSteps = [
70
- 100000, 50000, 40000, 30000, 20000, 15000, 10000, 5000, 2000, 1000, 400, 300,
71
- 250, 180, 90, 60, 50, 50, 50, 50, 50,
50
+ 1e5,
51
+ 5e4,
52
+ 4e4,
53
+ 3e4,
54
+ 2e4,
55
+ 15e3,
56
+ 1e4,
57
+ 5e3,
58
+ 2e3,
59
+ 1e3,
60
+ 400,
61
+ 300,
62
+ 250,
63
+ 180,
64
+ 90,
65
+ 60,
66
+ 50,
67
+ 50,
68
+ 50,
69
+ 50,
70
+ 50
72
71
  ];
73
-
74
- /**
75
- * @ignore
76
- */
77
72
  export const getTypeIndex = (type) => {
78
- if (typeof type === 'string') {
73
+ if (typeof type === "string") {
79
74
  return types.findIndex((t) => t.test(type));
80
75
  }
81
76
  return type;
82
77
  };
83
-
84
- /**
85
- * @ignore
86
- */
87
78
  export const getRadius = (type, zoom) => {
88
79
  try {
89
80
  const typeIdx = getTypeIndex(type || 0);
@@ -92,10 +83,6 @@ export const getRadius = (type, zoom) => {
92
83
  return 1;
93
84
  }
94
85
  };
95
-
96
- /**
97
- * @ignore
98
- */
99
86
  export const getBgColor = (type = 0) => {
100
87
  try {
101
88
  const typeIdx = getTypeIndex(type);
@@ -104,10 +91,6 @@ export const getBgColor = (type = 0) => {
104
91
  return 1;
105
92
  }
106
93
  };
107
-
108
- /**
109
- * @ignore
110
- */
111
94
  export const getTextColor = (type = 0) => {
112
95
  try {
113
96
  const typeIdx = getTypeIndex(type);
@@ -116,19 +99,12 @@ export const getTextColor = (type = 0) => {
116
99
  return 1;
117
100
  }
118
101
  };
119
-
120
- /**
121
- * @ignore
122
- */
123
102
  export const getTextSize = (ctx, markerSize, text, fontSize) => {
124
103
  ctx.font = `bold ${fontSize}px Arial`;
125
104
  let newText = ctx.measureText(text);
126
-
127
105
  const maxiter = 25;
128
106
  let i = 0;
129
-
130
107
  while (newText.width > markerSize - 6 && i < maxiter) {
131
- // eslint-disable-next-line no-param-reassign
132
108
  fontSize -= 0.5;
133
109
  ctx.font = `bold ${fontSize}px arial, sans-serif`;
134
110
  newText = ctx.measureText(text);
@@ -136,55 +112,41 @@ export const getTextSize = (ctx, markerSize, text, fontSize) => {
136
112
  }
137
113
  return fontSize;
138
114
  };
139
-
140
- /**
141
- * @ignore
142
- * @param {number} delayInMs Delay in milliseconds.
143
- * @param {boolean} cancelled true if the journey is cancelled.
144
- * @param {boolean} isDelayText true if the color is used for delay text of the symbol.
145
- */
146
115
  export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
147
116
  if (cancelled) {
148
- return isDelayText ? '#ff0000' : '#a0a0a0'; // red or gray
117
+ return isDelayText ? "#ff0000" : "#a0a0a0";
149
118
  }
150
- if (delayInMs >= 3600000) {
151
- return '#ed004c'; // pink { r: 237, g: 0, b: 76, s: '237,0,76' };
119
+ if (delayInMs >= 36e5) {
120
+ return "#ed004c";
152
121
  }
153
- if (delayInMs >= 500000) {
154
- return '#e80000'; // red { r: 232, g: 0, b: 0, s: '232,0,0' };
122
+ if (delayInMs >= 5e5) {
123
+ return "#e80000";
155
124
  }
156
- if (delayInMs >= 300000) {
157
- return '#ff4a00'; // orange { r: 255, g: 74, b: 0, s: '255,74,0' };
125
+ if (delayInMs >= 3e5) {
126
+ return "#ff4a00";
158
127
  }
159
- if (delayInMs >= 180000) {
160
- return '#f7bf00'; // yellow { r: 247, g: 191, b: 0, s: '247,191,0' };
128
+ if (delayInMs >= 18e4) {
129
+ return "#f7bf00";
161
130
  }
162
131
  if (delayInMs === null) {
163
- return '#a0a0a0'; // grey { r: 160, g: 160, b: 160, s: '160,160,160' };
132
+ return "#a0a0a0";
164
133
  }
165
- return '#00a00c'; // green { r: 0, g: 160, b: 12, s: '0,160,12' };
134
+ return "#00a00c";
166
135
  };
167
-
168
- /**
169
- * @ignore
170
- */
171
136
  export const getDelayText = (delayInMs, cancelled) => {
172
137
  if (cancelled) {
173
- return String.fromCodePoint(0x00d7);
138
+ return String.fromCodePoint(215);
174
139
  }
175
- if (delayInMs > 3600000) {
176
- const rounded = Math.round(delayInMs / 3600000);
140
+ if (delayInMs > 36e5) {
141
+ const rounded = Math.round(delayInMs / 36e5);
177
142
  return `+${rounded}h`;
178
143
  }
179
-
180
- if (delayInMs > 59000) {
181
- const rounded = Math.round(delayInMs / 60000);
144
+ if (delayInMs > 59e3) {
145
+ const rounded = Math.round(delayInMs / 6e4);
182
146
  return `+${rounded}m`;
183
147
  }
184
-
185
148
  if (delayInMs > 0) {
186
149
  return `+${delayInMs}s`;
187
150
  }
188
-
189
- return '';
151
+ return "";
190
152
  };