mobility-toolbox-js 2.0.0-beta.3 → 2.0.0-beta.33

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 (220) hide show
  1. package/README.md +4 -1
  2. package/api/RealtimeAPI.d.ts +268 -0
  3. package/api/RealtimeAPI.d.ts.map +1 -0
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/StopsAPI.d.ts +36 -0
  7. package/api/StopsAPI.d.ts.map +1 -0
  8. package/api/index.d.ts +5 -0
  9. package/api/index.d.ts.map +1 -0
  10. package/api/typedefs.d.ts +105 -0
  11. package/api/typedefs.d.ts.map +1 -0
  12. package/common/api/HttpAPI.d.ts +31 -0
  13. package/common/api/HttpAPI.d.ts.map +1 -0
  14. package/common/api/WebSocketAPI.d.ts +95 -0
  15. package/common/api/WebSocketAPI.d.ts.map +1 -0
  16. package/common/controls/Control.d.ts +74 -0
  17. package/common/controls/Control.d.ts.map +1 -0
  18. package/common/index.d.ts +3 -0
  19. package/common/index.d.ts.map +1 -0
  20. package/common/layers/Layer.d.ts +80 -0
  21. package/common/layers/Layer.d.ts.map +1 -0
  22. package/common/mixins/CopyrightMixin.d.ts +22 -0
  23. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  24. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  25. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  26. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  27. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  28. package/common/mixins/StopFinderMixin.d.ts +40 -0
  29. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  30. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  31. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  32. package/common/styles/index.d.ts +5 -0
  33. package/common/styles/index.d.ts.map +1 -0
  34. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  35. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  36. package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +3 -9
  37. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  38. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  39. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  40. package/common/typedefs.d.ts +50 -0
  41. package/common/typedefs.d.ts.map +1 -0
  42. package/common/utils/cleanStopTime.d.ts +7 -0
  43. package/common/utils/cleanStopTime.d.ts.map +1 -0
  44. package/common/utils/compareDepartures.d.ts +9 -0
  45. package/common/utils/compareDepartures.d.ts.map +1 -0
  46. package/common/utils/createCanvas.d.ts +9 -0
  47. package/common/utils/createCanvas.d.ts.map +1 -0
  48. package/common/utils/createTrackerFilters.d.ts +12 -0
  49. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  50. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  51. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  52. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  53. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  54. package/common/utils/getMapboxRender.d.ts +5 -0
  55. package/common/utils/getMapboxRender.d.ts.map +1 -0
  56. package/common/utils/getMaplibreRender.d.ts +5 -0
  57. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  58. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  59. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  60. package/common/utils/getUrlWithParams.d.ts +9 -0
  61. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  62. package/common/utils/getVehiclePosition.d.ts +14 -0
  63. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  64. package/common/utils/index.d.ts +12 -0
  65. package/common/utils/index.d.ts.map +1 -0
  66. package/common/utils/removeDuplicate.d.ts +10 -0
  67. package/common/utils/removeDuplicate.d.ts.map +1 -0
  68. package/common/utils/renderTrajectories.d.ts +20 -0
  69. package/common/utils/renderTrajectories.d.ts.map +1 -0
  70. package/common/utils/sortByDelay.d.ts +3 -0
  71. package/common/utils/sortByDelay.d.ts.map +1 -0
  72. package/common/utils/timeUtils.d.ts +5 -0
  73. package/common/utils/timeUtils.d.ts.map +1 -0
  74. package/common/utils/trackerConfig.d.ts +24 -0
  75. package/common/utils/trackerConfig.d.ts.map +1 -0
  76. package/iife.d.ts +3 -0
  77. package/iife.d.ts.map +1 -0
  78. package/index.d.ts +6 -0
  79. package/index.d.ts.map +1 -0
  80. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  81. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  82. package/mapbox/controls/index.d.ts +2 -0
  83. package/mapbox/controls/index.d.ts.map +1 -0
  84. package/mapbox/index.d.ts +5 -0
  85. package/mapbox/index.d.ts.map +1 -0
  86. package/mapbox/layers/Layer.d.ts +47 -0
  87. package/mapbox/layers/Layer.d.ts.map +1 -0
  88. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  89. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  90. package/mapbox/layers/index.d.ts +3 -0
  91. package/mapbox/layers/index.d.ts.map +1 -0
  92. package/mapbox/utils.d.ts +8 -0
  93. package/mapbox/utils.d.ts.map +1 -0
  94. package/mbt.js +50042 -0
  95. package/mbt.js.map +7 -0
  96. package/mbt.min.js +1008 -0
  97. package/mbt.min.js.map +7 -0
  98. package/ol/controls/CopyrightControl.d.ts +31 -0
  99. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  100. package/ol/controls/RoutingControl.d.ts +180 -0
  101. package/ol/controls/RoutingControl.d.ts.map +1 -0
  102. package/ol/controls/StopFinderControl.d.ts +32 -0
  103. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  104. package/ol/controls/index.d.ts +4 -0
  105. package/ol/controls/index.d.ts.map +1 -0
  106. package/ol/index.d.ts +6 -0
  107. package/ol/index.d.ts.map +1 -0
  108. package/ol/layers/Layer.d.ts +49 -0
  109. package/ol/layers/Layer.d.ts.map +1 -0
  110. package/ol/layers/MapboxLayer.d.ts +42 -0
  111. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  112. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  113. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  114. package/ol/layers/MaplibreLayer.d.ts +27 -0
  115. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  116. package/ol/layers/RealtimeLayer.d.ts +119 -0
  117. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  118. package/ol/layers/RoutingLayer.d.ts +24 -0
  119. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  120. package/ol/layers/VectorLayer.d.ts +23 -0
  121. package/ol/layers/VectorLayer.d.ts.map +1 -0
  122. package/ol/layers/WMSLayer.d.ts +38 -0
  123. package/ol/layers/WMSLayer.d.ts.map +1 -0
  124. package/ol/layers/index.d.ts +9 -0
  125. package/ol/layers/index.d.ts.map +1 -0
  126. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  127. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  128. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  129. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  130. package/ol/styles/index.d.ts +3 -0
  131. package/ol/styles/index.d.ts.map +1 -0
  132. package/package.json +56 -95
  133. package/setupTests.d.ts +2 -0
  134. package/setupTests.d.ts.map +1 -0
  135. package/types/index.d.ts +10 -0
  136. package/types/realtime.d.ts +24 -0
  137. package/types/routing.d.ts +206 -0
  138. package/types/stops.d.ts +143 -0
  139. package/api/index.js +0 -3
  140. package/api/routing/RoutingAPI.js +0 -44
  141. package/api/routing/RoutingAPI.test.js +0 -41
  142. package/api/stops/StopsAPI.js +0 -41
  143. package/api/stops/StopsAPI.test.js +0 -34
  144. package/api/tralis/TralisAPI.js +0 -731
  145. package/api/tralis/TralisAPI.test.js +0 -75
  146. package/api/tralis/TralisAPIUtils.js +0 -73
  147. package/api/tralis/WebSocketConnector.js +0 -338
  148. package/api/tralis/WebSocketConnector.test.js +0 -356
  149. package/api/tralis/typedefs.js +0 -81
  150. package/common/Tracker.js +0 -197
  151. package/common/api/api.js +0 -64
  152. package/common/api/api.test.js +0 -68
  153. package/common/controls/Control.js +0 -146
  154. package/common/controls/Control.test.js +0 -98
  155. package/common/layers/Layer.js +0 -404
  156. package/common/layers/Layer.test.js +0 -585
  157. package/common/mixins/CopyrightMixin.js +0 -48
  158. package/common/mixins/SearchMixin.js +0 -176
  159. package/common/mixins/TralisLayerMixin.js +0 -930
  160. package/common/styles/index.js +0 -4
  161. package/common/styles/trackerDefaultStyle.js +0 -333
  162. package/common/styles/trackerSimpleStyle.js +0 -22
  163. package/common/trackerConfig.js +0 -190
  164. package/common/trackerConfig.test.js +0 -25
  165. package/common/typedefs.js +0 -23
  166. package/common/utils/createTrackerFilters.js +0 -87
  167. package/common/utils/createTrackerFilters.test.js +0 -95
  168. package/common/utils/getMapboxMapCopyrights.js +0 -32
  169. package/common/utils/getMapboxMapCopyrights.test.js +0 -47
  170. package/common/utils/getMapboxStyleUrl.js +0 -32
  171. package/common/utils/getVehiclePosition.js +0 -72
  172. package/common/utils/index.js +0 -6
  173. package/common/utils/removeDuplicate.js +0 -22
  174. package/common/utils/removeDuplicate.test.js +0 -22
  175. package/common/utils/sortByDelay.js +0 -23
  176. package/common/utils/timeUtils.js +0 -44
  177. package/common/utils/timeUtils.test.js +0 -16
  178. package/index.js +0 -2
  179. package/index.js.map +0 -1
  180. package/mapbox/controls/CopyrightControl.js +0 -58
  181. package/mapbox/index.js +0 -3
  182. package/mapbox/layers/Layer.js +0 -118
  183. package/mapbox/layers/Layer.test.js +0 -202
  184. package/mapbox/layers/TralisLayer.js +0 -329
  185. package/mapbox/layers/TralisLayer.test.js +0 -40
  186. package/mapbox/utils.js +0 -46
  187. package/module.js +0 -23
  188. package/ol/README.md +0 -0
  189. package/ol/controls/CopyrightControl.js +0 -80
  190. package/ol/controls/CopyrightControl.test.js +0 -211
  191. package/ol/controls/RoutingControl.js +0 -752
  192. package/ol/controls/RoutingControl.test.js +0 -216
  193. package/ol/controls/StopFinderControl.js +0 -38
  194. package/ol/controls/StopFinderControl.test.js +0 -59
  195. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  196. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  197. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  198. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  199. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  200. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  201. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  202. package/ol/index.js +0 -13
  203. package/ol/layers/Layer.js +0 -193
  204. package/ol/layers/Layer.test.js +0 -197
  205. package/ol/layers/MapboxLayer.js +0 -378
  206. package/ol/layers/MapboxLayer.test.js +0 -186
  207. package/ol/layers/MapboxStyleLayer.js +0 -417
  208. package/ol/layers/MapboxStyleLayer.test.js +0 -262
  209. package/ol/layers/MaplibreLayer.js +0 -280
  210. package/ol/layers/RoutingLayer.js +0 -91
  211. package/ol/layers/RoutingLayer.test.js +0 -49
  212. package/ol/layers/TralisLayer.js +0 -359
  213. package/ol/layers/TralisLayer.test.js +0 -97
  214. package/ol/layers/VectorLayer.js +0 -43
  215. package/ol/layers/VectorLayer.test.js +0 -98
  216. package/ol/layers/WMSLayer.js +0 -80
  217. package/ol/layers/WMSLayer.test.js +0 -84
  218. package/ol/styles/fullTrajectoryDelayStyle.js +0 -35
  219. package/ol/styles/fullTrajectoryStyle.js +0 -51
  220. package/ol/styles/index.js +0 -2
@@ -1,4 +0,0 @@
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,333 +0,0 @@
1
- import {
2
- getRadius,
3
- getBgColor,
4
- getDelayColor,
5
- getDelayText,
6
- getTextColor,
7
- getTextSize,
8
- } from '../trackerConfig';
9
-
10
- const createCanvas = (width, height) => {
11
- const canvas = document.createElement('canvas');
12
- canvas.width = width;
13
- canvas.height = height;
14
- return canvas;
15
- };
16
-
17
- // Draw circle delay background
18
- const cacheDelayBg = {};
19
- export const getDelayBgCanvas = (origin, radius, color) => {
20
- const key = `${origin}, ${radius}, ${color}`;
21
- if (!cacheDelayBg[key]) {
22
- const canvas = createCanvas(origin * 2, origin * 2);
23
- const ctx = canvas.getContext('2d');
24
- ctx.beginPath();
25
- ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
26
- ctx.fillStyle = color;
27
- ctx.filter = 'blur(1px)';
28
- ctx.fill();
29
- cacheDelayBg[key] = canvas;
30
- }
31
- return cacheDelayBg[key];
32
- };
33
-
34
- // Draw delay text
35
- const cacheDelayText = {};
36
- export const getDelayTextCanvas = (
37
- width,
38
- text,
39
- fontSize,
40
- font,
41
- delayColor,
42
- delayOutlineColor,
43
- pixelRatio,
44
- ) => {
45
- const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
46
- if (!cacheDelayText[key]) {
47
- const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
48
- const ctx = canvas.getContext('2d');
49
- ctx.textAlign = 'left';
50
- ctx.textBaseline = 'middle';
51
- ctx.font = font;
52
- ctx.fillStyle = delayColor;
53
- ctx.strokeStyle = delayOutlineColor;
54
- ctx.lineWidth = 1.5 * pixelRatio;
55
- const delayText = text;
56
- ctx.strokeText(delayText, 0, fontSize);
57
- ctx.fillText(delayText, 0, fontSize);
58
- cacheDelayText[key] = canvas;
59
- }
60
- return cacheDelayText[key];
61
- };
62
-
63
- // Draw colored circle with black border
64
- const cacheCircle = {};
65
- export const getCircleCanvas = (
66
- origin,
67
- radius,
68
- color,
69
- hasStroke,
70
- hasDash,
71
- pixelRatio,
72
- ) => {
73
- const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
74
- if (!cacheCircle[key]) {
75
- const canvas = createCanvas(origin * 2, origin * 2);
76
- const ctx = canvas.getContext('2d');
77
- ctx.fillStyle = color;
78
-
79
- if (hasStroke) {
80
- ctx.lineWidth = 1 * pixelRatio;
81
- ctx.strokeStyle = '#000000';
82
- }
83
-
84
- ctx.beginPath();
85
- ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
86
- ctx.fill();
87
-
88
- if (hasDash) {
89
- ctx.setLineDash([5, 3]);
90
- }
91
-
92
- if (hasStroke) {
93
- ctx.stroke();
94
- }
95
-
96
- cacheCircle[key] = canvas;
97
- }
98
- return cacheCircle[key];
99
- };
100
-
101
- // Draw text in the circle
102
- const cacheText = {};
103
- export const getTextCanvas = (
104
- text,
105
- origin,
106
- textSize,
107
- fillColor,
108
- strokeColor,
109
- hasStroke,
110
- pixelRatio,
111
- ) => {
112
- const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
113
- if (!cacheText[key]) {
114
- 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.
118
- if (hasStroke) {
119
- ctx.save();
120
- ctx.textBaseline = 'middle';
121
- ctx.textAlign = 'center';
122
- ctx.font = `bold ${textSize + 2}px Arial`;
123
- ctx.strokeStyle = strokeColor;
124
- ctx.strokeText(text, origin, origin);
125
- ctx.restore();
126
- }
127
-
128
- // Draw a text
129
- ctx.textBaseline = 'middle';
130
- ctx.textAlign = 'center';
131
- ctx.fillStyle = fillColor;
132
- ctx.font = `bold ${textSize}px Arial`;
133
- ctx.strokeStyle = strokeColor;
134
- ctx.strokeText(text, origin, origin);
135
- ctx.fillText(text, origin, origin);
136
-
137
- cacheText[key] = canvas;
138
- }
139
- return cacheText[key];
140
- };
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
- const styleCache = {};
151
- const style = (trajectory, viewState, options) => {
152
- const {
153
- hoverVehicleId,
154
- selectedVehicleId,
155
- useDelayStyle,
156
- delayOutlineColor,
157
- delayDisplay,
158
- } = options;
159
-
160
- const { zoom, pixelRatio } = viewState;
161
- let { line, type } = trajectory.properties;
162
- const {
163
- train_id: id,
164
- delay,
165
- cancelled = false,
166
- operator_provides_realtime_journey: operatorProvidesRealtime,
167
- } = trajectory.properties;
168
-
169
- if (!type) {
170
- type = 'Rail';
171
- }
172
-
173
- if (!line) {
174
- line = {};
175
- }
176
-
177
- let { name, text_color: textColor, color } = line;
178
-
179
- if (!name) {
180
- name = 'I';
181
- }
182
-
183
- if (!textColor) {
184
- textColor = '#000000';
185
- }
186
-
187
- if (color && color[0] !== '#') {
188
- color = `#${color}`;
189
- }
190
-
191
- if (textColor[0] !== '#') {
192
- textColor = `#${textColor}`;
193
- }
194
-
195
- const z = Math.min(Math.floor(zoom || 1), 16);
196
- const hover = hoverVehicleId && hoverVehicleId === id;
197
- const selected = selectedVehicleId && selectedVehicleId === id;
198
-
199
- // Calcul the radius of the circle
200
- let radius = getRadius(type, z) * pixelRatio;
201
- const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
202
- if (hover || selected) {
203
- radius = isDisplayStrokeAndDelay
204
- ? radius + 5 * pixelRatio
205
- : 14 * pixelRatio;
206
- }
207
- const mustDrawText = radius > 10 * pixelRatio;
208
-
209
- // Optimize the cache key, very important in high zoom level
210
- let key = `${radius}${type}${color}${hover}${selected}${cancelled}${delay}`;
211
-
212
- if (useDelayStyle) {
213
- key += `${operatorProvidesRealtime}`;
214
- }
215
-
216
- if (mustDrawText) {
217
- key += `${name}${textColor}`;
218
- }
219
-
220
- if (!styleCache[key]) {
221
- if (radius === 0) {
222
- styleCache[key] = null;
223
- return null;
224
- }
225
-
226
- const margin = 1 * pixelRatio;
227
- const radiusDelay = radius + 2;
228
- const markerSize = radius * 2;
229
- const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio; // add space for delay information
230
- const origin = size / 2;
231
-
232
- // Create the canvas
233
- const canvas = createCanvas(size, size);
234
- const ctx = canvas.getContext('2d');
235
-
236
- if (isDisplayStrokeAndDelay && delay !== null) {
237
- // Draw circle delay background
238
- const delayBg = getDelayBgCanvas(
239
- origin,
240
- radiusDelay,
241
- getDelayColor(delay, cancelled),
242
- );
243
- ctx.drawImage(delayBg, 0, 0);
244
- }
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;
257
- const text = getDelayText(delay, cancelled);
258
-
259
- if (text) {
260
- 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
- );
275
- }
276
- }
277
-
278
- // Draw colored circle with black border
279
- let circleFillColor;
280
- if (useDelayStyle) {
281
- circleFillColor = getDelayColor(delay, cancelled);
282
- } else {
283
- circleFillColor = color || getBgColor(type);
284
- }
285
-
286
- 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
-
303
- ctx.drawImage(circle, 0, 0);
304
-
305
- // Draw text in the circle
306
- if (mustDrawText) {
307
- const fontSize = Math.max(radius, 10);
308
- 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
-
325
- ctx.drawImage(text, 0, 0);
326
- }
327
-
328
- styleCache[key] = canvas;
329
- }
330
-
331
- return styleCache[key];
332
- };
333
- export default style;
@@ -1,22 +0,0 @@
1
- /**
2
- * A very simple tracker style.
3
- * Display blue point for each train.
4
- */
5
- let canvas;
6
- const style = () => {
7
- if (!canvas) {
8
- document.createElement('canvas');
9
- canvas.width = 15;
10
- canvas.height = 15;
11
- const ctx = canvas.getContext('2d');
12
- ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
13
- ctx.fillStyle = '#8ED6FF';
14
- ctx.fill();
15
- ctx.lineWidth = 3;
16
- ctx.strokeStyle = 'black';
17
- ctx.stroke();
18
- ctx.lineWidth = 3;
19
- }
20
- return canvas;
21
- };
22
- export default style;
@@ -1,190 +0,0 @@
1
- const trackerRadiusMapping = {
2
- 0: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
3
- 1: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
4
- 2: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15],
5
- 3: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
6
- 4: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
7
- 5: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
8
- 6: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
9
- 7: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
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],
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
- export const types = [
22
- /^Tram/i,
23
- /^Subway( \/ Metro \/ S-Bahn)?/i,
24
- /^Train/i,
25
- /^Bus/i,
26
- /^Ferry/i,
27
- /^Cable ?Car/i,
28
- /^Gondola/i,
29
- /^Funicular/i,
30
- /^(Long distance bus|coach)/i,
31
- /^Rail/i, // New endpoint use Rail instead of Train.
32
- ];
33
-
34
- /**
35
- * @ignore
36
- */
37
- export const bgColors = [
38
- '#ffb400',
39
- '#ff5400',
40
- '#ff8080',
41
- '#ea0000',
42
- '#3000ff',
43
- '#ffb400',
44
- '#41a27b',
45
- '#00d237',
46
- '#b5b5b5',
47
- '#ff8080',
48
- ];
49
-
50
- /**
51
- * @ignore
52
- */
53
- export const textColors = [
54
- '#000000',
55
- '#ffffff',
56
- '#000000',
57
- '#ffffff',
58
- '#ffffff',
59
- '#000000',
60
- '#ffffff',
61
- '#000000',
62
- '#000000',
63
- '#000000',
64
- ];
65
-
66
- /**
67
- * @ignore
68
- */
69
- 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,
72
- ];
73
-
74
- /**
75
- * @ignore
76
- */
77
- export const getTypeIndex = (type) => {
78
- if (typeof type === 'string') {
79
- return types.findIndex((t) => t.test(type));
80
- }
81
- return type;
82
- };
83
-
84
- /**
85
- * @ignore
86
- */
87
- export const getRadius = (type, zoom) => {
88
- try {
89
- const typeIdx = getTypeIndex(type || 0);
90
- return trackerRadiusMapping[typeIdx][zoom];
91
- } catch (e) {
92
- return 1;
93
- }
94
- };
95
-
96
- /**
97
- * @ignore
98
- */
99
- export const getBgColor = (type = 0) => {
100
- try {
101
- const typeIdx = getTypeIndex(type);
102
- return bgColors[typeIdx];
103
- } catch (e) {
104
- return 1;
105
- }
106
- };
107
-
108
- /**
109
- * @ignore
110
- */
111
- export const getTextColor = (type = 0) => {
112
- try {
113
- const typeIdx = getTypeIndex(type);
114
- return textColors[typeIdx];
115
- } catch (e) {
116
- return 1;
117
- }
118
- };
119
-
120
- /**
121
- * @ignore
122
- */
123
- export const getTextSize = (ctx, markerSize, text, fontSize) => {
124
- ctx.font = `bold ${fontSize}px Arial`;
125
- let newText = ctx.measureText(text);
126
-
127
- const maxiter = 25;
128
- let i = 0;
129
-
130
- while (newText.width > markerSize - 6 && i < maxiter) {
131
- // eslint-disable-next-line no-param-reassign
132
- fontSize -= 0.5;
133
- ctx.font = `bold ${fontSize}px arial, sans-serif`;
134
- newText = ctx.measureText(text);
135
- i += 1;
136
- }
137
- return fontSize;
138
- };
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
- export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
147
- if (cancelled) {
148
- return isDelayText ? '#ff0000' : '#a0a0a0'; // red or gray
149
- }
150
- if (delayInMs >= 3600000) {
151
- return '#ed004c'; // pink { r: 237, g: 0, b: 76, s: '237,0,76' };
152
- }
153
- if (delayInMs >= 500000) {
154
- return '#e80000'; // red { r: 232, g: 0, b: 0, s: '232,0,0' };
155
- }
156
- if (delayInMs >= 300000) {
157
- return '#ff4a00'; // orange { r: 255, g: 74, b: 0, s: '255,74,0' };
158
- }
159
- if (delayInMs >= 180000) {
160
- return '#f7bf00'; // yellow { r: 247, g: 191, b: 0, s: '247,191,0' };
161
- }
162
- if (delayInMs === null) {
163
- return '#a0a0a0'; // grey { r: 160, g: 160, b: 160, s: '160,160,160' };
164
- }
165
- return '#00a00c'; // green { r: 0, g: 160, b: 12, s: '0,160,12' };
166
- };
167
-
168
- /**
169
- * @ignore
170
- */
171
- export const getDelayText = (delayInMs, cancelled) => {
172
- if (cancelled) {
173
- return String.fromCodePoint(0x00d7);
174
- }
175
- if (delayInMs > 3600000) {
176
- const rounded = Math.round(delayInMs / 3600000);
177
- return `+${rounded}h`;
178
- }
179
-
180
- if (delayInMs > 59000) {
181
- const rounded = Math.round(delayInMs / 60000);
182
- return `+${rounded}m`;
183
- }
184
-
185
- if (delayInMs > 0) {
186
- return `+${delayInMs}s`;
187
- }
188
-
189
- return '';
190
- };
@@ -1,25 +0,0 @@
1
- import { getTypeIndex } from './trackerConfig';
2
-
3
- describe('trackerConfig', () => {
4
- describe('#getTypeIndex()', () => {
5
- test("retrurn the type is it's not a string", () => {
6
- const obj = { foo: 'foo' };
7
- expect(getTypeIndex(obj)).toBe(obj);
8
- expect(getTypeIndex(0)).toBe(0);
9
- expect(getTypeIndex(null)).toBe(null);
10
- expect(getTypeIndex(undefined)).toBe(undefined);
11
- });
12
-
13
- test('find good index for new tracker values', () => {
14
- expect(getTypeIndex('tram')).toBe(0);
15
- expect(getTypeIndex('subway')).toBe(1);
16
- expect(getTypeIndex('bus')).toBe(3);
17
- expect(getTypeIndex('ferry')).toBe(4);
18
- expect(getTypeIndex('cablecar')).toBe(5);
19
- expect(getTypeIndex('gondola')).toBe(6);
20
- expect(getTypeIndex('funicular')).toBe(7);
21
- expect(getTypeIndex('coach')).toBe(8);
22
- expect(getTypeIndex('rail')).toBe(9);
23
- });
24
- });
25
- });
@@ -1,23 +0,0 @@
1
- /**
2
- * @typedef {function} FilterFunction
3
- * @param {Object} vehicle Vehicle to filter.
4
- */
5
-
6
- /**
7
- * @typedef {Object} ViewState
8
- * @property {number} time A time in ms.
9
- * @property {number[2]} center A center in mercator coordinate.
10
- * @property {number[4]} extent An Extent in mercator coordinates.
11
- * @property {number[2]} size A size ([width, height]).
12
- * @property {number} rotation A rotation in radians.
13
- * @property {number} resolution A resolution.
14
- * @property {number} zoom A zoom level.
15
- * @property {number} pixelRatio A pixel ratio.
16
- */
17
-
18
- /**
19
- * @typedef {Object} FeatureInfo
20
- * @property {Layer} layer A layer.
21
- * @property {ol/Feature~Feature[]} features An array of features.
22
- * @property {number[2]} coordinate The coordinate where to find the featue.
23
- */
@@ -1,87 +0,0 @@
1
- /**
2
- * Return a filter functions based on some parameters of a vehicle.
3
- *
4
- * @param {string|Array<string>} line - A list of vehicle's name to filter. Names can be separated by a comma. Ex: 'S1,S2,S3'
5
- * @param {string|Array<string} route - A list of vehicle's route (contained in routeIdentifier property) to filter. Indentifiers can be separated by a comma. Ex: 'id1,id2,id3'
6
- * @param {string|Array<string} operator A list of vehicle's operator to filter. Operators can be separated by a comma. Ex: 'SBB,DB'
7
- * @param {Regexp} regexLine - A regex aplly of vehcile's name.
8
- * @private
9
- */
10
- const createFilters = (line, route, operator, regexLine) => {
11
- const filterList = [];
12
-
13
- if (!line && !route && !operator && !regexLine) {
14
- return null;
15
- }
16
-
17
- if (regexLine) {
18
- const regexLineList =
19
- typeof regexLine === 'string' ? [regexLine] : regexLine;
20
- const lineFilter = (item) => {
21
- const name =
22
- item.properties.name ||
23
- (item.properties.line && item.properties.line.name) ||
24
- '';
25
- if (!name) {
26
- return false;
27
- }
28
- return regexLineList.some((regexStr) =>
29
- new RegExp(regexStr, 'i').test(name),
30
- );
31
- };
32
- filterList.push(lineFilter);
33
- }
34
-
35
- if (line) {
36
- const lineFiltersList = typeof line === 'string' ? line.split(',') : line;
37
- const lineList = lineFiltersList.map((l) =>
38
- l.replace(/\s+/g, '').toUpperCase(),
39
- );
40
- const lineFilter = (item) => {
41
- const { line: linee, name } = item.properties;
42
- const lineName = (name || (linee && linee.name) || '').toUpperCase();
43
- if (!lineName) {
44
- return false;
45
- }
46
- return lineList.includes(lineName);
47
- };
48
- filterList.push(lineFilter);
49
- }
50
-
51
- if (route) {
52
- const routes = typeof route === 'string' ? route.split(',') : route;
53
- const routeList = routes.map((item) => parseInt(item, 10));
54
- const routeFilter = (item) => {
55
- const routeId = parseInt(
56
- item.properties.routeIdentifier.split('.')[0],
57
- 10,
58
- );
59
- return routeList.includes(routeId);
60
- };
61
- filterList.push(routeFilter);
62
- }
63
-
64
- if (operator) {
65
- const operatorList = typeof operator === 'string' ? [operator] : operator;
66
- const operatorFilter = (item) =>
67
- operatorList.some((op) =>
68
- new RegExp(op, 'i').test(item.properties.operator),
69
- );
70
- filterList.push(operatorFilter);
71
- }
72
-
73
- if (!filterList.length) {
74
- return null;
75
- }
76
-
77
- return (t) => {
78
- for (let i = 0; i < filterList.length; i += 1) {
79
- if (!filterList[i](t)) {
80
- return false;
81
- }
82
- }
83
- return true;
84
- };
85
- };
86
-
87
- export default createFilters;