mobility-toolbox-js 2.0.1-beta.13 → 2.2.0-beta.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 +281 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +490 -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 +779 -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 +26074 -16501
  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 +13 -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
@@ -0,0 +1,60 @@
1
+ import { AnyMap, CommonLayerClass, UserInteractionCallback } from '../../types';
2
+ import LayerCommon from '../layers/LayerCommon';
3
+ export type UserInteractionsLayerMixinOptions = {
4
+ userInteractions?: boolean;
5
+ userClickInteractions?: boolean;
6
+ userHoverInteractions?: boolean;
7
+ defaultUserInteractions?: boolean;
8
+ onClick?: UserInteractionCallback;
9
+ onHover?: UserInteractionCallback;
10
+ };
11
+ /**
12
+ * UserInteractionsLayerInterface.
13
+ */
14
+ export declare class UserInteractionsLayerInterface {
15
+ constructor(options?: {});
16
+ /**
17
+ * Initialize the layer adding user interactions.
18
+ *
19
+ * @param {ol/Map~Map} map
20
+ */
21
+ attachToMap(map: AnyMap): void;
22
+ /**
23
+ * Terminate the layer unsubscribing user interactions.
24
+ */
25
+ detachFromMap(): void;
26
+ /**
27
+ * Activate map listeners events.
28
+ */
29
+ activateUserInteractions(): void;
30
+ /**
31
+ * Deactivate map listeners events.
32
+ */
33
+ deactivateUserInteractions(): void;
34
+ /**
35
+ * Subscribe on user:click event.
36
+ */
37
+ onClick(callback: UserInteractionCallback): void;
38
+ /**
39
+ * Subscribe on user:hover event.
40
+ */
41
+ onHover(callback: UserInteractionCallback): void;
42
+ /**
43
+ * Unsubscribe on user:click event.
44
+ */
45
+ unClick(callback: UserInteractionCallback): void;
46
+ /**
47
+ * Unsubscribe on user:hover event.
48
+ */
49
+ unHover(callback: UserInteractionCallback): void;
50
+ }
51
+ /**
52
+ * Mixin for UserInteractionsLayerInterface. It provide onClick and onHover functions.
53
+ *
54
+ * @param {Class} Base A class to extend with {UserInteractionsLayerInterface} functionnalities.
55
+ * @return {Class} A class that implements {UserInteractionsLayerInterface} class and extends Base;
56
+ * @private
57
+ */
58
+ declare function UserInteractionsLayerMixin<T extends CommonLayerClass>(Base: T): T & typeof LayerCommon;
59
+ export default UserInteractionsLayerMixin;
60
+ //# sourceMappingURL=UserInteractionsLayerMixin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserInteractionsLayerMixin.d.ts","sourceRoot":"","sources":["../../../src/common/mixins/UserInteractionsLayerMixin.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,WAAW,MAAM,uBAAuB,CAAC;AAEhD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,qBAAa,8BAA8B;gBAU7B,OAAO,KAAK;IAExB;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM;IAEvB;;OAEG;IACH,aAAa;IAEb;;OAEG;IACH,wBAAwB;IAExB;;OAEG;IACH,0BAA0B;IAE1B;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,uBAAuB;IAEzC;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,uBAAuB;IAEzC;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,uBAAuB;IAEzC;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,uBAAuB;CAC1C;AAED;;;;;;GAMG;AACH,iBAAS,0BAA0B,CAAC,CAAC,SAAS,gBAAgB,EAC5D,IAAI,EAAE,CAAC,GACN,CAAC,GAAG,OAAO,WAAW,CAkQxB;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,241 @@
1
+ /* eslint-disable no-empty-function,@typescript-eslint/no-empty-function */
2
+ /* eslint-disable no-useless-constructor,@typescript-eslint/no-useless-constructor */
3
+ /* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
4
+ /* eslint-disable class-methods-use-this */
5
+ /* eslint-disable max-classes-per-file */
6
+ import { fromLonLat } from 'ol/proj';
7
+ import { unByKey } from 'ol/Observable';
8
+ import BaseEvent from 'ol/events/Event';
9
+ /**
10
+ * UserInteractionsLayerInterface.
11
+ */
12
+ export class UserInteractionsLayerInterface {
13
+ /*
14
+ * Constructor
15
+
16
+ * @param {Object} options Layer options.
17
+ * @param {string} options.userInteractions If true, it listens for user mouse hover and click event.
18
+ * @param {string} options.userClickInteractions If true, it listens for user click event.
19
+ * @param {string} options.userHoverInteractions If true, it listens for user mouse over event.
20
+ * @param {string} options.defaultUserInteractions If true, it adds default listeners for user mouse hover and click event.
21
+ */
22
+ constructor(options = {}) { }
23
+ /**
24
+ * Initialize the layer adding user interactions.
25
+ *
26
+ * @param {ol/Map~Map} map
27
+ */
28
+ attachToMap(map) { }
29
+ /**
30
+ * Terminate the layer unsubscribing user interactions.
31
+ */
32
+ detachFromMap() { }
33
+ /**
34
+ * Activate map listeners events.
35
+ */
36
+ activateUserInteractions() { }
37
+ /**
38
+ * Deactivate map listeners events.
39
+ */
40
+ deactivateUserInteractions() { }
41
+ /**
42
+ * Subscribe on user:click event.
43
+ */
44
+ onClick(callback) { }
45
+ /**
46
+ * Subscribe on user:hover event.
47
+ */
48
+ onHover(callback) { }
49
+ /**
50
+ * Unsubscribe on user:click event.
51
+ */
52
+ unClick(callback) { }
53
+ /**
54
+ * Unsubscribe on user:hover event.
55
+ */
56
+ unHover(callback) { }
57
+ }
58
+ /**
59
+ * Mixin for UserInteractionsLayerInterface. It provide onClick and onHover functions.
60
+ *
61
+ * @param {Class} Base A class to extend with {UserInteractionsLayerInterface} functionnalities.
62
+ * @return {Class} A class that implements {UserInteractionsLayerInterface} class and extends Base;
63
+ * @private
64
+ */
65
+ function UserInteractionsLayerMixin(Base) {
66
+ // @ts-ignore
67
+ return class extends Base {
68
+ constructor(options = {}) {
69
+ super(options);
70
+ const { userInteractions = true, userClickInteractions = true, userHoverInteractions = true, defaultUserInteractions = true, } = options;
71
+ this.userInteractions = userInteractions;
72
+ this.userClickInteractions = userClickInteractions;
73
+ this.userHoverInteractions = userHoverInteractions;
74
+ this.defaultUserInteractions = defaultUserInteractions;
75
+ this.userClickCallbacks = [];
76
+ this.userHoverCallbacks = [];
77
+ this.userClickEventsKeys = [];
78
+ this.userHoverEventsKeys = [];
79
+ this.onUserClickCallback = this.onUserClickCallback.bind(this);
80
+ this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
81
+ // Add mouse event callbacks
82
+ const { onClick, onHover } = options;
83
+ if (this.userInteractions && this.userClickInteractions && onClick) {
84
+ this.onClick(onClick);
85
+ }
86
+ if (this.userInteractions && this.userHoverInteractions && onHover) {
87
+ this.onHover(onHover);
88
+ }
89
+ }
90
+ attachToMap(map) {
91
+ super.attachToMap(map);
92
+ if (this.userInteractions &&
93
+ this.defaultUserInteractions &&
94
+ this.userClickInteractions &&
95
+ this.onFeatureClick) {
96
+ this.onClick(this.onFeatureClick);
97
+ }
98
+ if (this.userInteractions &&
99
+ this.defaultUserInteractions &&
100
+ this.userHoverInteractions &&
101
+ this.onFeatureHover) {
102
+ this.onHover(this.onFeatureHover);
103
+ }
104
+ this.listenEvents();
105
+ }
106
+ detachFromMap() {
107
+ this.unlistenEvents();
108
+ super.detachFromMap();
109
+ }
110
+ listenEvents() {
111
+ this.unlistenEvents();
112
+ this.userClickCallbacks.forEach((callback) => {
113
+ this.userClickEventsKeys.push(this.on(
114
+ // @ts-ignore
115
+ 'user:click', ({ target: { features, layer, coordinate, event }, }) => {
116
+ callback(features, layer, coordinate, event);
117
+ }));
118
+ });
119
+ this.userHoverCallbacks.forEach((callback) => {
120
+ this.userHoverEventsKeys.push(this.on(
121
+ // @ts-ignore
122
+ 'user:hover', ({ target: { features, layer, coordinate, event }, }) => {
123
+ callback(features, layer, coordinate, event);
124
+ }));
125
+ });
126
+ }
127
+ unlistenEvents() {
128
+ unByKey(this.userClickEventsKeys);
129
+ unByKey(this.userHoverEventsKeys);
130
+ this.userClickEventsKeys = [];
131
+ this.userHoverEventsKeys = [];
132
+ }
133
+ /**
134
+ * Listens to click events on the layer.
135
+ * @param {function} callback Callback function, called with the clicked
136
+ * features,
137
+ * the layer instance and the click event.
138
+ */
139
+ onClick(callback) {
140
+ this.userClickCallbacks.push(callback);
141
+ this.activateUserInteractions();
142
+ if (this.map) {
143
+ // If the layer is already attached to the map we reload the events
144
+ this.listenEvents();
145
+ }
146
+ }
147
+ /**
148
+ * Listens to hover events on the layer.
149
+ * @param {function} callback Callback function, called with the clicked
150
+ * features, the layer instance and the click event.
151
+ */
152
+ onHover(callback) {
153
+ this.userHoverCallbacks.push(callback);
154
+ this.activateUserInteractions();
155
+ if (this.map) {
156
+ // If the layer is already attached to the map we reload the events
157
+ this.listenEvents();
158
+ }
159
+ }
160
+ /**
161
+ * Unlistens to click events on the layer.
162
+ * @param {function} callback Callback function, called with the clicked
163
+ * features,
164
+ * the layer instance and the click event.
165
+ */
166
+ unClick(callback) {
167
+ const index = this.userClickCallbacks.indexOf(callback);
168
+ if (index !== -1) {
169
+ return;
170
+ }
171
+ this.userClickCallbacks = this.userClickCallbacks.slice(index, 1);
172
+ if (this.map) {
173
+ // If the layer is already attached to the map we reload the events
174
+ this.listenEvents();
175
+ }
176
+ }
177
+ /**
178
+ * Unlistens to hover events on the layer.
179
+ * @param {function} callback Callback function, called with the clicked
180
+ * features, the layer instance and the click event.
181
+ */
182
+ unHover(callback) {
183
+ const index = this.userHoverCallbacks.indexOf(callback);
184
+ if (index !== -1) {
185
+ return;
186
+ }
187
+ this.userHoverCallbacks = this.userHoverCallbacks.slice(index, 1);
188
+ if (this.map) {
189
+ // If the layer is already attached to the map we reload the events
190
+ this.listenEvents();
191
+ }
192
+ }
193
+ /**
194
+ * Function triggered when the user click the map.
195
+ * @private
196
+ */
197
+ onUserClickCallback(evt) {
198
+ const coordinate = evt.coordinate ||
199
+ fromLonLat(evt.lngLat.toArray());
200
+ const emptyFeatureInfo = {
201
+ features: [],
202
+ layer: this,
203
+ coordinate,
204
+ event: evt,
205
+ };
206
+ return this.getFeatureInfoAtCoordinate(coordinate)
207
+ .then((featureInfo) => {
208
+ const event = new BaseEvent('user:click');
209
+ event.target = featureInfo;
210
+ this.dispatchEvent(event);
211
+ return featureInfo;
212
+ })
213
+ .catch(() => emptyFeatureInfo);
214
+ }
215
+ /**
216
+ * Function triggered when the user move the cursor.
217
+ * @private
218
+ */
219
+ onUserMoveCallback(evt) {
220
+ const coordinate = evt.coordinate ||
221
+ fromLonLat(evt.lngLat.toArray());
222
+ const emptyFeatureInfo = {
223
+ features: [],
224
+ layer: this,
225
+ coordinate,
226
+ event: evt,
227
+ };
228
+ return this.getFeatureInfoAtCoordinate(coordinate)
229
+ .then((featureInfo) => {
230
+ const event = new BaseEvent('user:hover');
231
+ event.target = featureInfo;
232
+ this.dispatchEvent(event);
233
+ return featureInfo;
234
+ })
235
+ .catch(() => emptyFeatureInfo);
236
+ }
237
+ activateUserInteractions() { }
238
+ deactivateUserInteractions() { }
239
+ };
240
+ }
241
+ export default UserInteractionsLayerMixin;
@@ -0,0 +1,5 @@
1
+ export { default as realtimeDefaultStyle } from "./realtimeDefaultStyle";
2
+ export { default as realtimeDelayStyle } from "./realtimeDelayStyle";
3
+ export { default as realtimeSimpleStyle } from "./realtimeSimpleStyle";
4
+ export * from "./realtimeDefaultStyle";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/styles/index.js"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- export { default as trackerDefaultStyle } from "./trackerDefaultStyle";
2
- export { default as trackerDelayStyle } from "./trackerDelayStyle";
3
- export { default as trackerSimpleStyle } from "./trackerSimpleStyle";
4
- export * from "./trackerDefaultStyle";
1
+ export { default as realtimeDefaultStyle } from './realtimeDefaultStyle';
2
+ export { default as realtimeDelayStyle } from './realtimeDelayStyle';
3
+ export { default as realtimeSimpleStyle } from './realtimeSimpleStyle';
4
+ export * from './realtimeDefaultStyle';
@@ -0,0 +1,36 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
2
+ /**
3
+ * Draw circle delay background
4
+ *
5
+ * @private
6
+ */
7
+ export declare const getDelayBgCanvas: (origin: number, radius: number, color: string) => import("../../types").AnyCanvas | null;
8
+ /**
9
+ * Draw delay text
10
+ *
11
+ * @private
12
+ */
13
+ export declare const getDelayTextCanvas: (text: string, fontSize: number, font: string, delayColor: string, delayOutlineColor?: string, pixelRatio?: number) => import("../../types").AnyCanvas | null;
14
+ /**
15
+ * Draw colored circle with black border
16
+ *
17
+ * @private
18
+ */
19
+ export declare const getCircleCanvas: (origin: number, radius: number, color: string, hasStroke: boolean, hasDash: boolean, pixelRatio: number) => import("../../types").AnyCanvas | null;
20
+ /**
21
+ * Draw text in the circle
22
+ *
23
+ * @private
24
+ */
25
+ export declare const getTextCanvas: (text: string, origin: number, textSize: number, fillColor: string, strokeColor: string, hasStroke: boolean, pixelRatio: number) => import("../../types").AnyCanvas | null;
26
+ /**
27
+ * A tracker style that take in account the delay.
28
+ *
29
+ * @param {RealtimeTrajectory} trajectory The trajectory to render.
30
+ * @param {ViewState} viewState The view state of the map.
31
+ * @param {RealtimeStyleOptions} options Some options to change the rendering
32
+ * @return a canvas
33
+ */
34
+ declare const realtimeDefaultStyle: RealtimeStyleFunction;
35
+ export default realtimeDefaultStyle;
36
+ //# sourceMappingURL=realtimeDefaultStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeDefaultStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDefaultStyle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAMrB;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,WACnB,MAAM,UACN,MAAM,SACP,MAAM,2CAmBd,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SACvB,MAAM,YACF,MAAM,QACV,MAAM,cACA,MAAM,sBACC,MAAM,eACb,MAAM,2CA0BnB,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,eAAe,WAClB,MAAM,UACN,MAAM,SACP,MAAM,aACF,OAAO,WACT,OAAO,cACJ,MAAM,2CAiCnB,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,aAAa,SAClB,MAAM,UACJ,MAAM,YACJ,MAAM,aACL,MAAM,eACJ,MAAM,aACR,OAAO,cACN,MAAM,2CAmCnB,CAAC;AAKF;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,EAAE,qBAkO3B,CAAC;AACF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,275 @@
1
+ import createCanvas from '../utils/createCanvas';
2
+ /** @private */
3
+ const cacheDelayBg = {};
4
+ /**
5
+ * Draw circle delay background
6
+ *
7
+ * @private
8
+ */
9
+ export const getDelayBgCanvas = (origin, radius, color) => {
10
+ const key = `${origin}, ${radius}, ${color}`;
11
+ if (!cacheDelayBg[key]) {
12
+ const canvas = createCanvas(origin * 2, origin * 2);
13
+ if (canvas) {
14
+ const ctx = canvas.getContext('2d');
15
+ if (!ctx) {
16
+ return null;
17
+ }
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
+ }
25
+ }
26
+ return cacheDelayBg[key];
27
+ };
28
+ /** @private */
29
+ const cacheDelayText = {};
30
+ /**
31
+ * Draw delay text
32
+ *
33
+ * @private
34
+ */
35
+ export const getDelayTextCanvas = (text, fontSize, font, delayColor, delayOutlineColor = '#000', pixelRatio = 1) => {
36
+ const key = `${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
37
+ if (!cacheDelayText[key]) {
38
+ const canvas = createCanvas(Math.ceil(text.length * fontSize), Math.ceil(fontSize + 8 * pixelRatio));
39
+ if (canvas) {
40
+ const ctx = canvas.getContext('2d');
41
+ if (!ctx) {
42
+ return null;
43
+ }
44
+ ctx.font = font;
45
+ ctx.textAlign = 'left';
46
+ ctx.textBaseline = 'middle';
47
+ ctx.font = font;
48
+ ctx.fillStyle = delayColor;
49
+ ctx.strokeStyle = delayOutlineColor;
50
+ ctx.lineWidth = 1.5 * pixelRatio;
51
+ ctx.strokeText(text, 0, fontSize);
52
+ ctx.fillText(text, 0, fontSize);
53
+ cacheDelayText[key] = canvas;
54
+ }
55
+ }
56
+ return cacheDelayText[key];
57
+ };
58
+ /** @private */
59
+ const cacheCircle = {};
60
+ /**
61
+ * Draw colored circle with black border
62
+ *
63
+ * @private
64
+ */
65
+ export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
66
+ const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
67
+ if (!cacheCircle[key]) {
68
+ const canvas = createCanvas(origin * 2, origin * 2);
69
+ if (canvas) {
70
+ const ctx = canvas.getContext('2d');
71
+ if (!ctx) {
72
+ return null;
73
+ }
74
+ ctx.fillStyle = color;
75
+ if (hasStroke) {
76
+ ctx.lineWidth = 1 * pixelRatio;
77
+ ctx.strokeStyle = '#000000';
78
+ }
79
+ ctx.beginPath();
80
+ ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
81
+ ctx.fill();
82
+ if (hasDash) {
83
+ ctx.setLineDash([5, 3]);
84
+ }
85
+ if (hasStroke) {
86
+ ctx.stroke();
87
+ }
88
+ cacheCircle[key] = canvas;
89
+ }
90
+ }
91
+ return cacheCircle[key];
92
+ };
93
+ /** @private */
94
+ const cacheText = {};
95
+ /**
96
+ * Draw text in the circle
97
+ *
98
+ * @private
99
+ */
100
+ export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
101
+ const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
102
+ if (!cacheText[key]) {
103
+ const canvas = createCanvas(origin * 2, origin * 2);
104
+ if (canvas) {
105
+ const ctx = canvas.getContext('2d');
106
+ if (!ctx) {
107
+ return null;
108
+ }
109
+ // Draw a stroke to the text only if a provider provides realtime but we don't use it.
110
+ if (hasStroke) {
111
+ ctx.save();
112
+ ctx.textBaseline = 'middle';
113
+ ctx.textAlign = 'center';
114
+ ctx.font = `bold ${textSize + 2}px Arial`;
115
+ ctx.strokeStyle = strokeColor;
116
+ ctx.strokeText(text, origin, origin);
117
+ ctx.restore();
118
+ }
119
+ // Draw a text
120
+ ctx.textBaseline = 'middle';
121
+ ctx.textAlign = 'center';
122
+ ctx.fillStyle = fillColor;
123
+ ctx.font = `bold ${textSize}px Arial`;
124
+ ctx.strokeStyle = strokeColor;
125
+ ctx.strokeText(text, origin, origin);
126
+ ctx.fillText(text, origin, origin);
127
+ cacheText[key] = canvas;
128
+ }
129
+ }
130
+ return cacheText[key];
131
+ };
132
+ /** @private */
133
+ const cache = {};
134
+ /**
135
+ * A tracker style that take in account the delay.
136
+ *
137
+ * @param {RealtimeTrajectory} trajectory The trajectory to render.
138
+ * @param {ViewState} viewState The view state of the map.
139
+ * @param {RealtimeStyleOptions} options Some options to change the rendering
140
+ * @return a canvas
141
+ */
142
+ const realtimeDefaultStyle = (trajectory, viewState, options) => {
143
+ const { hoverVehicleId, selectedVehicleId, useDelayStyle, delayOutlineColor = '#000', delayDisplay = 300000, getRadius = () => 0, getBgColor = () => '#000', getDelayColor = () => '#000', getDelayText = () => null, getTextColor = () => '#000', getTextSize = () => 0, getMaxRadiusForText = () => 10, getMaxRadiusForStrokeAndDelay = () => 7, } = options;
144
+ const { zoom, pixelRatio = 1 } = viewState;
145
+ let { type } = trajectory.properties;
146
+ const { train_id: id, line, delay, state, operator_provides_realtime_journey: operatorProvidesRealtime, } = trajectory.properties;
147
+ let { name, text_color: textColor, color } = line || {};
148
+ const cancelled = state === 'JOURNEY_CANCELLED';
149
+ if (!type) {
150
+ type = 'Rail';
151
+ }
152
+ if (!name) {
153
+ name = 'I';
154
+ }
155
+ if (!textColor) {
156
+ textColor = '#000000';
157
+ }
158
+ if (color && color[0] !== '#') {
159
+ color = `#${color}`;
160
+ }
161
+ if (textColor[0] !== '#') {
162
+ textColor = `#${textColor}`;
163
+ }
164
+ const z = Math.min(Math.floor(zoom || 1), 16);
165
+ const hover = !!(hoverVehicleId && hoverVehicleId === id);
166
+ const selected = !!(selectedVehicleId && selectedVehicleId === id);
167
+ // Calcul the radius of the circle
168
+ let radius = getRadius(type, z) * pixelRatio;
169
+ const isDisplayStrokeAndDelay = radius >= getMaxRadiusForStrokeAndDelay() * pixelRatio;
170
+ if (hover || selected) {
171
+ radius = isDisplayStrokeAndDelay
172
+ ? radius + 5 * pixelRatio
173
+ : 14 * pixelRatio;
174
+ }
175
+ const isDisplayText = radius > getMaxRadiusForText() * pixelRatio;
176
+ // Optimize the cache key, very important in high zoom level
177
+ let key = `${radius}${hover || selected}`;
178
+ if (useDelayStyle) {
179
+ key += `${operatorProvidesRealtime}${delay}`;
180
+ if (isDisplayStrokeAndDelay) {
181
+ key += `${cancelled}`;
182
+ }
183
+ }
184
+ else {
185
+ key += `${color || type}`;
186
+ if (isDisplayStrokeAndDelay) {
187
+ key += `${cancelled}${delay}`;
188
+ }
189
+ }
190
+ if (isDisplayText) {
191
+ key += `${name}${textColor}`;
192
+ }
193
+ if (!cache[key]) {
194
+ if (radius === 0) {
195
+ return null;
196
+ }
197
+ const margin = 1 * pixelRatio;
198
+ const radiusDelay = radius + 2 * pixelRatio;
199
+ const markerSize = radius * 2;
200
+ const size = radiusDelay * 2 + margin * 2;
201
+ const origin = size / 2;
202
+ // Draw circle delay background
203
+ let delayBg = null;
204
+ if (isDisplayStrokeAndDelay && delay !== null) {
205
+ delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
206
+ }
207
+ // Show delay if feature is hovered or if delay is above 5mins.
208
+ let delayText = null;
209
+ let fontSize = 0;
210
+ if (isDisplayStrokeAndDelay &&
211
+ (hover || (delay || 0) >= delayDisplay || cancelled)) {
212
+ // Draw delay text
213
+ fontSize =
214
+ Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
215
+ const text = getDelayText(delay, cancelled);
216
+ if (text) {
217
+ delayText = getDelayTextCanvas(text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
218
+ }
219
+ }
220
+ // Draw colored circle with black border
221
+ let circleFillColor;
222
+ if (useDelayStyle) {
223
+ circleFillColor = getDelayColor(delay, cancelled);
224
+ }
225
+ else {
226
+ circleFillColor = color || getBgColor(type);
227
+ }
228
+ const hasStroke = isDisplayStrokeAndDelay || hover || selected;
229
+ const hasDash = !!isDisplayStrokeAndDelay &&
230
+ !!useDelayStyle &&
231
+ delay === null &&
232
+ operatorProvidesRealtime === 'yes';
233
+ const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
234
+ // Create the canvas
235
+ const width = size + ((delayText === null || delayText === void 0 ? void 0 : delayText.width) || 0) * 2;
236
+ const height = size;
237
+ const canvas = createCanvas(width, height);
238
+ if (canvas) {
239
+ const ctx = canvas.getContext('2d');
240
+ if (!ctx) {
241
+ return null;
242
+ }
243
+ // The renderTrajectories will center the image on the vehicle positions.
244
+ const originX = (delayText === null || delayText === void 0 ? void 0 : delayText.width) || 0;
245
+ if (delayBg) {
246
+ ctx.drawImage(delayBg, originX, 0);
247
+ }
248
+ if (circle) {
249
+ ctx.drawImage(circle, originX, 0);
250
+ }
251
+ // Draw text in the circle
252
+ let circleText = null;
253
+ if (isDisplayText) {
254
+ const fontSize2 = Math.max(radius, 10);
255
+ const textSize = getTextSize(ctx, markerSize, name, fontSize2);
256
+ const textColor2 = !useDelayStyle
257
+ ? textColor || getTextColor(type)
258
+ : '#000000';
259
+ const hasStroke2 = !!useDelayStyle &&
260
+ delay === null &&
261
+ operatorProvidesRealtime === 'yes';
262
+ circleText = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
263
+ }
264
+ if (circleText) {
265
+ ctx.drawImage(circleText, originX, 0);
266
+ }
267
+ if (delayText) {
268
+ ctx.drawImage(delayText, originX + Math.ceil(origin + radiusDelay) + margin, Math.ceil(origin - fontSize));
269
+ }
270
+ cache[key] = canvas;
271
+ }
272
+ }
273
+ return cache[key];
274
+ };
275
+ export default realtimeDefaultStyle;
@@ -0,0 +1,12 @@
1
+ import type { RealtimeStyleFunction } from '../../types';
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 const realtimeDelayStyle: RealtimeStyleFunction;
11
+ export default realtimeDelayStyle;
12
+ //# sourceMappingURL=realtimeDelayStyle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"realtimeDelayStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDelayStyle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,qBAAqB,EACtB,MAAM,aAAa,CAAC;AACrB;;;;;;;GAOG;AACH,QAAA,MAAM,kBAAkB,EAAE,qBASzB,CAAC;AACF,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import realtimeDefaultStyle from './realtimeDefaultStyle';
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
+ const realtimeDelayStyle = (trajectory, viewState, options) => {
11
+ return realtimeDefaultStyle(trajectory, viewState, Object.assign(Object.assign({}, options), { useDelayStyle: true }));
12
+ };
13
+ export default realtimeDelayStyle;