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

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 (259) hide show
  1. package/api/RealtimeAPI.d.ts +279 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +466 -0
  4. package/api/RoutingAPI.d.ts +37 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +32 -12
  7. package/api/StopsAPI.d.ts +38 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +33 -9
  10. package/api/index.d.ts +4 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +3 -3
  13. package/api/typedefs.d.ts +179 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +75 -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 +54 -27
  19. package/common/api/WebSocketAPI.d.ts +153 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +330 -164
  22. package/common/controls/ControlCommon.d.ts +76 -0
  23. package/common/controls/ControlCommon.d.ts.map +1 -0
  24. package/common/controls/ControlCommon.js +150 -0
  25. package/common/controls/CopyrightControlCommon.d.ts +13 -0
  26. package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
  27. package/common/controls/CopyrightControlCommon.js +34 -0
  28. package/common/controls/StopFinderControlCommon.d.ts +55 -0
  29. package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
  30. package/common/controls/StopFinderControlCommon.js +144 -0
  31. package/common/index.d.ts +3 -0
  32. package/common/index.d.ts.map +1 -0
  33. package/common/index.js +2 -4
  34. package/common/layers/LayerCommon.d.ts +94 -0
  35. package/common/layers/LayerCommon.d.ts.map +1 -0
  36. package/common/layers/LayerCommon.js +244 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +776 -0
  40. package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
  41. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  42. package/common/mixins/UserInteractionsLayerMixin.js +241 -0
  43. package/common/styles/index.d.ts +5 -0
  44. package/common/styles/index.d.ts.map +1 -0
  45. package/common/styles/index.js +4 -4
  46. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  47. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  48. package/common/styles/realtimeDefaultStyle.js +275 -0
  49. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  50. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDelayStyle.js +13 -0
  52. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  53. package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeHeadingStyle.js +85 -0
  55. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -0
  58. package/common/typedefs.d.ts +111 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +52 -0
  61. package/common/utils/compareDepartures.d.ts +11 -0
  62. package/common/utils/compareDepartures.d.ts.map +1 -0
  63. package/common/utils/compareDepartures.js +35 -0
  64. package/common/utils/createCanvas.d.ts +10 -0
  65. package/common/utils/createCanvas.d.ts.map +1 -0
  66. package/common/utils/createCanvas.js +27 -0
  67. package/common/utils/createRealtimeFilters.d.ts +13 -0
  68. package/common/utils/createRealtimeFilters.d.ts.map +1 -0
  69. package/common/utils/createRealtimeFilters.js +74 -0
  70. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  71. package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
  72. package/common/utils/debounceDeparturesMessages.js +24 -0
  73. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  74. package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
  75. package/common/utils/debounceWebsocketMessages.js +29 -0
  76. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  77. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  78. package/common/utils/getLayersAsFlatArray.js +15 -0
  79. package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
  80. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  81. package/common/utils/getMapboxMapCopyrights.js +26 -15
  82. package/common/utils/getMapboxRender.d.ts +7 -0
  83. package/common/utils/getMapboxRender.d.ts.map +1 -0
  84. package/common/utils/getMapboxRender.js +87 -0
  85. package/common/utils/getMaplibreRender.d.ts +7 -0
  86. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  87. package/common/utils/getMaplibreRender.js +38 -0
  88. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  89. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  90. package/common/utils/getRealtimeModeSuffix.js +7 -0
  91. package/common/utils/getUrlWithParams.d.ts +9 -0
  92. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  93. package/common/utils/getUrlWithParams.js +18 -0
  94. package/common/utils/getVehiclePosition.d.ts +16 -0
  95. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  96. package/common/utils/getVehiclePosition.js +67 -37
  97. package/common/utils/index.d.ts +17 -0
  98. package/common/utils/index.d.ts.map +1 -0
  99. package/common/utils/index.js +17 -5
  100. package/common/utils/realtimeConfig.d.ts +49 -0
  101. package/common/utils/realtimeConfig.d.ts.map +1 -0
  102. package/common/utils/realtimeConfig.js +173 -0
  103. package/common/utils/removeDuplicate.d.ts +10 -0
  104. package/common/utils/removeDuplicate.d.ts.map +1 -0
  105. package/common/utils/removeDuplicate.js +12 -5
  106. package/common/utils/renderTrajectories.d.ts +17 -0
  107. package/common/utils/renderTrajectories.d.ts.map +1 -0
  108. package/common/utils/renderTrajectories.js +110 -0
  109. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  110. package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
  111. package/common/utils/sortAndFilterDepartures.js +58 -0
  112. package/common/utils/sortByDelay.d.ts +3 -0
  113. package/common/utils/sortByDelay.d.ts.map +1 -0
  114. package/common/utils/sortByDelay.js +17 -15
  115. package/common/utils/timeUtils.d.ts +24 -0
  116. package/common/utils/timeUtils.d.ts.map +1 -0
  117. package/common/utils/timeUtils.js +34 -15
  118. package/iife.d.ts +3 -0
  119. package/iife.d.ts.map +1 -0
  120. package/iife.js +5 -0
  121. package/index.d.ts +10 -0
  122. package/index.d.ts.map +1 -0
  123. package/index.js +8 -6
  124. package/mapbox/controls/CopyrightControl.d.ts +29 -0
  125. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  126. package/mapbox/controls/CopyrightControl.js +44 -25
  127. package/mapbox/controls/index.d.ts +2 -0
  128. package/mapbox/controls/index.d.ts.map +1 -0
  129. package/mapbox/controls/index.js +2 -1
  130. package/mapbox/index.d.ts +6 -0
  131. package/mapbox/index.d.ts.map +1 -0
  132. package/mapbox/index.js +5 -4
  133. package/mapbox/layers/Layer.d.ts +59 -0
  134. package/mapbox/layers/Layer.d.ts.map +1 -0
  135. package/mapbox/layers/Layer.js +99 -55
  136. package/mapbox/layers/RealtimeLayer.d.ts +181 -0
  137. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  138. package/mapbox/layers/RealtimeLayer.js +276 -0
  139. package/mapbox/layers/index.d.ts +3 -0
  140. package/mapbox/layers/index.d.ts.map +1 -0
  141. package/mapbox/layers/index.js +2 -2
  142. package/mapbox/utils/getMercatorResolution.d.ts +9 -0
  143. package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
  144. package/mapbox/utils/getMercatorResolution.js +18 -0
  145. package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
  146. package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
  147. package/mapbox/utils/getSourceCoordinates.js +27 -0
  148. package/mapbox/utils/index.d.ts +3 -0
  149. package/mapbox/utils/index.d.ts.map +1 -0
  150. package/mapbox/utils/index.js +2 -0
  151. package/mbt.js +26061 -16500
  152. package/mbt.js.map +4 -4
  153. package/mbt.min.js +205 -126
  154. package/mbt.min.js.map +4 -4
  155. package/ol/controls/CopyrightControl.d.ts +31 -0
  156. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  157. package/ol/controls/CopyrightControl.js +62 -36
  158. package/ol/controls/RoutingControl.d.ts +193 -0
  159. package/ol/controls/RoutingControl.d.ts.map +1 -0
  160. package/ol/controls/RoutingControl.js +601 -357
  161. package/ol/controls/StopFinderControl.d.ts +30 -0
  162. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  163. package/ol/controls/StopFinderControl.js +30 -8
  164. package/ol/controls/index.d.ts +4 -0
  165. package/ol/controls/index.d.ts.map +1 -0
  166. package/ol/controls/index.js +3 -3
  167. package/ol/index.d.ts +6 -0
  168. package/ol/index.d.ts.map +1 -0
  169. package/ol/index.js +5 -5
  170. package/ol/layers/Layer.d.ts +86 -0
  171. package/ol/layers/Layer.d.ts.map +1 -0
  172. package/ol/layers/Layer.js +163 -77
  173. package/ol/layers/MapGlLayer.d.ts +67 -0
  174. package/ol/layers/MapGlLayer.d.ts.map +1 -0
  175. package/ol/layers/MapGlLayer.js +218 -0
  176. package/ol/layers/MapboxLayer.d.ts +50 -0
  177. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  178. package/ol/layers/MapboxLayer.js +99 -193
  179. package/ol/layers/MapboxStyleLayer.d.ts +129 -0
  180. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  181. package/ol/layers/MapboxStyleLayer.js +362 -171
  182. package/ol/layers/MaplibreLayer.d.ts +28 -0
  183. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  184. package/ol/layers/MaplibreLayer.js +30 -135
  185. package/ol/layers/RealtimeLayer.d.ts +202 -0
  186. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  187. package/ol/layers/RealtimeLayer.js +340 -0
  188. package/ol/layers/RoutingLayer.d.ts +34 -0
  189. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  190. package/ol/layers/RoutingLayer.js +72 -48
  191. package/ol/layers/VectorLayer.d.ts +25 -0
  192. package/ol/layers/VectorLayer.d.ts.map +1 -0
  193. package/ol/layers/VectorLayer.js +34 -18
  194. package/ol/layers/WMSLayer.d.ts +42 -0
  195. package/ol/layers/WMSLayer.d.ts.map +1 -0
  196. package/ol/layers/WMSLayer.js +84 -34
  197. package/ol/layers/index.d.ts +9 -0
  198. package/ol/layers/index.d.ts.map +1 -0
  199. package/ol/layers/index.js +8 -8
  200. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  201. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  202. package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
  203. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  204. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  205. package/ol/styles/fullTrajectoryStyle.js +40 -39
  206. package/ol/styles/index.d.ts +3 -0
  207. package/ol/styles/index.d.ts.map +1 -0
  208. package/ol/styles/index.js +2 -2
  209. package/package.json +81 -133
  210. package/setupTests.d.ts +2 -0
  211. package/setupTests.d.ts.map +1 -0
  212. package/setupTests.js +26 -0
  213. package/types/common.d.ts +122 -0
  214. package/types/index.d.ts +11 -0
  215. package/types/realtime.d.ts +320 -0
  216. package/types/routing.d.ts +206 -0
  217. package/types/stops.d.ts +143 -0
  218. package/README.md +0 -23
  219. package/api/RoutingAPI.test.js +0 -25
  220. package/api/StopsAPI.test.js +0 -22
  221. package/api/TralisAPI.js +0 -359
  222. package/api/TralisAPI.test.js +0 -67
  223. package/api/TralisAPIUtils.js +0 -43
  224. package/common/Tracker.js +0 -93
  225. package/common/api/HttpAPI.test.js +0 -50
  226. package/common/api/WebSocketAPI.test.js +0 -311
  227. package/common/controls/Control.js +0 -81
  228. package/common/controls/Control.test.js +0 -87
  229. package/common/layers/Layer.js +0 -213
  230. package/common/layers/Layer.test.js +0 -526
  231. package/common/mixins/CopyrightMixin.js +0 -24
  232. package/common/mixins/SearchMixin.js +0 -110
  233. package/common/mixins/TralisLayerMixin.js +0 -479
  234. package/common/styles/trackerDefaultStyle.js +0 -197
  235. package/common/styles/trackerDelayStyle.js +0 -8
  236. package/common/styles/trackerSimpleStyle.js +0 -18
  237. package/common/trackerConfig.js +0 -152
  238. package/common/trackerConfig.test.js +0 -23
  239. package/common/utils/createTrackerFilters.js +0 -56
  240. package/common/utils/createTrackerFilters.test.js +0 -79
  241. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  242. package/common/utils/getMapboxStyleUrl.js +0 -22
  243. package/common/utils/removeDuplicate.test.js +0 -19
  244. package/common/utils/timeUtils.test.js +0 -10
  245. package/mapbox/layers/Layer.test.js +0 -182
  246. package/mapbox/layers/TralisLayer.js +0 -182
  247. package/mapbox/layers/TralisLayer.test.js +0 -38
  248. package/mapbox/utils.js +0 -32
  249. package/ol/controls/CopyrightControl.test.js +0 -165
  250. package/ol/controls/RoutingControl.test.js +0 -151
  251. package/ol/controls/StopFinderControl.test.js +0 -48
  252. package/ol/layers/Layer.test.js +0 -174
  253. package/ol/layers/MapboxLayer.test.js +0 -160
  254. package/ol/layers/MapboxStyleLayer.test.js +0 -231
  255. package/ol/layers/RoutingLayer.test.js +0 -40
  256. package/ol/layers/TralisLayer.js +0 -185
  257. package/ol/layers/TralisLayer.test.js +0 -79
  258. package/ol/layers/VectorLayer.test.js +0 -87
  259. package/ol/layers/WMSLayer.test.js +0 -76
@@ -1,152 +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
- export const types = [
14
- /^Tram/i,
15
- /^Subway( \/ Metro \/ S-Bahn)?/i,
16
- /^Train/i,
17
- /^Bus/i,
18
- /^Ferry/i,
19
- /^Cable ?Car/i,
20
- /^Gondola/i,
21
- /^Funicular/i,
22
- /^(Long distance bus|coach)/i,
23
- /^Rail/i
24
- ];
25
- export const bgColors = [
26
- "#ffb400",
27
- "#ff5400",
28
- "#ff8080",
29
- "#ea0000",
30
- "#3000ff",
31
- "#ffb400",
32
- "#41a27b",
33
- "#00d237",
34
- "#b5b5b5",
35
- "#ff8080"
36
- ];
37
- export const textColors = [
38
- "#000000",
39
- "#ffffff",
40
- "#000000",
41
- "#ffffff",
42
- "#ffffff",
43
- "#000000",
44
- "#ffffff",
45
- "#000000",
46
- "#000000",
47
- "#000000"
48
- ];
49
- export const timeSteps = [
50
- 1e5,
51
- 5e4,
52
- 4e4,
53
- 3e4,
54
- 2e4,
55
- 15e3,
56
- 1e4,
57
- 5e3,
58
- 2e3,
59
- 1e3,
60
- 400,
61
- 300,
62
- 250,
63
- 180,
64
- 90,
65
- 60,
66
- 50,
67
- 50,
68
- 50,
69
- 50,
70
- 50
71
- ];
72
- export const getTypeIndex = (type) => {
73
- if (typeof type === "string") {
74
- return types.findIndex((t) => t.test(type));
75
- }
76
- return type;
77
- };
78
- export const getRadius = (type, zoom) => {
79
- try {
80
- const typeIdx = getTypeIndex(type || 0);
81
- return trackerRadiusMapping[typeIdx][zoom];
82
- } catch (e) {
83
- return 1;
84
- }
85
- };
86
- export const getBgColor = (type = 0) => {
87
- try {
88
- const typeIdx = getTypeIndex(type);
89
- return bgColors[typeIdx];
90
- } catch (e) {
91
- return 1;
92
- }
93
- };
94
- export const getTextColor = (type = 0) => {
95
- try {
96
- const typeIdx = getTypeIndex(type);
97
- return textColors[typeIdx];
98
- } catch (e) {
99
- return 1;
100
- }
101
- };
102
- export const getTextSize = (ctx, markerSize, text, fontSize) => {
103
- ctx.font = `bold ${fontSize}px Arial`;
104
- let newText = ctx.measureText(text);
105
- const maxiter = 25;
106
- let i = 0;
107
- while (newText.width > markerSize - 6 && i < maxiter) {
108
- fontSize -= 0.5;
109
- ctx.font = `bold ${fontSize}px arial, sans-serif`;
110
- newText = ctx.measureText(text);
111
- i += 1;
112
- }
113
- return fontSize;
114
- };
115
- export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
116
- if (cancelled) {
117
- return isDelayText ? "#ff0000" : "#a0a0a0";
118
- }
119
- if (delayInMs >= 36e5) {
120
- return "#ed004c";
121
- }
122
- if (delayInMs >= 5e5) {
123
- return "#e80000";
124
- }
125
- if (delayInMs >= 3e5) {
126
- return "#ff4a00";
127
- }
128
- if (delayInMs >= 18e4) {
129
- return "#f7bf00";
130
- }
131
- if (delayInMs === null) {
132
- return "#a0a0a0";
133
- }
134
- return "#00a00c";
135
- };
136
- export const getDelayText = (delayInMs, cancelled) => {
137
- if (cancelled) {
138
- return String.fromCodePoint(215);
139
- }
140
- if (delayInMs > 36e5) {
141
- const rounded = Math.round(delayInMs / 36e5);
142
- return `+${rounded}h`;
143
- }
144
- if (delayInMs > 59e3) {
145
- const rounded = Math.round(delayInMs / 6e4);
146
- return `+${rounded}m`;
147
- }
148
- if (delayInMs > 0) {
149
- return `+${delayInMs}s`;
150
- }
151
- return "";
152
- };
@@ -1,23 +0,0 @@
1
- import { getTypeIndex } from "./trackerConfig";
2
- describe("trackerConfig", () => {
3
- describe("#getTypeIndex()", () => {
4
- test("retrurn the type is it's not a string", () => {
5
- const obj = { foo: "foo" };
6
- expect(getTypeIndex(obj)).toBe(obj);
7
- expect(getTypeIndex(0)).toBe(0);
8
- expect(getTypeIndex(null)).toBe(null);
9
- expect(getTypeIndex(void 0)).toBe(void 0);
10
- });
11
- test("find good index for new tracker values", () => {
12
- expect(getTypeIndex("tram")).toBe(0);
13
- expect(getTypeIndex("subway")).toBe(1);
14
- expect(getTypeIndex("bus")).toBe(3);
15
- expect(getTypeIndex("ferry")).toBe(4);
16
- expect(getTypeIndex("cablecar")).toBe(5);
17
- expect(getTypeIndex("gondola")).toBe(6);
18
- expect(getTypeIndex("funicular")).toBe(7);
19
- expect(getTypeIndex("coach")).toBe(8);
20
- expect(getTypeIndex("rail")).toBe(9);
21
- });
22
- });
23
- });
@@ -1,56 +0,0 @@
1
- const createFilters = (line, route, operator, regexLine) => {
2
- const filterList = [];
3
- if (!line && !route && !operator && !regexLine) {
4
- return null;
5
- }
6
- if (regexLine) {
7
- const regexLineList = typeof regexLine === "string" ? [regexLine] : regexLine;
8
- const lineFilter = (item) => {
9
- const name = item.properties.name || item.properties.line && item.properties.line.name || "";
10
- if (!name) {
11
- return false;
12
- }
13
- return regexLineList.some((regexStr) => new RegExp(regexStr, "i").test(name));
14
- };
15
- filterList.push(lineFilter);
16
- }
17
- if (line) {
18
- const lineFiltersList = typeof line === "string" ? line.split(",") : line;
19
- const lineList = lineFiltersList.map((l) => l.replace(/\s+/g, "").toUpperCase());
20
- const lineFilter = (item) => {
21
- const { line: linee, name } = item.properties;
22
- const lineName = (name || linee && linee.name || "").toUpperCase();
23
- if (!lineName) {
24
- return false;
25
- }
26
- return lineList.includes(lineName);
27
- };
28
- filterList.push(lineFilter);
29
- }
30
- if (route) {
31
- const routes = typeof route === "string" ? route.split(",") : route;
32
- const routeList = routes.map((item) => parseInt(item, 10));
33
- const routeFilter = (item) => {
34
- const routeId = parseInt(item.properties.routeIdentifier.split(".")[0], 10);
35
- return routeList.includes(routeId);
36
- };
37
- filterList.push(routeFilter);
38
- }
39
- if (operator) {
40
- const operatorList = typeof operator === "string" ? [operator] : operator;
41
- const operatorFilter = (item) => operatorList.some((op) => new RegExp(op, "i").test(item.properties.operator));
42
- filterList.push(operatorFilter);
43
- }
44
- if (!filterList.length) {
45
- return null;
46
- }
47
- return (t) => {
48
- for (let i = 0; i < filterList.length; i += 1) {
49
- if (!filterList[i](t)) {
50
- return false;
51
- }
52
- }
53
- return true;
54
- };
55
- };
56
- export default createFilters;
@@ -1,79 +0,0 @@
1
- import createTrackerFilters from "./createTrackerFilters";
2
- const u1 = {
3
- properties: {
4
- routeIdentifier: "001.000827.004:7",
5
- operator: "FoO",
6
- line: {
7
- name: "U1"
8
- }
9
- }
10
- };
11
- const ireta = {
12
- properties: {
13
- routeIdentifier: "0022.000827.004:7",
14
- operator: "BAR",
15
- line: {
16
- name: "IRETA"
17
- }
18
- }
19
- };
20
- const arb = {
21
- properties: {
22
- routeIdentifier: "00333.000827.004:7",
23
- operator: "qux",
24
- line: {
25
- name: "ARB"
26
- }
27
- }
28
- };
29
- const trajectories = [u1, ireta, arb];
30
- describe("#createTrackerFilter()", () => {
31
- test("returns null", () => {
32
- const filterFunc = createTrackerFilters();
33
- expect(filterFunc).toBe(null);
34
- });
35
- describe("using line", () => {
36
- test("as string", () => {
37
- const filterFunc = createTrackerFilters("u1,foo");
38
- expect(trajectories.filter(filterFunc)).toEqual([u1]);
39
- });
40
- test("as array of string", () => {
41
- const filterFunc = createTrackerFilters(["u1", "foo", "IRETA"]);
42
- expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
43
- });
44
- });
45
- describe("using route identifier", () => {
46
- test("as string", () => {
47
- const filterFunc = createTrackerFilters(null, "1,foo");
48
- expect(trajectories.filter(filterFunc)).toEqual([u1]);
49
- });
50
- test("as array of string", () => {
51
- const filterFunc = createTrackerFilters(null, ["22", "foo", "1"]);
52
- expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
53
- });
54
- });
55
- describe("using operator", () => {
56
- test("as string", () => {
57
- const filterFunc = createTrackerFilters(null, null, "foo");
58
- expect(trajectories.filter(filterFunc)).toEqual([u1]);
59
- });
60
- test("as array of string", () => {
61
- const filterFunc = createTrackerFilters(null, null, ["bar", "foo", "1"]);
62
- expect(trajectories.filter(filterFunc)).toEqual([u1, ireta]);
63
- });
64
- });
65
- describe("using regexLine", () => {
66
- test("as string", () => {
67
- const filterFunc = createTrackerFilters(null, null, null, "^(S|R$|RE|PE|D|IRE|RB|TER)");
68
- expect(trajectories.filter(filterFunc)).toEqual([ireta]);
69
- });
70
- test("as array of string", () => {
71
- const filterFunc = createTrackerFilters(null, null, null, [
72
- "^IR",
73
- "^ARB$",
74
- "foo"
75
- ]);
76
- expect(trajectories.filter(filterFunc)).toEqual([ireta, arb]);
77
- });
78
- });
79
- });
@@ -1,40 +0,0 @@
1
- import getMapboxMapCopyrights from "./getMapboxMapCopyrights";
2
- describe("getMapboxMapCopyrights()", () => {
3
- test("returns an empty array if map is not defined", () => {
4
- expect(getMapboxMapCopyrights().length).toBe(0);
5
- });
6
- test("returns an empty array if map.style is not defined", () => {
7
- expect(getMapboxMapCopyrights({}).length).toBe(0);
8
- });
9
- test("returns non depluicated copyrights in an array", () => {
10
- expect(getMapboxMapCopyrights({
11
- style: {
12
- sourceCaches: {
13
- used: {
14
- used: true,
15
- getSource() {
16
- return {
17
- attribution: '<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a> <a href="https://www.openstreetmap.org/about/" target="_blank">&copy; OpenStreetMap contributors</a>'
18
- };
19
- }
20
- },
21
- "not used": {
22
- used: false
23
- },
24
- "also used": {
25
- used: true,
26
- getSource() {
27
- return {
28
- attribution: '<a href="https://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a> <a href="https://www.imagico.de/" target="_blank">&copy; imagico</a>'
29
- };
30
- }
31
- }
32
- }
33
- }
34
- })).toEqual([
35
- '<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a>',
36
- '<a href="https://www.openstreetmap.org/about/" target="_blank">\xA9 OpenStreetMap contributors</a>',
37
- '<a href="https://www.imagico.de/" target="_blank">\xA9 imagico</a>'
38
- ]);
39
- });
40
- });
@@ -1,22 +0,0 @@
1
- import qs from "query-string";
2
- const getMapboxStyleUrl = (apiKey, apiKeyName, styleUrl) => {
3
- if (apiKey === false) {
4
- return styleUrl;
5
- }
6
- const parsedStyle = qs.parseUrl(styleUrl);
7
- if (!apiKey && parsedStyle.query[apiKeyName]) {
8
- return styleUrl;
9
- }
10
- if (!apiKey) {
11
- console.warn(`No apiKey is defined for request to ${styleUrl}`);
12
- return null;
13
- }
14
- return qs.stringifyUrl({
15
- ...parsedStyle,
16
- query: {
17
- ...parsedStyle.query,
18
- [apiKeyName]: apiKey
19
- }
20
- });
21
- };
22
- export default getMapboxStyleUrl;
@@ -1,19 +0,0 @@
1
- import removeDuplicate from "./removeDuplicate";
2
- describe("removeDuplicate()", () => {
3
- test("removes duplicates", () => {
4
- expect(removeDuplicate([
5
- "a",
6
- " ",
7
- " ",
8
- "b",
9
- "a",
10
- void 0,
11
- null,
12
- "A",
13
- 0,
14
- "c",
15
- "b",
16
- "B"
17
- ])).toEqual(["a", "b", "c"]);
18
- });
19
- });
@@ -1,10 +0,0 @@
1
- import { getUTCDateString, getUTCTimeString } from "./timeUtils";
2
- describe("timeUtils", () => {
3
- test("getUTCDateString should be correct.", () => {
4
- expect(getUTCDateString(new Date(2020, 5, 30))).toBe("20200630");
5
- expect(getUTCDateString(new Date("January 1, 2021 00:15:30 GMT+2:00"))).toBe("20201231");
6
- });
7
- test("getUTCTimeString should be correct.", () => {
8
- expect(getUTCTimeString(new Date(2020, 5, 30, 11, 5, 1, 123))).toBe("11:5:1.123");
9
- });
10
- });
@@ -1,182 +0,0 @@
1
- import { Map } from "maplibre-gl";
2
- import { toLonLat } from "ol/proj";
3
- import Layer from "./Layer";
4
- let map;
5
- let mapElement;
6
- describe("Layer", () => {
7
- beforeEach(() => {
8
- mapElement = document.createElement("div");
9
- const { style } = mapElement;
10
- style.position = "absolute";
11
- style.left = "0px";
12
- style.top = "0px";
13
- style.width = "400px";
14
- style.height = "400px";
15
- mapElement.setAttribute("id", "map");
16
- document.body.appendChild(mapElement);
17
- map = new Map({
18
- container: document.getElementById("map"),
19
- style: `path/to/style`,
20
- center: toLonLat([831634, 5933959]),
21
- zoom: 9
22
- });
23
- });
24
- afterEach(() => {
25
- document.body.removeChild(mapElement);
26
- });
27
- test("should initialize.", () => {
28
- const layer = new Layer({ name: "Layer" });
29
- expect(layer).toBeInstanceOf(Layer);
30
- });
31
- test("should be visible by default.", () => {
32
- const layer = new Layer({ name: "Layer" });
33
- expect(layer.visible).toBe(true);
34
- });
35
- test("should be invisible if defined.", () => {
36
- const layer = new Layer({ name: "Layer", visible: false });
37
- expect(layer.visible).toBe(false);
38
- });
39
- test("should be invisible if set.", () => {
40
- const layer = new Layer({ name: "Layer" });
41
- layer.setVisible(false);
42
- expect(layer.visible).toBe(false);
43
- });
44
- test("should visibility stay unchanged", () => {
45
- const layer = new Layer({ name: "Layer", visible: false });
46
- layer.setVisible(false);
47
- expect(layer.visible).toBe(false);
48
- });
49
- test("should return its name.", () => {
50
- const layer = new Layer({ name: "Layer", visible: false });
51
- expect(layer.name).toEqual("Layer");
52
- });
53
- test("should call terminate on initialization.", () => {
54
- const layer = new Layer({ name: "Layer" });
55
- const spy = jest.spyOn(layer, "detachFromMap");
56
- layer.attachToMap(map);
57
- expect(spy).toHaveBeenCalledTimes(1);
58
- });
59
- test("should listen for click/hover events when layer is visible by default then should not when hidden.", async () => {
60
- global.console.error = jest.fn();
61
- const layer = new Layer({ name: "Layer" });
62
- expect(layer.visible).toBe(true);
63
- const spy = jest.fn();
64
- const spy2 = jest.fn();
65
- layer.attachToMap(map);
66
- layer.onHover(spy);
67
- layer.onClick(spy2);
68
- expect(spy).toHaveBeenCalledTimes(0);
69
- expect(spy2).toHaveBeenCalledTimes(0);
70
- await map.fire("mousemove", {
71
- type: "mousemove",
72
- lngLat: { toArray: () => [0, 0] },
73
- coordinate: [0, 0]
74
- });
75
- await map.fire("click", {
76
- type: "click",
77
- lngLat: { toArray: () => [0, 0] }
78
- });
79
- expect(spy).toHaveBeenCalledTimes(1);
80
- expect(spy2).toHaveBeenCalledTimes(1);
81
- spy.mockReset();
82
- spy2.mockReset();
83
- layer.setVisible(false);
84
- await map.fire("mousemove", {
85
- type: "mousemove",
86
- lngLat: { toArray: () => [0, 0] }
87
- });
88
- await map.fire("click", {
89
- type: "click",
90
- lngLat: { toArray: () => [0, 0] }
91
- });
92
- expect(spy).toHaveBeenCalledTimes(0);
93
- expect(spy2).toHaveBeenCalledTimes(0);
94
- global.console.error.mockRestore();
95
- });
96
- test("should not listen for click/hover events when layer is not visible by default then should not when visible.", async () => {
97
- global.console.error = jest.fn();
98
- const layer = new Layer({ name: "Layer", visible: false });
99
- expect(layer.visible).toBe(false);
100
- const spy = jest.fn();
101
- const spy2 = jest.fn();
102
- layer.attachToMap(map);
103
- layer.onHover(spy);
104
- layer.onClick(spy2);
105
- expect(spy).toHaveBeenCalledTimes(0);
106
- expect(spy2).toHaveBeenCalledTimes(0);
107
- await map.fire("mousemove", {
108
- type: "mousemove",
109
- lngLat: { toArray: () => [0, 0] },
110
- coordinate: [0, 0]
111
- });
112
- await map.fire("click", {
113
- type: "click",
114
- lngLat: { toArray: () => [0, 0] }
115
- });
116
- expect(spy).toHaveBeenCalledTimes(0);
117
- expect(spy2).toHaveBeenCalledTimes(0);
118
- spy.mockReset();
119
- spy2.mockReset();
120
- layer.setVisible(true);
121
- await map.fire("mousemove", {
122
- type: "mousemove",
123
- lngLat: { toArray: () => [0, 0] },
124
- coordinate: [0, 0]
125
- });
126
- await map.fire("click", {
127
- type: "click",
128
- lngLat: { toArray: () => [0, 0] }
129
- });
130
- expect(spy).toHaveBeenCalledTimes(1);
131
- expect(spy2).toHaveBeenCalledTimes(1);
132
- global.console.error.mockRestore();
133
- });
134
- test("should not listen for click/hover events after layer.detachFromMap()", async () => {
135
- global.console.error = jest.fn();
136
- const layer = new Layer({ name: "Layer", visible: true });
137
- expect(layer.visible).toBe(true);
138
- const spy = jest.fn();
139
- const spy2 = jest.fn();
140
- layer.attachToMap(map);
141
- layer.onHover(spy);
142
- layer.onClick(spy2);
143
- expect(spy).toHaveBeenCalledTimes(0);
144
- expect(spy2).toHaveBeenCalledTimes(0);
145
- await map.fire("mousemove", {
146
- type: "mousemove",
147
- lngLat: { toArray: () => [0, 0] },
148
- coordinate: [0, 0]
149
- });
150
- await map.fire("click", {
151
- type: "click",
152
- lngLat: { toArray: () => [0, 0] }
153
- });
154
- expect(spy).toHaveBeenCalledTimes(1);
155
- expect(spy2).toHaveBeenCalledTimes(1);
156
- spy.mockReset();
157
- spy2.mockReset();
158
- layer.detachFromMap(map);
159
- await map.fire("mousemove", {
160
- type: "mousemove",
161
- lngLat: { toArray: () => [0, 0] },
162
- coordinate: [0, 0]
163
- });
164
- await map.fire("click", {
165
- type: "click",
166
- lngLat: { toArray: () => [0, 0] }
167
- });
168
- expect(spy).toHaveBeenCalledTimes(0);
169
- expect(spy2).toHaveBeenCalledTimes(0);
170
- global.console.error.mockRestore();
171
- });
172
- test("should clone", () => {
173
- const layer = new Layer({
174
- name: "Layer",
175
- copyrights: ["bar"]
176
- });
177
- const clone = layer.clone({ name: "clone" });
178
- expect(clone).not.toBe(layer);
179
- expect(clone.name).toBe("clone");
180
- expect(clone).toBeInstanceOf(Layer);
181
- });
182
- });