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,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTextCanvas = exports.getCircleCanvas = exports.getDelayTextCanvas = exports.getDelayBgCanvas = void 0;
4
- var createCanvas_1 = require("../utils/createCanvas");
1
+ import createCanvas from '../utils/createCanvas';
5
2
  /** @private */
6
- var cacheDelayBg = {};
3
+ const cacheDelayBg = {};
7
4
  /**
8
5
  * Draw circle delay background
9
6
  *
10
7
  * @private
11
8
  */
12
- var getDelayBgCanvas = function (origin, radius, color) {
13
- var key = "".concat(origin, ", ").concat(radius, ", ").concat(color);
9
+ export const getDelayBgCanvas = (origin, radius, color) => {
10
+ const key = `${origin}, ${radius}, ${color}`;
14
11
  if (!cacheDelayBg[key]) {
15
- var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
12
+ const canvas = createCanvas(origin * 2, origin * 2);
16
13
  if (canvas) {
17
- var ctx = canvas.getContext('2d');
14
+ const ctx = canvas.getContext('2d');
18
15
  ctx.beginPath();
19
16
  ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
20
17
  ctx.fillStyle = color;
@@ -25,29 +22,26 @@ var getDelayBgCanvas = function (origin, radius, color) {
25
22
  }
26
23
  return cacheDelayBg[key];
27
24
  };
28
- exports.getDelayBgCanvas = getDelayBgCanvas;
29
25
  /** @private */
30
- var cacheDelayText = {};
26
+ const cacheDelayText = {};
31
27
  /**
32
28
  * Draw delay text
33
29
  *
34
30
  * @private
35
31
  */
36
- var getDelayTextCanvas = function (width, text, fontSize, font, delayColor, delayOutlineColor, pixelRatio) {
37
- if (delayOutlineColor === void 0) { delayOutlineColor = '#000'; }
38
- if (pixelRatio === void 0) { pixelRatio = 1; }
39
- var key = "".concat(width, ", ").concat(text, ", ").concat(font, ", ").concat(delayColor, ", ").concat(delayOutlineColor, ", ").concat(pixelRatio);
32
+ export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor = '#000', pixelRatio = 1) => {
33
+ const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
40
34
  if (!cacheDelayText[key]) {
41
- var canvas = (0, createCanvas_1.default)(width, fontSize + 8 * pixelRatio);
35
+ const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
42
36
  if (canvas) {
43
- var ctx = canvas.getContext('2d');
37
+ const ctx = canvas.getContext('2d');
44
38
  ctx.textAlign = 'left';
45
39
  ctx.textBaseline = 'middle';
46
40
  ctx.font = font;
47
41
  ctx.fillStyle = delayColor;
48
42
  ctx.strokeStyle = delayOutlineColor;
49
43
  ctx.lineWidth = 1.5 * pixelRatio;
50
- var delayText = text;
44
+ const delayText = text;
51
45
  ctx.strokeText(delayText, 0, fontSize);
52
46
  ctx.fillText(delayText, 0, fontSize);
53
47
  cacheDelayText[key] = canvas;
@@ -55,20 +49,19 @@ var getDelayTextCanvas = function (width, text, fontSize, font, delayColor, dela
55
49
  }
56
50
  return cacheDelayText[key];
57
51
  };
58
- exports.getDelayTextCanvas = getDelayTextCanvas;
59
52
  /** @private */
60
- var cacheCircle = {};
53
+ const cacheCircle = {};
61
54
  /**
62
55
  * Draw colored circle with black border
63
56
  *
64
57
  * @private
65
58
  */
66
- var getCircleCanvas = function (origin, radius, color, hasStroke, hasDash, pixelRatio) {
67
- var key = "".concat(origin, ", ").concat(radius, ", ").concat(color, ", ").concat(hasStroke, ", ").concat(hasDash, ", ").concat(pixelRatio);
59
+ export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
60
+ const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
68
61
  if (!cacheCircle[key]) {
69
- var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
62
+ const canvas = createCanvas(origin * 2, origin * 2);
70
63
  if (canvas) {
71
- var ctx = canvas.getContext('2d');
64
+ const ctx = canvas.getContext('2d');
72
65
  ctx.fillStyle = color;
73
66
  if (hasStroke) {
74
67
  ctx.lineWidth = 1 * pixelRatio;
@@ -88,26 +81,25 @@ var getCircleCanvas = function (origin, radius, color, hasStroke, hasDash, pixel
88
81
  }
89
82
  return cacheCircle[key];
90
83
  };
91
- exports.getCircleCanvas = getCircleCanvas;
92
84
  /** @private */
93
- var cacheText = {};
85
+ const cacheText = {};
94
86
  /**
95
87
  * Draw text in the circle
96
88
  *
97
89
  * @private
98
90
  */
99
- var getTextCanvas = function (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) {
100
- var key = "".concat(text, ", ").concat(origin, ", ").concat(textSize, ", ").concat(fillColor, ",").concat(strokeColor, ", ").concat(hasStroke, ", ").concat(pixelRatio);
91
+ export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
92
+ const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
101
93
  if (!cacheText[key]) {
102
- var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
94
+ const canvas = createCanvas(origin * 2, origin * 2);
103
95
  if (canvas) {
104
- var ctx = canvas.getContext('2d');
96
+ const ctx = canvas.getContext('2d');
105
97
  // Draw a stroke to the text only if a provider provides realtime but we don't use it.
106
98
  if (hasStroke) {
107
99
  ctx.save();
108
100
  ctx.textBaseline = 'middle';
109
101
  ctx.textAlign = 'center';
110
- ctx.font = "bold ".concat(textSize + 2, "px Arial");
102
+ ctx.font = `bold ${textSize + 2}px Arial`;
111
103
  ctx.strokeStyle = strokeColor;
112
104
  ctx.strokeText(text, origin, origin);
113
105
  ctx.restore();
@@ -116,7 +108,7 @@ var getTextCanvas = function (text, origin, textSize, fillColor, strokeColor, ha
116
108
  ctx.textBaseline = 'middle';
117
109
  ctx.textAlign = 'center';
118
110
  ctx.fillStyle = fillColor;
119
- ctx.font = "bold ".concat(textSize, "px Arial");
111
+ ctx.font = `bold ${textSize}px Arial`;
120
112
  ctx.strokeStyle = strokeColor;
121
113
  ctx.strokeText(text, origin, origin);
122
114
  ctx.fillText(text, origin, origin);
@@ -125,9 +117,8 @@ var getTextCanvas = function (text, origin, textSize, fillColor, strokeColor, ha
125
117
  }
126
118
  return cacheText[key];
127
119
  };
128
- exports.getTextCanvas = getTextCanvas;
129
120
  /** @private */
130
- var cache = {};
121
+ const cache = {};
131
122
  /**
132
123
  * A tracker style that take in account the delay.
133
124
  *
@@ -136,15 +127,13 @@ var cache = {};
136
127
  * @param {*} options Some options to change the rendering
137
128
  * @return a canvas
138
129
  */
139
- var realtimeDefaultStyle = function (trajectory, viewState, options) {
140
- var hoverVehicleId = options.hoverVehicleId, selectedVehicleId = options.selectedVehicleId, useDelayStyle = options.useDelayStyle, _a = options.delayOutlineColor, delayOutlineColor = _a === void 0 ? '#000' : _a, _b = options.delayDisplay, delayDisplay = _b === void 0 ? 300000 : _b, getRadius = options.getRadius, getBgColor = options.getBgColor, getDelayColor = options.getDelayColor, getDelayText = options.getDelayText, getTextColor = options.getTextColor, getTextSize = options.getTextSize;
141
- var zoom = viewState.zoom, pixelRatio = viewState.pixelRatio;
142
- var _c = trajectory.properties, type = _c.type, cancelled = _c.cancelled;
143
- var _d = trajectory.properties, id = _d.train_id, line = _d.line, delay = _d.delay, state = _d.state, operatorProvidesRealtime = _d.operator_provides_realtime_journey;
144
- var _e = line || {}, name = _e.name, textColor = _e.text_color, color = _e.color;
145
- // In the future, the cancelled property will be removed we still managed it
146
- // until the backend change is on prod.
147
- cancelled = cancelled === true || state === 'JOURNEY_CANCELLED';
130
+ const realtimeDefaultStyle = (trajectory, viewState, options) => {
131
+ const { hoverVehicleId, selectedVehicleId, useDelayStyle, delayOutlineColor = '#000', delayDisplay = 300000, getRadius, getBgColor, getDelayColor, getDelayText, getTextColor, getTextSize, } = options;
132
+ const { zoom, pixelRatio } = viewState;
133
+ let { type } = trajectory.properties;
134
+ const { train_id: id, line, delay, state, operator_provides_realtime_journey: operatorProvidesRealtime, } = trajectory.properties;
135
+ let { name, text_color: textColor, color } = line || {};
136
+ const cancelled = state === 'JOURNEY_CANCELLED';
148
137
  if (!type) {
149
138
  type = 'Rail';
150
139
  }
@@ -155,89 +144,89 @@ var realtimeDefaultStyle = function (trajectory, viewState, options) {
155
144
  textColor = '#000000';
156
145
  }
157
146
  if (color && color[0] !== '#') {
158
- color = "#".concat(color);
147
+ color = `#${color}`;
159
148
  }
160
149
  if (textColor[0] !== '#') {
161
- textColor = "#".concat(textColor);
150
+ textColor = `#${textColor}`;
162
151
  }
163
- var z = Math.min(Math.floor(zoom || 1), 16);
164
- var hover = hoverVehicleId && hoverVehicleId === id;
165
- var selected = selectedVehicleId && selectedVehicleId === id;
152
+ const z = Math.min(Math.floor(zoom || 1), 16);
153
+ const hover = hoverVehicleId && hoverVehicleId === id;
154
+ const selected = selectedVehicleId && selectedVehicleId === id;
166
155
  // Calcul the radius of the circle
167
- var radius = getRadius(type, z) * pixelRatio;
168
- var isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
156
+ let radius = getRadius(type, z) * pixelRatio;
157
+ const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
169
158
  if (hover || selected) {
170
159
  radius = isDisplayStrokeAndDelay
171
160
  ? radius + 5 * pixelRatio
172
161
  : 14 * pixelRatio;
173
162
  }
174
- var mustDrawText = radius > 10 * pixelRatio;
163
+ const mustDrawText = radius > 10 * pixelRatio;
175
164
  // Optimize the cache key, very important in high zoom level
176
- var key = "".concat(radius).concat(hover).concat(selected).concat(cancelled).concat(delay);
165
+ let key = `${radius}${hover}${selected}${cancelled}${delay}`;
177
166
  if (useDelayStyle) {
178
- key += "".concat(operatorProvidesRealtime);
167
+ key += `${operatorProvidesRealtime}`;
179
168
  }
180
169
  else {
181
- key += "".concat(type).concat(color);
170
+ key += `${type}${color}`;
182
171
  }
183
172
  if (mustDrawText) {
184
- key += "".concat(name).concat(textColor);
173
+ key += `${name}${textColor}`;
185
174
  }
186
175
  if (!cache[key]) {
187
176
  if (radius === 0) {
188
177
  cache[key] = null;
189
178
  return null;
190
179
  }
191
- var margin = 1 * pixelRatio;
192
- var radiusDelay = radius + 2;
193
- var markerSize = radius * 2;
194
- var size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio; // add space for delay information
195
- var origin_1 = size / 2;
180
+ const margin = 1 * pixelRatio;
181
+ const radiusDelay = radius + 2;
182
+ const markerSize = radius * 2;
183
+ const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio; // add space for delay information
184
+ const origin = size / 2;
196
185
  // Create the canvas
197
- var canvas = (0, createCanvas_1.default)(size, size);
186
+ const canvas = createCanvas(size, size);
198
187
  if (canvas) {
199
- var ctx = canvas.getContext('2d');
188
+ const ctx = canvas.getContext('2d');
200
189
  if (isDisplayStrokeAndDelay && delay !== null) {
201
190
  // Draw circle delay background
202
- var delayBg = (0, exports.getDelayBgCanvas)(origin_1, radiusDelay, getDelayColor(delay, cancelled));
191
+ const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
203
192
  ctx.drawImage(delayBg, 0, 0);
204
193
  }
205
194
  // Show delay if feature is hovered or if delay is above 5mins.
206
195
  if (isDisplayStrokeAndDelay &&
207
196
  (hover || delay >= delayDisplay || cancelled)) {
208
197
  // Draw delay text
209
- var fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
210
- var text = getDelayText(delay, cancelled);
198
+ const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
199
+ const text = getDelayText(delay, cancelled);
211
200
  if (text) {
212
- var textWidth = text.length * fontSize;
213
- var delayText = (0, exports.getDelayTextCanvas)(textWidth, text, fontSize, "bold ".concat(fontSize, "px arial, sans-serif"), getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
214
- ctx.drawImage(delayText, origin_1 + radiusDelay + margin, origin_1 - fontSize);
201
+ const textWidth = text.length * fontSize;
202
+ const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
203
+ ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
215
204
  }
216
205
  }
217
206
  // Draw colored circle with black border
218
- var circleFillColor = void 0;
207
+ let circleFillColor;
219
208
  if (useDelayStyle) {
220
209
  circleFillColor = getDelayColor(delay, cancelled);
221
210
  }
222
211
  else {
223
212
  circleFillColor = color || getBgColor(type);
224
213
  }
225
- var hasStroke = isDisplayStrokeAndDelay || hover || selected;
226
- var hasDash = isDisplayStrokeAndDelay &&
214
+ const hasStroke = isDisplayStrokeAndDelay || hover || selected;
215
+ const hasDash = isDisplayStrokeAndDelay &&
227
216
  useDelayStyle &&
228
217
  delay === null &&
229
218
  operatorProvidesRealtime === 'yes';
230
- var circle = (0, exports.getCircleCanvas)(origin_1, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
219
+ const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
231
220
  ctx.drawImage(circle, 0, 0);
232
221
  // Draw text in the circle
233
222
  if (mustDrawText) {
234
- var fontSize = Math.max(radius, 10);
235
- var textSize = getTextSize(ctx, markerSize, name, fontSize);
236
- var textColor2 = !useDelayStyle
223
+ const fontSize = Math.max(radius, 10);
224
+ const textSize = getTextSize(ctx, markerSize, name, fontSize);
225
+ const textColor2 = !useDelayStyle
237
226
  ? textColor || getTextColor(type)
238
227
  : '#000000';
239
- var hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
240
- var text = (0, exports.getTextCanvas)(name, origin_1, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
228
+ const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
229
+ const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
241
230
  ctx.drawImage(text, 0, 0);
242
231
  }
243
232
  cache[key] = canvas;
@@ -245,4 +234,4 @@ var realtimeDefaultStyle = function (trajectory, viewState, options) {
245
234
  }
246
235
  return cache[key];
247
236
  };
248
- exports.default = realtimeDefaultStyle;
237
+ export default realtimeDefaultStyle;
@@ -1,17 +1,4 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
1
+ import realtimeDefaultStyle from './realtimeDefaultStyle';
15
2
  /**
16
3
  * A tracker style that display the delay as backgroundColor.
17
4
  *
@@ -20,7 +7,7 @@ var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
20
7
  * @param {*} options Some options to change the rendering
21
8
  * @return a canvas
22
9
  */
23
- var realtimeDelayStyle = function (trajectory, viewState, options) {
24
- return (0, realtimeDefaultStyle_1.default)(trajectory, viewState, __assign(__assign({}, options), { useDelayStyle: true }));
10
+ const realtimeDelayStyle = (trajectory, viewState, options) => {
11
+ return realtimeDefaultStyle(trajectory, viewState, Object.assign(Object.assign({}, options), { useDelayStyle: true }));
25
12
  };
26
- exports.default = realtimeDelayStyle;
13
+ export default realtimeDelayStyle;
@@ -1,16 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * A very simple tracker style.
5
3
  * Display blue point for each train.
6
4
  */
7
- var canvas;
8
- var realtimeSimpleStyle = function () {
5
+ let canvas;
6
+ const realtimeSimpleStyle = () => {
9
7
  if (!canvas) {
10
- document.createElement('canvas');
8
+ canvas = document.createElement('canvas');
11
9
  canvas.width = 15;
12
10
  canvas.height = 15;
13
- var ctx = canvas.getContext('2d');
11
+ const ctx = canvas.getContext('2d');
14
12
  ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
15
13
  ctx.fillStyle = '#8ED6FF';
16
14
  ctx.fill();
@@ -21,4 +19,4 @@ var realtimeSimpleStyle = function () {
21
19
  }
22
20
  return canvas;
23
21
  };
24
- exports.default = realtimeSimpleStyle;
22
+ export default realtimeSimpleStyle;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * @typedef {function} FilterFunction
3
4
  * @param {Object} vehicle Vehicle to filter.
@@ -1,14 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * Remove the delay from arrivalTime and departureTime
5
3
  * @private
6
4
  */
7
- var cleanStopTime = function (content) {
5
+ const cleanStopTime = (content) => {
8
6
  if (!content) {
9
7
  return;
10
8
  }
11
- content.stations.forEach(function (station) {
9
+ content.stations.forEach((station) => {
12
10
  // eslint-disable-next-line no-param-reassign
13
11
  station.arrivalTimeWithDelay = station.arrivalTime;
14
12
  if (station.departureTime) {
@@ -27,4 +25,4 @@ var cleanStopTime = function (content) {
27
25
  // eslint-disable-next-line consistent-return
28
26
  return content;
29
27
  };
30
- exports.default = cleanStopTime;
28
+ export default cleanStopTime;
@@ -5,5 +5,5 @@ export default compareDepartures;
5
5
  * @param {Object} b Second departure.
6
6
  * @private
7
7
  */
8
- declare function compareDepartures(a: any, b: any, sortByMinArrivalTime?: boolean): number;
8
+ declare function compareDepartures(a: Object, b: Object, sortByMinArrivalTime?: boolean): number;
9
9
  //# sourceMappingURL=compareDepartures.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compareDepartures.d.ts","sourceRoot":"","sources":["../../../src/common/utils/compareDepartures.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,2FA8BC"}
1
+ {"version":3,"file":"compareDepartures.d.ts","sourceRoot":"","sources":["../../../src/common/utils/compareDepartures.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,sCAJW,MAAM,KACN,MAAM,0CAiChB"}
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * Compare two given departures for sort alogithm,
5
3
  * @param {Object} a First departure.
6
4
  * @param {Object} b Second departure.
7
5
  * @private
8
6
  */
9
- var compareDepartures = function (a, b, sortByMinArrivalTime) {
10
- if (sortByMinArrivalTime === void 0) { sortByMinArrivalTime = false; }
7
+ const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
11
8
  // First LEAVING and HIDDEN, then BOARDING and then sorted by time.
12
- var topStates = ['HIDDEN', 'LEAVING', 'BOARDING'];
13
- var aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
14
- var bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
9
+ const topStates = ['HIDDEN', 'LEAVING', 'BOARDING'];
10
+ const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
11
+ const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
15
12
  if (aTop || bTop) {
16
13
  if (aTop !== bTop) {
17
14
  return aTop ? -1 : 1;
@@ -21,9 +18,9 @@ var compareDepartures = function (a, b, sortByMinArrivalTime) {
21
18
  return topStates.indexOf(a.state) - topStates.indexOf(b.state);
22
19
  }
23
20
  }
24
- var aDuration = null;
25
- var bDuration = null;
26
- var now = Date.now();
21
+ let aDuration = null;
22
+ let bDuration = null;
23
+ const now = Date.now();
27
24
  if (sortByMinArrivalTime) {
28
25
  aDuration = new Date(a.min_arrival_time || a.time).getTime() - now;
29
26
  bDuration = new Date(b.min_arrival_time || b.time).getTime() - now;
@@ -34,4 +31,4 @@ var compareDepartures = function (a, b, sortByMinArrivalTime) {
34
31
  }
35
32
  return aDuration - bDuration;
36
33
  };
37
- exports.default = compareDepartures;
34
+ export default compareDepartures;
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * This function try to create a canvas element and return it.
5
3
  * it uses document.createElement('canvas') if document is available
6
4
  * or new OffscreenCanvas(width, height) if OffscreenCanvas is avalaible (for web worker)
7
5
  * or it returns null if neither is available.
8
6
  */
9
- var createCanvas = function (width, height) {
10
- var canvas = null;
7
+ const createCanvas = (width, height) => {
8
+ let canvas = null;
11
9
  // Prevent SSR errors
12
10
  if (typeof window === 'undefined') {
13
11
  return null;
@@ -26,4 +24,4 @@ var createCanvas = function (width, height) {
26
24
  }
27
25
  return canvas;
28
26
  };
29
- exports.default = createCanvas;
27
+ export default createCanvas;
@@ -8,5 +8,5 @@ export default createFilters;
8
8
  * @param {Regexp} regexLine - A regex aplly of vehcile's name.
9
9
  * @private
10
10
  */
11
- declare function createFilters(line: string | Array<string>, route: string | Array<string>, operator: string | Array<string>, regexLine: Regexp): (t: any) => boolean;
11
+ declare function createFilters(line: string | Array<string>, route: string | Array<string>, operator: string | Array<string>, regexLine: Regexp): ((t: any) => boolean) | null;
12
12
  //# sourceMappingURL=createTrackerFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTrackerFilters.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,qCANW,MAAM,GAAC,MAAM,MAAM,CAAC,SACpB,MAAM,GAAC,MAAM,MAAM,CAAA,YACnB,MAAM,GAAC,MAAM,MAAM,CAAA,0CA+E7B"}
1
+ {"version":3,"file":"createTrackerFilters.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,qCANW,MAAM,GAAC,MAAM,MAAM,CAAC,SACpB,MAAM,GAAC,MAAM,MAAM,CAAA,YACnB,MAAM,GAAC,MAAM,MAAM,CAAA,mDA+E7B"}
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * Return a filter functions based on some parameters of a vehicle.
5
3
  *
@@ -9,64 +7,56 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
7
  * @param {Regexp} regexLine - A regex aplly of vehcile's name.
10
8
  * @private
11
9
  */
12
- var createFilters = function (line, route, operator, regexLine) {
13
- var filterList = [];
10
+ const createFilters = (line, route, operator, regexLine) => {
11
+ const filterList = [];
14
12
  if (!line && !route && !operator && !regexLine) {
15
13
  return null;
16
14
  }
17
15
  if (regexLine) {
18
- var regexLineList_1 = typeof regexLine === 'string' ? [regexLine] : regexLine;
19
- var lineFilter = function (item) {
20
- var name = item.properties.name ||
16
+ const regexLineList = typeof regexLine === 'string' ? [regexLine] : regexLine;
17
+ const lineFilter = (item) => {
18
+ const name = item.properties.name ||
21
19
  (item.properties.line && item.properties.line.name) ||
22
20
  '';
23
21
  if (!name) {
24
22
  return false;
25
23
  }
26
- return regexLineList_1.some(function (regexStr) {
27
- return new RegExp(regexStr, 'i').test(name);
28
- });
24
+ return regexLineList.some((regexStr) => new RegExp(regexStr, 'i').test(name));
29
25
  };
30
26
  filterList.push(lineFilter);
31
27
  }
32
28
  if (line) {
33
- var lineFiltersList = typeof line === 'string' ? line.split(',') : line;
34
- var lineList_1 = lineFiltersList.map(function (l) {
35
- return l.replace(/\s+/g, '').toUpperCase();
36
- });
37
- var lineFilter = function (item) {
38
- var _a = item.properties, linee = _a.line, name = _a.name;
39
- var lineName = (name || (linee && linee.name) || '').toUpperCase();
29
+ const lineFiltersList = typeof line === 'string' ? line.split(',') : line;
30
+ const lineList = lineFiltersList.map((l) => l.replace(/\s+/g, '').toUpperCase());
31
+ const lineFilter = (item) => {
32
+ const { line: linee, name } = item.properties;
33
+ const lineName = (name || (linee && linee.name) || '').toUpperCase();
40
34
  if (!lineName) {
41
35
  return false;
42
36
  }
43
- return lineList_1.includes(lineName);
37
+ return lineList.includes(lineName);
44
38
  };
45
39
  filterList.push(lineFilter);
46
40
  }
47
41
  if (route) {
48
- var routes = typeof route === 'string' ? route.split(',') : route;
49
- var routeList_1 = routes.map(function (item) { return parseInt(item, 10); });
50
- var routeFilter = function (item) {
51
- var routeId = parseInt(item.properties.routeIdentifier.split('.')[0], 10);
52
- return routeList_1.includes(routeId);
42
+ const routes = typeof route === 'string' ? route.split(',') : route;
43
+ const routeList = routes.map((item) => parseInt(item, 10));
44
+ const routeFilter = (item) => {
45
+ const routeId = parseInt(item.properties.routeIdentifier.split('.')[0], 10);
46
+ return routeList.includes(routeId);
53
47
  };
54
48
  filterList.push(routeFilter);
55
49
  }
56
50
  if (operator) {
57
- var operatorList_1 = typeof operator === 'string' ? [operator] : operator;
58
- var operatorFilter = function (item) {
59
- return operatorList_1.some(function (op) {
60
- return new RegExp(op, 'i').test(item.properties.operator);
61
- });
62
- };
51
+ const operatorList = typeof operator === 'string' ? [operator] : operator;
52
+ const operatorFilter = (item) => operatorList.some((op) => new RegExp(op, 'i').test(item.properties.operator));
63
53
  filterList.push(operatorFilter);
64
54
  }
65
55
  if (!filterList.length) {
66
56
  return null;
67
57
  }
68
- return function (t) {
69
- for (var i = 0; i < filterList.length; i += 1) {
58
+ return (t) => {
59
+ for (let i = 0; i < filterList.length; i += 1) {
70
60
  if (!filterList[i](t)) {
71
61
  return false;
72
62
  }
@@ -74,4 +64,4 @@ var createFilters = function (line, route, operator, regexLine) {
74
64
  return true;
75
65
  };
76
66
  };
77
- exports.default = createFilters;
67
+ export default createFilters;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=createTrackerFilters.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTrackerFilters.test.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.test.js"],"names":[],"mappings":""}