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

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 (225) hide show
  1. package/api/RealtimeAPI.d.ts +268 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +626 -343
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +65 -15
  7. package/api/StopsAPI.d.ts +36 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +70 -12
  10. package/api/index.d.ts +5 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +10 -3
  13. package/api/typedefs.d.ts +105 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +72 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +82 -30
  19. package/common/api/WebSocketAPI.d.ts +95 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +313 -168
  22. package/common/controls/Control.d.ts +74 -0
  23. package/common/controls/Control.d.ts.map +1 -0
  24. package/common/controls/Control.js +167 -78
  25. package/common/index.d.ts +3 -0
  26. package/common/index.d.ts.map +1 -0
  27. package/common/index.js +18 -2
  28. package/common/layers/Layer.d.ts +80 -0
  29. package/common/layers/Layer.d.ts.map +1 -0
  30. package/common/layers/Layer.js +251 -134
  31. package/common/mixins/CopyrightMixin.d.ts +22 -0
  32. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  33. package/common/mixins/CopyrightMixin.js +70 -22
  34. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  35. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  36. package/common/mixins/MapboxLayerMixin.js +240 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +698 -429
  40. package/common/mixins/StopFinderMixin.d.ts +40 -0
  41. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  42. package/common/mixins/StopFinderMixin.js +195 -107
  43. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  44. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  45. package/common/mixins/UserInteractionsLayerMixin.js +222 -121
  46. package/common/styles/index.d.ts +5 -0
  47. package/common/styles/index.d.ts.map +1 -0
  48. package/common/styles/index.js +24 -4
  49. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  50. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDefaultStyle.js +236 -190
  52. package/common/styles/realtimeDelayStyle.d.ts +11 -0
  53. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeDelayStyle.js +25 -7
  55. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -17
  58. package/common/typedefs.d.ts +50 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +21 -0
  61. package/common/utils/cleanStopTime.d.ts +7 -0
  62. package/common/utils/cleanStopTime.d.ts.map +1 -0
  63. package/common/utils/cleanStopTime.js +28 -17
  64. package/common/utils/compareDepartures.d.ts +9 -0
  65. package/common/utils/compareDepartures.d.ts.map +1 -0
  66. package/common/utils/compareDepartures.js +34 -22
  67. package/common/utils/createCanvas.d.ts +9 -0
  68. package/common/utils/createCanvas.d.ts.map +1 -0
  69. package/common/utils/createCanvas.js +28 -16
  70. package/common/utils/createTrackerFilters.d.ts +12 -0
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  72. package/common/utils/createTrackerFilters.js +75 -54
  73. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  74. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  75. package/common/utils/getLayersAsFlatArray.js +15 -13
  76. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  77. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  78. package/common/utils/getMapboxMapCopyrights.js +24 -17
  79. package/common/utils/getMapboxRender.d.ts +5 -0
  80. package/common/utils/getMapboxRender.d.ts.map +1 -0
  81. package/common/utils/getMapboxRender.js +77 -0
  82. package/common/utils/getMaplibreRender.d.ts +5 -0
  83. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  84. package/common/utils/getMaplibreRender.js +38 -0
  85. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  86. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  87. package/common/utils/getRealtimeModeSuffix.js +11 -2
  88. package/common/utils/getUrlWithParams.d.ts +9 -0
  89. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  90. package/common/utils/getUrlWithParams.js +20 -10
  91. package/common/utils/getVehiclePosition.d.ts +14 -0
  92. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  93. package/common/utils/getVehiclePosition.js +63 -39
  94. package/common/utils/index.d.ts +12 -0
  95. package/common/utils/index.d.ts.map +1 -0
  96. package/common/utils/index.js +37 -9
  97. package/common/utils/removeDuplicate.d.ts +10 -0
  98. package/common/utils/removeDuplicate.d.ts.map +1 -0
  99. package/common/utils/removeDuplicate.js +29 -7
  100. package/common/utils/renderTrajectories.d.ts +20 -0
  101. package/common/utils/renderTrajectories.d.ts.map +1 -0
  102. package/common/utils/renderTrajectories.js +111 -78
  103. package/common/utils/sortByDelay.d.ts +3 -0
  104. package/common/utils/sortByDelay.d.ts.map +1 -0
  105. package/common/utils/sortByDelay.js +21 -17
  106. package/common/utils/timeUtils.d.ts +5 -0
  107. package/common/utils/timeUtils.d.ts.map +1 -0
  108. package/common/utils/timeUtils.js +47 -18
  109. package/common/utils/trackerConfig.d.ts +24 -0
  110. package/common/utils/trackerConfig.d.ts.map +1 -0
  111. package/common/utils/trackerConfig.js +171 -118
  112. package/iife.d.ts +3 -0
  113. package/iife.d.ts.map +1 -0
  114. package/iife.js +7 -0
  115. package/index.d.ts +6 -0
  116. package/index.d.ts.map +1 -0
  117. package/index.js +10 -7
  118. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  119. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  120. package/mapbox/controls/CopyrightControl.js +72 -28
  121. package/mapbox/controls/index.d.ts +2 -0
  122. package/mapbox/controls/index.d.ts.map +1 -0
  123. package/mapbox/controls/index.js +6 -1
  124. package/mapbox/index.d.ts +5 -0
  125. package/mapbox/index.d.ts.map +1 -0
  126. package/mapbox/index.js +20 -4
  127. package/mapbox/layers/Layer.d.ts +47 -0
  128. package/mapbox/layers/Layer.d.ts.map +1 -0
  129. package/mapbox/layers/Layer.js +137 -54
  130. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  131. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  132. package/mapbox/layers/RealtimeLayer.js +310 -183
  133. package/mapbox/layers/index.d.ts +3 -0
  134. package/mapbox/layers/index.d.ts.map +1 -0
  135. package/mapbox/layers/index.js +7 -2
  136. package/mapbox/utils.d.ts +8 -0
  137. package/mapbox/utils.d.ts.map +1 -0
  138. package/mapbox/utils.js +54 -29
  139. package/mbt.js +2052 -2109
  140. package/mbt.js.map +3 -3
  141. package/mbt.min.js +18 -18
  142. package/mbt.min.js.map +3 -3
  143. package/ol/controls/CopyrightControl.d.ts +31 -0
  144. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  145. package/ol/controls/CopyrightControl.js +89 -41
  146. package/ol/controls/RoutingControl.d.ts +180 -0
  147. package/ol/controls/RoutingControl.d.ts.map +1 -0
  148. package/ol/controls/RoutingControl.js +666 -371
  149. package/ol/controls/StopFinderControl.d.ts +32 -0
  150. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  151. package/ol/controls/StopFinderControl.js +59 -10
  152. package/ol/controls/index.d.ts +4 -0
  153. package/ol/controls/index.d.ts.map +1 -0
  154. package/ol/controls/index.js +9 -3
  155. package/ol/index.d.ts +6 -0
  156. package/ol/index.d.ts.map +1 -0
  157. package/ol/index.js +21 -5
  158. package/ol/layers/Layer.d.ts +49 -0
  159. package/ol/layers/Layer.d.ts.map +1 -0
  160. package/ol/layers/Layer.js +178 -81
  161. package/ol/layers/MapboxLayer.d.ts +42 -0
  162. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  163. package/ol/layers/MapboxLayer.js +131 -198
  164. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  165. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  166. package/ol/layers/MapboxStyleLayer.js +382 -186
  167. package/ol/layers/MaplibreLayer.d.ts +27 -0
  168. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  169. package/ol/layers/MaplibreLayer.js +67 -138
  170. package/ol/layers/RealtimeLayer.d.ts +119 -0
  171. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  172. package/ol/layers/RealtimeLayer.js +327 -184
  173. package/ol/layers/RoutingLayer.d.ts +24 -0
  174. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  175. package/ol/layers/RoutingLayer.js +111 -56
  176. package/ol/layers/VectorLayer.d.ts +23 -0
  177. package/ol/layers/VectorLayer.d.ts.map +1 -0
  178. package/ol/layers/VectorLayer.js +71 -21
  179. package/ol/layers/WMSLayer.d.ts +38 -0
  180. package/ol/layers/WMSLayer.d.ts.map +1 -0
  181. package/ol/layers/WMSLayer.js +105 -37
  182. package/ol/layers/index.d.ts +9 -0
  183. package/ol/layers/index.d.ts.map +1 -0
  184. package/ol/layers/index.js +19 -8
  185. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  186. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  187. package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
  188. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  189. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  190. package/ol/styles/fullTrajectoryStyle.js +44 -40
  191. package/ol/styles/index.d.ts +3 -0
  192. package/ol/styles/index.d.ts.map +1 -0
  193. package/ol/styles/index.js +7 -2
  194. package/package.json +14 -36
  195. package/setupTests.d.ts +2 -0
  196. package/setupTests.d.ts.map +1 -0
  197. package/setupTests.js +15 -0
  198. package/types/index.d.ts +7 -6
  199. package/types/routing.d.ts +25 -25
  200. package/types/stops.d.ts +19 -19
  201. package/api/RealtimeAPI.test.js +0 -67
  202. package/api/RoutingAPI.test.js +0 -25
  203. package/api/StopsAPI.test.js +0 -22
  204. package/common/api/HttpAPI.test.js +0 -50
  205. package/common/api/WebSocketAPI.test.js +0 -311
  206. package/common/controls/Control.test.js +0 -87
  207. package/common/layers/Layer.test.js +0 -134
  208. package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
  209. package/common/utils/createTrackerFilters.test.js +0 -79
  210. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  211. package/common/utils/removeDuplicate.test.js +0 -19
  212. package/common/utils/timeUtils.test.js +0 -10
  213. package/common/utils/trackerConfig.test.js +0 -23
  214. package/mapbox/layers/Layer.test.js +0 -182
  215. package/mapbox/layers/RealtimeLayer.test.js +0 -10
  216. package/ol/controls/CopyrightControl.test.js +0 -165
  217. package/ol/controls/RoutingControl.test.js +0 -146
  218. package/ol/controls/StopFinderControl.test.js +0 -48
  219. package/ol/layers/Layer.test.js +0 -175
  220. package/ol/layers/MapboxLayer.test.js +0 -160
  221. package/ol/layers/MapboxStyleLayer.test.js +0 -226
  222. package/ol/layers/RealtimeLayer.test.js +0 -67
  223. package/ol/layers/RoutingLayer.test.js +0 -39
  224. package/ol/layers/VectorLayer.test.js +0 -76
  225. package/ol/layers/WMSLayer.test.js +0 -57
@@ -1,202 +1,248 @@
1
- import createCanvas from "../utils/createCanvas";
2
- const cacheDelayBg = {};
3
- export const getDelayBgCanvas = (origin, radius, color) => {
4
- const key = `${origin}, ${radius}, ${color}`;
5
- if (!cacheDelayBg[key]) {
6
- const canvas = createCanvas(origin * 2, origin * 2);
7
- if (canvas) {
8
- const ctx = canvas.getContext("2d");
9
- ctx.beginPath();
10
- ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
11
- ctx.fillStyle = color;
12
- ctx.filter = "blur(1px)";
13
- ctx.fill();
14
- cacheDelayBg[key] = canvas;
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");
5
+ /** @private */
6
+ var cacheDelayBg = {};
7
+ /**
8
+ * Draw circle delay background
9
+ *
10
+ * @private
11
+ */
12
+ var getDelayBgCanvas = function (origin, radius, color) {
13
+ var key = "".concat(origin, ", ").concat(radius, ", ").concat(color);
14
+ if (!cacheDelayBg[key]) {
15
+ var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
16
+ if (canvas) {
17
+ var ctx = canvas.getContext('2d');
18
+ ctx.beginPath();
19
+ ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
20
+ ctx.fillStyle = color;
21
+ ctx.filter = 'blur(1px)';
22
+ ctx.fill();
23
+ cacheDelayBg[key] = canvas;
24
+ }
15
25
  }
16
- }
17
- return cacheDelayBg[key];
26
+ return cacheDelayBg[key];
18
27
  };
19
- const cacheDelayText = {};
20
- export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor = "#000", pixelRatio = 1) => {
21
- const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
22
- if (!cacheDelayText[key]) {
23
- const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
24
- if (canvas) {
25
- const ctx = canvas.getContext("2d");
26
- ctx.textAlign = "left";
27
- ctx.textBaseline = "middle";
28
- ctx.font = font;
29
- ctx.fillStyle = delayColor;
30
- ctx.strokeStyle = delayOutlineColor;
31
- ctx.lineWidth = 1.5 * pixelRatio;
32
- const delayText = text;
33
- ctx.strokeText(delayText, 0, fontSize);
34
- ctx.fillText(delayText, 0, fontSize);
35
- cacheDelayText[key] = canvas;
28
+ exports.getDelayBgCanvas = getDelayBgCanvas;
29
+ /** @private */
30
+ var cacheDelayText = {};
31
+ /**
32
+ * Draw delay text
33
+ *
34
+ * @private
35
+ */
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);
40
+ if (!cacheDelayText[key]) {
41
+ var canvas = (0, createCanvas_1.default)(width, fontSize + 8 * pixelRatio);
42
+ if (canvas) {
43
+ var ctx = canvas.getContext('2d');
44
+ ctx.textAlign = 'left';
45
+ ctx.textBaseline = 'middle';
46
+ ctx.font = font;
47
+ ctx.fillStyle = delayColor;
48
+ ctx.strokeStyle = delayOutlineColor;
49
+ ctx.lineWidth = 1.5 * pixelRatio;
50
+ var delayText = text;
51
+ ctx.strokeText(delayText, 0, fontSize);
52
+ ctx.fillText(delayText, 0, fontSize);
53
+ cacheDelayText[key] = canvas;
54
+ }
36
55
  }
37
- }
38
- return cacheDelayText[key];
56
+ return cacheDelayText[key];
39
57
  };
40
- const cacheCircle = {};
41
- export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
42
- const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
43
- if (!cacheCircle[key]) {
44
- const canvas = createCanvas(origin * 2, origin * 2);
45
- if (canvas) {
46
- const ctx = canvas.getContext("2d");
47
- ctx.fillStyle = color;
48
- if (hasStroke) {
49
- ctx.lineWidth = 1 * pixelRatio;
50
- ctx.strokeStyle = "#000000";
51
- }
52
- ctx.beginPath();
53
- ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
54
- ctx.fill();
55
- if (hasDash) {
56
- ctx.setLineDash([5, 3]);
57
- }
58
- if (hasStroke) {
59
- ctx.stroke();
60
- }
61
- cacheCircle[key] = canvas;
58
+ exports.getDelayTextCanvas = getDelayTextCanvas;
59
+ /** @private */
60
+ var cacheCircle = {};
61
+ /**
62
+ * Draw colored circle with black border
63
+ *
64
+ * @private
65
+ */
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);
68
+ if (!cacheCircle[key]) {
69
+ var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
70
+ if (canvas) {
71
+ var ctx = canvas.getContext('2d');
72
+ ctx.fillStyle = color;
73
+ if (hasStroke) {
74
+ ctx.lineWidth = 1 * pixelRatio;
75
+ ctx.strokeStyle = '#000000';
76
+ }
77
+ ctx.beginPath();
78
+ ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
79
+ ctx.fill();
80
+ if (hasDash) {
81
+ ctx.setLineDash([5, 3]);
82
+ }
83
+ if (hasStroke) {
84
+ ctx.stroke();
85
+ }
86
+ cacheCircle[key] = canvas;
87
+ }
62
88
  }
63
- }
64
- return cacheCircle[key];
89
+ return cacheCircle[key];
65
90
  };
66
- const cacheText = {};
67
- export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
68
- const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
69
- if (!cacheText[key]) {
70
- const canvas = createCanvas(origin * 2, origin * 2);
71
- if (canvas) {
72
- const ctx = canvas.getContext("2d");
73
- if (hasStroke) {
74
- ctx.save();
75
- ctx.textBaseline = "middle";
76
- ctx.textAlign = "center";
77
- ctx.font = `bold ${textSize + 2}px Arial`;
78
- ctx.strokeStyle = strokeColor;
79
- ctx.strokeText(text, origin, origin);
80
- ctx.restore();
81
- }
82
- ctx.textBaseline = "middle";
83
- ctx.textAlign = "center";
84
- ctx.fillStyle = fillColor;
85
- ctx.font = `bold ${textSize}px Arial`;
86
- ctx.strokeStyle = strokeColor;
87
- ctx.strokeText(text, origin, origin);
88
- ctx.fillText(text, origin, origin);
89
- cacheText[key] = canvas;
91
+ exports.getCircleCanvas = getCircleCanvas;
92
+ /** @private */
93
+ var cacheText = {};
94
+ /**
95
+ * Draw text in the circle
96
+ *
97
+ * @private
98
+ */
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);
101
+ if (!cacheText[key]) {
102
+ var canvas = (0, createCanvas_1.default)(origin * 2, origin * 2);
103
+ if (canvas) {
104
+ var ctx = canvas.getContext('2d');
105
+ // Draw a stroke to the text only if a provider provides realtime but we don't use it.
106
+ if (hasStroke) {
107
+ ctx.save();
108
+ ctx.textBaseline = 'middle';
109
+ ctx.textAlign = 'center';
110
+ ctx.font = "bold ".concat(textSize + 2, "px Arial");
111
+ ctx.strokeStyle = strokeColor;
112
+ ctx.strokeText(text, origin, origin);
113
+ ctx.restore();
114
+ }
115
+ // Draw a text
116
+ ctx.textBaseline = 'middle';
117
+ ctx.textAlign = 'center';
118
+ ctx.fillStyle = fillColor;
119
+ ctx.font = "bold ".concat(textSize, "px Arial");
120
+ ctx.strokeStyle = strokeColor;
121
+ ctx.strokeText(text, origin, origin);
122
+ ctx.fillText(text, origin, origin);
123
+ cacheText[key] = canvas;
124
+ }
90
125
  }
91
- }
92
- return cacheText[key];
126
+ return cacheText[key];
93
127
  };
94
- const cache = {};
95
- const realtimeDefaultStyle = (trajectory, viewState, options) => {
96
- const {
97
- hoverVehicleId,
98
- selectedVehicleId,
99
- useDelayStyle,
100
- delayOutlineColor = "#000",
101
- delayDisplay = 3e5,
102
- getRadius,
103
- getBgColor,
104
- getDelayColor,
105
- getDelayText,
106
- getTextColor,
107
- getTextSize
108
- } = options;
109
- const { zoom, pixelRatio } = viewState;
110
- let { type, cancelled } = trajectory.properties;
111
- const {
112
- train_id: id,
113
- line,
114
- delay,
115
- state,
116
- operator_provides_realtime_journey: operatorProvidesRealtime
117
- } = trajectory.properties;
118
- let { name, text_color: textColor, color } = line || {};
119
- cancelled = cancelled === true || state === "JOURNEY_CANCELLED";
120
- if (!type) {
121
- type = "Rail";
122
- }
123
- if (!name) {
124
- name = "I";
125
- }
126
- if (!textColor) {
127
- textColor = "#000000";
128
- }
129
- if (color && color[0] !== "#") {
130
- color = `#${color}`;
131
- }
132
- if (textColor[0] !== "#") {
133
- textColor = `#${textColor}`;
134
- }
135
- const z = Math.min(Math.floor(zoom || 1), 16);
136
- const hover = hoverVehicleId && hoverVehicleId === id;
137
- const selected = selectedVehicleId && selectedVehicleId === id;
138
- let radius = getRadius(type, z) * pixelRatio;
139
- const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
140
- if (hover || selected) {
141
- radius = isDisplayStrokeAndDelay ? radius + 5 * pixelRatio : 14 * pixelRatio;
142
- }
143
- const mustDrawText = radius > 10 * pixelRatio;
144
- let key = `${radius}${hover}${selected}${cancelled}${delay}`;
145
- if (useDelayStyle) {
146
- key += `${operatorProvidesRealtime}`;
147
- } else {
148
- key += `${type}${color}`;
149
- }
150
- if (mustDrawText) {
151
- key += `${name}${textColor}`;
152
- }
153
- if (!cache[key]) {
154
- if (radius === 0) {
155
- cache[key] = null;
156
- return null;
128
+ exports.getTextCanvas = getTextCanvas;
129
+ /** @private */
130
+ var cache = {};
131
+ /**
132
+ * A tracker style that take in account the delay.
133
+ *
134
+ * @param {*} trajectory The trajectory to render.
135
+ * @param {*} viewState The view state of the map.
136
+ * @param {*} options Some options to change the rendering
137
+ * @return a canvas
138
+ */
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';
148
+ if (!type) {
149
+ type = 'Rail';
150
+ }
151
+ if (!name) {
152
+ name = 'I';
153
+ }
154
+ if (!textColor) {
155
+ textColor = '#000000';
156
+ }
157
+ if (color && color[0] !== '#') {
158
+ color = "#".concat(color);
157
159
  }
158
- const margin = 1 * pixelRatio;
159
- const radiusDelay = radius + 2;
160
- const markerSize = radius * 2;
161
- const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio;
162
- const origin = size / 2;
163
- const canvas = createCanvas(size, size);
164
- if (canvas) {
165
- const ctx = canvas.getContext("2d");
166
- if (isDisplayStrokeAndDelay && delay !== null) {
167
- const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
168
- ctx.drawImage(delayBg, 0, 0);
169
- }
170
- if (isDisplayStrokeAndDelay && (hover || delay >= delayDisplay || cancelled)) {
171
- const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
172
- const text = getDelayText(delay, cancelled);
173
- if (text) {
174
- const textWidth = text.length * fontSize;
175
- const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
176
- ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
160
+ if (textColor[0] !== '#') {
161
+ textColor = "#".concat(textColor);
162
+ }
163
+ var z = Math.min(Math.floor(zoom || 1), 16);
164
+ var hover = hoverVehicleId && hoverVehicleId === id;
165
+ var selected = selectedVehicleId && selectedVehicleId === id;
166
+ // Calcul the radius of the circle
167
+ var radius = getRadius(type, z) * pixelRatio;
168
+ var isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
169
+ if (hover || selected) {
170
+ radius = isDisplayStrokeAndDelay
171
+ ? radius + 5 * pixelRatio
172
+ : 14 * pixelRatio;
173
+ }
174
+ var mustDrawText = radius > 10 * pixelRatio;
175
+ // Optimize the cache key, very important in high zoom level
176
+ var key = "".concat(radius).concat(hover).concat(selected).concat(cancelled).concat(delay);
177
+ if (useDelayStyle) {
178
+ key += "".concat(operatorProvidesRealtime);
179
+ }
180
+ else {
181
+ key += "".concat(type).concat(color);
182
+ }
183
+ if (mustDrawText) {
184
+ key += "".concat(name).concat(textColor);
185
+ }
186
+ if (!cache[key]) {
187
+ if (radius === 0) {
188
+ cache[key] = null;
189
+ return null;
190
+ }
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;
196
+ // Create the canvas
197
+ var canvas = (0, createCanvas_1.default)(size, size);
198
+ if (canvas) {
199
+ var ctx = canvas.getContext('2d');
200
+ if (isDisplayStrokeAndDelay && delay !== null) {
201
+ // Draw circle delay background
202
+ var delayBg = (0, exports.getDelayBgCanvas)(origin_1, radiusDelay, getDelayColor(delay, cancelled));
203
+ ctx.drawImage(delayBg, 0, 0);
204
+ }
205
+ // Show delay if feature is hovered or if delay is above 5mins.
206
+ if (isDisplayStrokeAndDelay &&
207
+ (hover || delay >= delayDisplay || cancelled)) {
208
+ // 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);
211
+ 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);
215
+ }
216
+ }
217
+ // Draw colored circle with black border
218
+ var circleFillColor = void 0;
219
+ if (useDelayStyle) {
220
+ circleFillColor = getDelayColor(delay, cancelled);
221
+ }
222
+ else {
223
+ circleFillColor = color || getBgColor(type);
224
+ }
225
+ var hasStroke = isDisplayStrokeAndDelay || hover || selected;
226
+ var hasDash = isDisplayStrokeAndDelay &&
227
+ useDelayStyle &&
228
+ delay === null &&
229
+ operatorProvidesRealtime === 'yes';
230
+ var circle = (0, exports.getCircleCanvas)(origin_1, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
231
+ ctx.drawImage(circle, 0, 0);
232
+ // Draw text in the circle
233
+ if (mustDrawText) {
234
+ var fontSize = Math.max(radius, 10);
235
+ var textSize = getTextSize(ctx, markerSize, name, fontSize);
236
+ var textColor2 = !useDelayStyle
237
+ ? textColor || getTextColor(type)
238
+ : '#000000';
239
+ var hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
240
+ var text = (0, exports.getTextCanvas)(name, origin_1, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
241
+ ctx.drawImage(text, 0, 0);
242
+ }
243
+ cache[key] = canvas;
177
244
  }
178
- }
179
- let circleFillColor;
180
- if (useDelayStyle) {
181
- circleFillColor = getDelayColor(delay, cancelled);
182
- } else {
183
- circleFillColor = color || getBgColor(type);
184
- }
185
- const hasStroke = isDisplayStrokeAndDelay || hover || selected;
186
- const hasDash = isDisplayStrokeAndDelay && useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
187
- const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
188
- ctx.drawImage(circle, 0, 0);
189
- if (mustDrawText) {
190
- const fontSize = Math.max(radius, 10);
191
- const textSize = getTextSize(ctx, markerSize, name, fontSize);
192
- const textColor2 = !useDelayStyle ? textColor || getTextColor(type) : "#000000";
193
- const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === "yes";
194
- const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
195
- ctx.drawImage(text, 0, 0);
196
- }
197
- cache[key] = canvas;
198
245
  }
199
- }
200
- return cache[key];
246
+ return cache[key];
201
247
  };
202
- export default realtimeDefaultStyle;
248
+ exports.default = realtimeDefaultStyle;
@@ -0,0 +1,11 @@
1
+ export default realtimeDelayStyle;
2
+ /**
3
+ * A tracker style that display the delay as backgroundColor.
4
+ *
5
+ * @param {*} trajectory The trajectory to render.
6
+ * @param {*} viewState The view state of the map.
7
+ * @param {*} options Some options to change the rendering
8
+ * @return a canvas
9
+ */
10
+ declare function realtimeDelayStyle(trajectory: any, viewState: any, options: any): any;
11
+ //# sourceMappingURL=realtimeDelayStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeDelayStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDelayStyle.js"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AACH,wFAKC"}
@@ -1,8 +1,26 @@
1
- import realtimeDefaultStyle from "./realtimeDefaultStyle";
2
- const realtimeDelayStyle = (trajectory, viewState, options) => {
3
- return realtimeDefaultStyle(trajectory, viewState, {
4
- ...options,
5
- useDelayStyle: true
6
- });
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);
7
12
  };
8
- export default realtimeDelayStyle;
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
15
+ /**
16
+ * A tracker style that display the delay as backgroundColor.
17
+ *
18
+ * @param {*} trajectory The trajectory to render.
19
+ * @param {*} viewState The view state of the map.
20
+ * @param {*} options Some options to change the rendering
21
+ * @return a canvas
22
+ */
23
+ var realtimeDelayStyle = function (trajectory, viewState, options) {
24
+ return (0, realtimeDefaultStyle_1.default)(trajectory, viewState, __assign(__assign({}, options), { useDelayStyle: true }));
25
+ };
26
+ exports.default = realtimeDelayStyle;
@@ -0,0 +1,3 @@
1
+ export default realtimeSimpleStyle;
2
+ declare function realtimeSimpleStyle(): any;
3
+ //# sourceMappingURL=realtimeSimpleStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeSimpleStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeSimpleStyle.js"],"names":[],"mappings":";AAKA,4CAeC"}
@@ -1,18 +1,24 @@
1
- let canvas;
2
- const realtimeSimpleStyle = () => {
3
- if (!canvas) {
4
- document.createElement("canvas");
5
- canvas.width = 15;
6
- canvas.height = 15;
7
- const ctx = canvas.getContext("2d");
8
- ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
9
- ctx.fillStyle = "#8ED6FF";
10
- ctx.fill();
11
- ctx.lineWidth = 3;
12
- ctx.strokeStyle = "black";
13
- ctx.stroke();
14
- ctx.lineWidth = 3;
15
- }
16
- return canvas;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * A very simple tracker style.
5
+ * Display blue point for each train.
6
+ */
7
+ var canvas;
8
+ var realtimeSimpleStyle = function () {
9
+ if (!canvas) {
10
+ document.createElement('canvas');
11
+ canvas.width = 15;
12
+ canvas.height = 15;
13
+ var ctx = canvas.getContext('2d');
14
+ ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
15
+ ctx.fillStyle = '#8ED6FF';
16
+ ctx.fill();
17
+ ctx.lineWidth = 3;
18
+ ctx.strokeStyle = 'black';
19
+ ctx.stroke();
20
+ ctx.lineWidth = 3;
21
+ }
22
+ return canvas;
17
23
  };
18
- export default realtimeSimpleStyle;
24
+ exports.default = realtimeSimpleStyle;
@@ -0,0 +1,50 @@
1
+ type FilterFunction = Function;
2
+ type ViewState = {
3
+ /**
4
+ * A time in ms.
5
+ */
6
+ time: number;
7
+ /**
8
+ * A center in mercator coordinate.
9
+ */
10
+ center: any;
11
+ /**
12
+ * An Extent in mercator coordinates.
13
+ */
14
+ extent: any;
15
+ /**
16
+ * A size ([width, height]).
17
+ */
18
+ size: any;
19
+ /**
20
+ * A rotation in radians.
21
+ */
22
+ rotation: number;
23
+ /**
24
+ * A resolution.
25
+ */
26
+ resolution: number;
27
+ /**
28
+ * A zoom level.
29
+ */
30
+ zoom: number;
31
+ /**
32
+ * A pixel ratio.
33
+ */
34
+ pixelRatio: number;
35
+ };
36
+ type FeatureInfo = {
37
+ /**
38
+ * A layer.
39
+ */
40
+ layer: Layer;
41
+ /**
42
+ * /Feature~Feature[]} features An array of features.
43
+ */
44
+ "": ol;
45
+ /**
46
+ * The coordinate where to find the featue.
47
+ */
48
+ coordinate: any;
49
+ };
50
+ //# sourceMappingURL=typedefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../../src/common/typedefs.js"],"names":[],"mappings":";;;;;UAOc,MAAM;;;;;;;;;;;;;;;;cAIN,MAAM;;;;gBACN,MAAM;;;;UACN,MAAM;;;;gBACN,MAAM"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @typedef {function} FilterFunction
3
+ * @param {Object} vehicle Vehicle to filter.
4
+ */
5
+ /**
6
+ * @typedef {Object} ViewState
7
+ * @property {number} time A time in ms.
8
+ * @property {number[2]} center A center in mercator coordinate.
9
+ * @property {number[4]} extent An Extent in mercator coordinates.
10
+ * @property {number[2]} size A size ([width, height]).
11
+ * @property {number} rotation A rotation in radians.
12
+ * @property {number} resolution A resolution.
13
+ * @property {number} zoom A zoom level.
14
+ * @property {number} pixelRatio A pixel ratio.
15
+ */
16
+ /**
17
+ * @typedef {Object} FeatureInfo
18
+ * @property {Layer} layer A layer.
19
+ * @property {ol/Feature~Feature[]} features An array of features.
20
+ * @property {number[2]} coordinate The coordinate where to find the featue.
21
+ */
@@ -0,0 +1,7 @@
1
+ export default cleanStopTime;
2
+ /**
3
+ * Remove the delay from arrivalTime and departureTime
4
+ * @private
5
+ */
6
+ declare function cleanStopTime(content: any): any;
7
+ //# sourceMappingURL=cleanStopTime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanStopTime.d.ts","sourceRoot":"","sources":["../../../src/common/utils/cleanStopTime.js"],"names":[],"mappings":";AAAA;;;GAGG;AACH,kDAsBC"}