mobility-toolbox-js 2.0.0 → 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 (271) 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 +35 -0
  7. package/api/StopsAPI.d.ts +38 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +36 -0
  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/{tralis/typedefs.js → typedefs.js} +4 -10
  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 +57 -0
  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 +341 -0
  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 -0
  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/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +4 -9
  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 +35 -6
  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 +21 -23
  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 +60 -60
  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 +13 -2
  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 +5 -12
  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 -20
  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 +13 -18
  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 +10 -2
  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 +25 -35
  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 -0
  130. package/mapbox/index.d.ts +6 -0
  131. package/mapbox/index.d.ts.map +1 -0
  132. package/mapbox/index.js +5 -3
  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 +78 -95
  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 -0
  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 +60005 -0
  152. package/mbt.js.map +7 -0
  153. package/mbt.min.js +1084 -0
  154. package/mbt.min.js.map +7 -0
  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 +44 -56
  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 +546 -667
  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 +10 -16
  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 -0
  167. package/ol/index.d.ts +6 -0
  168. package/ol/index.d.ts.map +1 -0
  169. package/ol/index.js +4 -12
  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 +147 -166
  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 +79 -348
  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 +329 -368
  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 +13 -259
  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 +62 -68
  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 +27 -32
  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 +74 -66
  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 -0
  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 +23 -25
  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 +37 -44
  206. package/ol/styles/index.d.ts +3 -0
  207. package/ol/styles/index.d.ts.map +1 -0
  208. package/package.json +98 -177
  209. package/setupTests.d.ts +2 -0
  210. package/setupTests.d.ts.map +1 -0
  211. package/setupTests.js +26 -0
  212. package/types/common.d.ts +122 -0
  213. package/types/index.d.ts +11 -0
  214. package/types/realtime.d.ts +320 -0
  215. package/types/routing.d.ts +206 -0
  216. package/types/stops.d.ts +143 -0
  217. package/README.md +0 -23
  218. package/api/routing/RoutingAPI.js +0 -44
  219. package/api/routing/RoutingAPI.test.js +0 -41
  220. package/api/stops/StopsAPI.js +0 -41
  221. package/api/stops/StopsAPI.test.js +0 -34
  222. package/api/tralis/TralisAPI.js +0 -731
  223. package/api/tralis/TralisAPI.test.js +0 -75
  224. package/api/tralis/TralisAPIUtils.js +0 -73
  225. package/api/tralis/WebSocketConnector.js +0 -338
  226. package/api/tralis/WebSocketConnector.test.js +0 -356
  227. package/common/Tracker.js +0 -197
  228. package/common/api/api.js +0 -64
  229. package/common/api/api.test.js +0 -68
  230. package/common/controls/Control.js +0 -146
  231. package/common/controls/Control.test.js +0 -98
  232. package/common/layers/Layer.js +0 -404
  233. package/common/layers/Layer.test.js +0 -585
  234. package/common/mixins/CopyrightMixin.js +0 -48
  235. package/common/mixins/SearchMixin.js +0 -176
  236. package/common/mixins/TralisLayerMixin.js +0 -930
  237. package/common/styles/trackerDefaultStyle.js +0 -333
  238. package/common/styles/trackerSimpleStyle.js +0 -22
  239. package/common/trackerConfig.js +0 -190
  240. package/common/trackerConfig.test.js +0 -25
  241. package/common/utils/createTrackerFilters.js +0 -87
  242. package/common/utils/createTrackerFilters.test.js +0 -95
  243. package/common/utils/getMapboxMapCopyrights.test.js +0 -47
  244. package/common/utils/getMapboxStyleUrl.js +0 -32
  245. package/common/utils/removeDuplicate.test.js +0 -22
  246. package/common/utils/timeUtils.test.js +0 -16
  247. package/index.js.map +0 -1
  248. package/mapbox/layers/Layer.test.js +0 -202
  249. package/mapbox/layers/TralisLayer.js +0 -329
  250. package/mapbox/layers/TralisLayer.test.js +0 -40
  251. package/mapbox/utils.js +0 -46
  252. package/module.js +0 -23
  253. package/ol/README.md +0 -0
  254. package/ol/controls/CopyrightControl.test.js +0 -211
  255. package/ol/controls/RoutingControl.test.js +0 -216
  256. package/ol/controls/StopFinderControl.test.js +0 -59
  257. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  258. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  259. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  260. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  261. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  262. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  263. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  264. package/ol/layers/Layer.test.js +0 -197
  265. package/ol/layers/MapboxLayer.test.js +0 -186
  266. package/ol/layers/MapboxStyleLayer.test.js +0 -262
  267. package/ol/layers/RoutingLayer.test.js +0 -49
  268. package/ol/layers/TralisLayer.js +0 -359
  269. package/ol/layers/TralisLayer.test.js +0 -97
  270. package/ol/layers/VectorLayer.test.js +0 -98
  271. package/ol/layers/WMSLayer.test.js +0 -84
@@ -1,7 +1,7 @@
1
1
  import { unByKey } from 'ol/Observable';
2
2
  import { transformExtent } from 'ol/proj';
3
- import LayerCommon from '../../common/layers/Layer';
4
-
3
+ import LayerCommon from '../../common/layers/LayerCommon';
4
+ import userInteractionsMixin from '../../common/mixins/UserInteractionsLayerMixin';
5
5
  /**
6
6
  * A class representing a layer to display on an OpenLayers map.
7
7
  *
@@ -17,102 +17,85 @@ import LayerCommon from '../../common/layers/Layer';
17
17
  * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
18
18
  * @extends {Layer}
19
19
  */
20
- class Layer extends LayerCommon {
21
- /**
22
- * Initialize the layer and listen to user events.
23
- * @param {ol/Map~Map} map
24
- */
25
- init(map) {
26
- super.init(map);
27
-
28
- if (!this.map) {
29
- return;
20
+ class Layer extends userInteractionsMixin(LayerCommon) {
21
+ /**
22
+ * Initialize the layer and listen to user events.
23
+ * @param {mapboxgl.Map|maplibregl.Map} map
24
+ */
25
+ attachToMap(map) {
26
+ super.attachToMap(map);
27
+ if (!this.map) {
28
+ return;
29
+ }
30
+ if (this.userInteractions) {
31
+ this.toggleVisibleListeners();
32
+ this.onChangeVisibleKey = this.on(
33
+ // @ts-ignore
34
+ 'change:visible', this.toggleVisibleListeners);
35
+ }
30
36
  }
31
-
32
- if (this.isClickActive || this.isHoverActive) {
33
- this.toggleVisibleListeners();
34
- this.onChangeVisibleKey = this.on(
35
- 'change:visible',
36
- this.toggleVisibleListeners,
37
- );
37
+ detachFromMap() {
38
+ if (this.map) {
39
+ this.deactivateUserInteractions();
40
+ // @ts-ignore
41
+ unByKey(this.onChangeVisibleKey);
42
+ }
43
+ super.detachFromMap();
38
44
  }
39
- }
40
-
41
- terminate(map) {
42
- if (this.map) {
43
- this.map.off('mousemove', this.onUserMoveCallback);
44
- this.map.off('click', this.onUserClickCallback);
45
- unByKey(this.onChangeVisibleKey);
45
+ activateUserInteractions() {
46
+ var _a, _b;
47
+ this.deactivateUserInteractions();
48
+ if (this.map &&
49
+ this.userInteractions &&
50
+ this.userClickInteractions &&
51
+ ((_a = this.userClickCallbacks) === null || _a === void 0 ? void 0 : _a.length)) {
52
+ this.map.on('click', this.onUserClickCallback);
53
+ }
54
+ if (this.map &&
55
+ this.userInteractions &&
56
+ this.userHoverInteractions &&
57
+ ((_b = this.userHoverCallbacks) === null || _b === void 0 ? void 0 : _b.length)) {
58
+ this.map.on('mousemove', this.onUserMoveCallback);
59
+ }
46
60
  }
47
- super.terminate(map);
48
- }
49
-
50
- /**
51
- * Function triggered when the user click the map.
52
- * @private
53
- */
54
- onUserClickCallback(evt) {
55
- super.onUserClickCallback({ coordinate: evt.lngLat.toArray(), ...evt });
56
- }
57
-
58
- /**
59
- * Function triggered when the user moves the cursor over the map.
60
- * @private
61
- */
62
- onUserMoveCallback(evt) {
63
- super.onUserMoveCallback({ coordinate: evt.lngLat.toArray(), ...evt });
64
- }
65
-
66
- /**
67
- * Toggle listeners needed when a layer is avisible or not.
68
- * @private
69
- */
70
- toggleVisibleListeners() {
71
- if (this.visible) {
72
- if (this.isClickActive) {
73
- this.map.on('click', this.onUserClickCallback);
74
- }
75
-
76
- if (this.isHoverActive) {
77
- this.map.on('mousemove', this.onUserMoveCallback);
78
- }
79
- } else {
80
- if (this.isClickActive) {
81
- this.map.off('click', this.onUserClickCallback);
82
- }
83
-
84
- if (this.isHoverActive) {
85
- this.map.off('mousemove', this.onUserMoveCallback);
86
- }
61
+ deactivateUserInteractions() {
62
+ if (this.map) {
63
+ this.map.off('mousemove', this.onUserMoveCallback);
64
+ this.map.off('click', this.onUserClickCallback);
65
+ }
66
+ }
67
+ /**
68
+ * Toggle listeners needed when a layer is avisible or not.
69
+ * @private
70
+ */
71
+ toggleVisibleListeners() {
72
+ if (this.visible) {
73
+ this.activateUserInteractions();
74
+ }
75
+ else {
76
+ this.deactivateUserInteractions();
77
+ }
78
+ }
79
+ /**
80
+ * Returns the current extent in mercator coordinates.
81
+ */
82
+ getMercatorExtent() {
83
+ const bounds = this.map.getBounds().toArray();
84
+ return transformExtent([...bounds[0], ...bounds[1]], 'EPSG:4326', 'EPSG:3857');
85
+ }
86
+ /**
87
+ * Returns the equivalent zoom in Openlayers.
88
+ */
89
+ getOlZoom() {
90
+ return this.map.getZoom() + 1;
91
+ }
92
+ /**
93
+ * Create a copy of the Layer.
94
+ * @param {Object} newOptions Options to override
95
+ * @return {Layer} A Layer
96
+ */
97
+ clone(newOptions) {
98
+ return new Layer(Object.assign(Object.assign({}, this.options), newOptions));
87
99
  }
88
- }
89
-
90
- /**
91
- * Returns the current extent in mercator coordinates.
92
- */
93
- getMercatorExtent() {
94
- const bounds = this.map.getBounds().toArray();
95
- return transformExtent(
96
- [...bounds[0], ...bounds[1]],
97
- 'EPSG:4326',
98
- 'EPSG:3857',
99
- );
100
- }
101
-
102
- /**
103
- * Returns the equivalent zoom in Openlayers.
104
- */
105
- getOlZoom() {
106
- return this.map.getZoom() + 1;
107
- }
108
-
109
- /**
110
- * Create a copy of the Layer.
111
- * @param {Object} newOptions Options to override
112
- * @return {Layer} A Layer
113
- */
114
- clone(newOptions) {
115
- return new Layer({ ...this.options, ...newOptions });
116
- }
117
100
  }
118
101
  export default Layer;
@@ -0,0 +1,181 @@
1
+ /// <reference types="mapbox-gl" />
2
+ import { Coordinate } from 'ol/coordinate';
3
+ import { Feature } from 'ol';
4
+ import Layer from './Layer';
5
+ import type { AnyMapboxMap, LayerGetFeatureInfoResponse } from '../../types';
6
+ import type { RealtimeTrajectory } from '../../api/typedefs';
7
+ declare const RealtimeLayer_base: {
8
+ new (options: import("../../common/mixins/RealtimeLayerMixin").RealtimeLayerMixinOptions): {
9
+ [x: string]: any;
10
+ debug: boolean;
11
+ trajectories?: {
12
+ [key: string]: GeoJSONFeature;
13
+ } | undefined;
14
+ canvas?: import("../../types").AnyCanvas | undefined;
15
+ mode: import("../../types").RealtimeMode;
16
+ api: import("../../api/RealtimeAPI").default;
17
+ tenant: string;
18
+ time?: Date | undefined;
19
+ live?: boolean | undefined;
20
+ speed?: number | undefined;
21
+ filter?: Function | undefined;
22
+ sort?: Function | undefined;
23
+ style?: import("../../types").RealtimeStyleFunction | undefined;
24
+ styleOptions?: import("../../types").RealtimeStyleOptions | undefined;
25
+ pixelRatio?: number | undefined;
26
+ minZoomInterpolation: number;
27
+ isUpdateBboxOnMoveEnd: boolean;
28
+ hoverVehicleId?: string | undefined;
29
+ selectedVehicleId?: string | undefined;
30
+ renderState?: import("../../types").RealtimeRenderState | undefined;
31
+ useRequestAnimationFrame?: boolean | undefined;
32
+ useDebounce?: boolean | undefined;
33
+ useThrottle?: boolean | undefined;
34
+ mots?: import("../../types").RealtimeMot[] | undefined;
35
+ motsByZoom: import("../../types").RealtimeMot[][];
36
+ generalizationLevel?: import("../../types").RealtimeGeneralizationLevel | undefined;
37
+ generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
38
+ renderTimeIntervalByZoom: number[];
39
+ format: import("ol/format/GeoJSON").default;
40
+ requestId?: number | undefined;
41
+ updateTimeInterval?: number | undefined;
42
+ updateTimeDelay?: number | undefined;
43
+ visibilityRef: import("ol/events").EventsKey;
44
+ selectedVehicle: GeoJSONFeature;
45
+ getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
46
+ getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
47
+ getRenderTimeIntervalByZoom: (zoom: number) => number;
48
+ throttleRenderTrajectories: (viewState: import("../../types").ViewState, noInterpolate?: boolean | undefined) => void;
49
+ debounceRenderTrajectories: (viewState: import("../../types").ViewState, noInterpolate?: boolean | undefined) => void;
50
+ onStart?: ((realtimeLayer: any) => void) | undefined;
51
+ onStop?: ((realtimeLayer: any) => void) | undefined;
52
+ defineProperties(options: import("../../common/mixins/RealtimeLayerMixin").RealtimeLayerMixinOptions): void;
53
+ attachToMap(map: any): void;
54
+ detachFromMap(): void;
55
+ start(): void;
56
+ startUpdateTime(): void;
57
+ stop(): void;
58
+ stopUpdateTime(): void;
59
+ renderTrajectoriesInternal(viewState: import("../../types").ViewState, noInterpolate?: boolean): boolean;
60
+ renderTrajectories(viewState: import("../../types").ViewState | undefined, noInterpolate: boolean | undefined): void;
61
+ setBbox(extent?: [number, number, number, number] | undefined, zoom?: number | undefined): void;
62
+ getRefreshTimeInMs(zoom?: number | undefined): number;
63
+ getVehicle(filterFc: Function): GeoJSONFeature[];
64
+ getFeatureInfoAtCoordinate(coordinate: Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<{
65
+ layer: any;
66
+ features: Feature<import("ol/geom/Geometry").default>[];
67
+ coordinate: Coordinate;
68
+ }>;
69
+ getTrajectoryInfos(id: string): Promise<{
70
+ stopSequence: import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature[]>;
71
+ fullTrajectory: import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<import("../../types").RealtimeFullTrajectory> | import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature[]>;
72
+ }>;
73
+ purgeOutOfDateTrajectories(): void;
74
+ purgeTrajectory(trajectory: GeoJSONFeature, extent: [number, number, number, number], zoom: number): boolean;
75
+ addTrajectory(trajectory: GeoJSONFeature): void;
76
+ removeTrajectory(trajectoryOrId: any): void;
77
+ onZoomEnd(): void;
78
+ onDocumentVisibilityChange(): void;
79
+ onTrajectoryMessage(data: import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<GeoJSONFeature>): void;
80
+ onDeleteTrajectoryMessage(data: import("../../common/api/WebSocketAPI").WebSocketAPIMessageEventData<string>): void;
81
+ onFeatureHover(features: Feature<import("ol/geom/Geometry").default>[], layer: import("../../types").AnyRealtimeLayer, coordinate: Coordinate): void;
82
+ onFeatureClick(features: Feature<import("ol/geom/Geometry").default>[], layer: import("../../types").AnyRealtimeLayer, coordinate: Coordinate): void;
83
+ };
84
+ } & typeof Layer;
85
+ /**
86
+ * Responsible for loading and display data from a Realtime service.
87
+ *
88
+ * @example
89
+ * import { RealtimeLayer } from 'mobility-toolbox-js/mapbox';
90
+ *
91
+ * const layer = new RealtimeLayer({
92
+ * url: [yourUrl],
93
+ * apiKey: [yourApiKey],
94
+ * });
95
+ *
96
+ *
97
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
98
+ *
99
+ * @extends {Layer}
100
+ * @implements {RealtimeLayerInterface}
101
+ */
102
+ declare class RealtimeLayer extends RealtimeLayer_base {
103
+ constructor(options?: {});
104
+ /**
105
+ * Initialize the layer.
106
+ *
107
+ * @param {mapboxgl.Map} map A [mapbox Map](https://docs.mapbox.com/mapbox-gl-js/api/map/).
108
+ * @param {string} beforeId Layer's id before which we want to add the new layer.
109
+ * @override
110
+ */
111
+ attachToMap(map: AnyMapboxMap, beforeId: string): void;
112
+ /**
113
+ * Remove listeners from the Mapbox Map.
114
+ */
115
+ detachFromMap(): void;
116
+ /**
117
+ * Start updating vehicles position.
118
+ *
119
+ * @listens {mapboxgl.map.event:zoomend} Listen to zoom end event.
120
+ * @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
121
+ * @override
122
+ */
123
+ start(): void;
124
+ /**
125
+ * Stop updating vehicles position, and unlisten events.
126
+ *
127
+ * @override
128
+ */
129
+ stop(): void;
130
+ onLoad(): void;
131
+ /**
132
+ * Function triggered when the user moves the cursor over the map.
133
+ * @override
134
+ */
135
+ onUserMoveCallback(evt: mapboxgl.MapLayerMouseEvent | maplibregl.MapMouseEvent): void;
136
+ /**
137
+ * Render the trajectories using current map's size, resolution and rotation.
138
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
139
+ * @overrides
140
+ */
141
+ renderTrajectories(noInterpolate?: boolean): void;
142
+ /**
143
+ * Return the delay in ms before the next rendering.
144
+ */
145
+ getRefreshTimeInMs(): number;
146
+ getFeatureInfoAtCoordinate(coordinate: Coordinate, options?: {}): Promise<LayerGetFeatureInfoResponse>;
147
+ onVisibilityChange(): void;
148
+ /**
149
+ * Remove the trajectory form the list if necessary.
150
+ *
151
+ * @private
152
+ */
153
+ purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
154
+ /**
155
+ * Send the current bbox to the websocket
156
+ */
157
+ setBbox(extent?: [number, number, number, number], zoom?: number): void;
158
+ /**
159
+ * Callback on 'move' event.
160
+ *
161
+ * @private
162
+ */
163
+ onMove(): void;
164
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
165
+ /**
166
+ * Send the new BBOX to the websocket.
167
+ *
168
+ * @private
169
+ * @override
170
+ */
171
+ onMoveEnd(): void;
172
+ /**
173
+ * Update the cursor style when hovering a vehicle.
174
+ *
175
+ * @private
176
+ * @override
177
+ */
178
+ onFeatureHover(features: Feature[], layer: RealtimeLayer, coordinate: Coordinate): void;
179
+ }
180
+ export default RealtimeLayer;
181
+ //# sourceMappingURL=RealtimeLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RealtimeLayer.d.ts","sourceRoot":"","sources":["../../../src/mapbox/layers/RealtimeLayer.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7D;;;;;;;;;;;;;;;;GAgBG;AAEH,cAAM,aAAc,SAAQ,kBAAY;gBAC1B,OAAO,KAAK;IAqBxB;;;;;;OAMG;IAEH,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM;IAuC/C;;OAEG;IACH,aAAa;IAkBb;;;;;;OAMG;IACH,KAAK;IAQL;;;;OAIG;IACH,IAAI;IASJ,MAAM;IASN;;;OAGG;IACH,kBAAkB,CAChB,GAAG,EAAE,QAAQ,CAAC,kBAAkB,GAAG,UAAU,CAAC,aAAa;IAQ7D;;;;OAIG;IAEH,kBAAkB,CAAC,aAAa,CAAC,EAAE,OAAe;IAuDlD;;OAEG;IACH,kBAAkB;IAIlB,0BAA0B,CACxB,UAAU,EAAE,UAAU,EACtB,OAAO,KAAK,GACX,OAAO,CAAC,2BAA2B,CAAC;IAQvC,kBAAkB;IAclB;;;;OAIG;IACH,eAAe,CACb,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EACxC,IAAI,EAAE,MAAM;IASd;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM;IAUhE;;;;OAIG;IACH,MAAM;IAIN,0BAA0B,CACxB,SAAS,EAAE,SAAS,EACpB,aAAa,GAAE,OAAe;IAahC;;;;;OAKG;IACH,SAAS;IAQT;;;;;OAKG;IACH,cAAc,CACZ,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,aAAa,EACpB,UAAU,EAAE,UAAU;CAOzB;AAED,eAAe,aAAa,CAAC"}
@@ -0,0 +1,276 @@
1
+ import { fromLonLat } from 'ol/proj';
2
+ import { unByKey } from 'ol/Observable';
3
+ import { getWidth, getHeight } from 'ol/extent';
4
+ import transformRotate from '@turf/transform-rotate';
5
+ import { point } from '@turf/helpers';
6
+ import mixin from '../../common/mixins/RealtimeLayerMixin';
7
+ import Layer from './Layer';
8
+ import { getSourceCoordinates, getMercatorResolution } from '../utils';
9
+ /**
10
+ * Responsible for loading and display data from a Realtime service.
11
+ *
12
+ * @example
13
+ * import { RealtimeLayer } from 'mobility-toolbox-js/mapbox';
14
+ *
15
+ * const layer = new RealtimeLayer({
16
+ * url: [yourUrl],
17
+ * apiKey: [yourApiKey],
18
+ * });
19
+ *
20
+ *
21
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
22
+ *
23
+ * @extends {Layer}
24
+ * @implements {RealtimeLayerInterface}
25
+ */
26
+ // @ts-ignore
27
+ class RealtimeLayer extends mixin(Layer) {
28
+ constructor(options = {}) {
29
+ super(Object.assign({}, options));
30
+ /** @ignore */
31
+ this.onLoad = this.onLoad.bind(this);
32
+ /** @ignore */
33
+ this.onMove = this.onMove.bind(this);
34
+ /** @ignore */
35
+ this.onMoveEnd = this.onMoveEnd.bind(this);
36
+ /** @ignore */
37
+ this.onZoomEnd = this.onZoomEnd.bind(this);
38
+ /** @ignore */
39
+ this.onVisibilityChange = this.onVisibilityChange.bind(this);
40
+ }
41
+ /**
42
+ * Initialize the layer.
43
+ *
44
+ * @param {mapboxgl.Map} map A [mapbox Map](https://docs.mapbox.com/mapbox-gl-js/api/map/).
45
+ * @param {string} beforeId Layer's id before which we want to add the new layer.
46
+ * @override
47
+ */
48
+ // @ts-ignore
49
+ attachToMap(map, beforeId) {
50
+ if (!map) {
51
+ return;
52
+ }
53
+ super.attachToMap(map);
54
+ this.source = {
55
+ type: 'canvas',
56
+ canvas: this.canvas,
57
+ coordinates: getSourceCoordinates(map, this.pixelRatio),
58
+ // Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
59
+ animate: true,
60
+ attribution: this.copyrights && this.copyrights.join(', '),
61
+ };
62
+ this.beforeId = beforeId;
63
+ this.layer = {
64
+ id: this.key,
65
+ type: 'raster',
66
+ source: this.key,
67
+ layout: {
68
+ visibility: this.visible ? 'visible' : 'none',
69
+ },
70
+ paint: {
71
+ 'raster-opacity': 1,
72
+ 'raster-fade-duration': 0,
73
+ 'raster-resampling': 'nearest', // important otherwise it looks blurry
74
+ },
75
+ };
76
+ if (map.isStyleLoaded()) {
77
+ this.onLoad();
78
+ }
79
+ this.map.on('load', this.onLoad);
80
+ this.listeners = [this.on('change:visible', this.onVisibilityChange)];
81
+ }
82
+ /**
83
+ * Remove listeners from the Mapbox Map.
84
+ */
85
+ detachFromMap() {
86
+ if (this.map) {
87
+ this.map.off('load', this.onLoad);
88
+ // @ts-ignore
89
+ this.listeners.forEach((listener) => {
90
+ unByKey(listener);
91
+ });
92
+ if (this.map.style && this.map.getLayer(this.key)) {
93
+ this.map.removeLayer(this.key);
94
+ }
95
+ if (this.map.style && this.map.getSource(this.key)) {
96
+ this.map.removeSource(this.key);
97
+ }
98
+ }
99
+ super.detachFromMap();
100
+ }
101
+ /**
102
+ * Start updating vehicles position.
103
+ *
104
+ * @listens {mapboxgl.map.event:zoomend} Listen to zoom end event.
105
+ * @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
106
+ * @override
107
+ */
108
+ start() {
109
+ super.start();
110
+ this.map.on('move', this.onMove);
111
+ this.map.on('moveend', this.onMoveEnd);
112
+ this.map.on('zoomend', this.onZoomEnd);
113
+ }
114
+ /**
115
+ * Stop updating vehicles position, and unlisten events.
116
+ *
117
+ * @override
118
+ */
119
+ stop() {
120
+ super.stop();
121
+ if (this.map) {
122
+ this.map.off('move', this.onMove);
123
+ this.map.off('moveend', this.onMoveEnd);
124
+ this.map.off('zoomend', this.onZoomEnd);
125
+ }
126
+ }
127
+ onLoad() {
128
+ if (!this.map.getSource(this.key)) {
129
+ this.map.addSource(this.key, this.source);
130
+ }
131
+ if (!this.map.getLayer(this.key)) {
132
+ this.map.addLayer(this.layer, this.beforeId);
133
+ }
134
+ }
135
+ /**
136
+ * Function triggered when the user moves the cursor over the map.
137
+ * @override
138
+ */
139
+ onUserMoveCallback(evt) {
140
+ super.onUserMoveCallback(Object.assign({ coordinate: fromLonLat(evt.lngLat.toArray()) }, evt));
141
+ }
142
+ /**
143
+ * Render the trajectories using current map's size, resolution and rotation.
144
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
145
+ * @overrides
146
+ */
147
+ // @ts-ignore
148
+ renderTrajectories(noInterpolate = false) {
149
+ if (!this.map) {
150
+ return;
151
+ }
152
+ if (!this.pixelRatio) {
153
+ this.pixelRatio = 1;
154
+ }
155
+ const { width, height } = this.map.getCanvas();
156
+ const center = this.map.getCenter();
157
+ // We use turf here to have good transform.
158
+ const leftBottom = this.map.unproject({
159
+ x: 0,
160
+ y: height / this.pixelRatio,
161
+ }); // southWest
162
+ const rightTop = this.map.unproject({
163
+ x: width / this.pixelRatio,
164
+ y: 0,
165
+ }); // north east
166
+ const coord0 = transformRotate(point([leftBottom.lng, leftBottom.lat]), -this.map.getBearing(), {
167
+ pivot: [center.lng, center.lat],
168
+ }).geometry.coordinates;
169
+ const coord1 = transformRotate(point([rightTop.lng, rightTop.lat]), -this.map.getBearing(), {
170
+ pivot: [center.lng, center.lat],
171
+ }).geometry.coordinates;
172
+ const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
173
+ const xResolution = getWidth(bounds) / (width / this.pixelRatio);
174
+ const yResolution = getHeight(bounds) / (height / this.pixelRatio);
175
+ const res = Math.max(xResolution, yResolution);
176
+ // Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
177
+ const viewState = {
178
+ size: [width / this.pixelRatio, height / this.pixelRatio],
179
+ center: fromLonLat([center.lng, center.lat]),
180
+ extent: bounds,
181
+ resolution: res,
182
+ zoom: this.getOlZoom(),
183
+ rotation: -(this.map.getBearing() * Math.PI) / 180,
184
+ pixelRatio: this.pixelRatio,
185
+ };
186
+ super.renderTrajectories(viewState, noInterpolate);
187
+ }
188
+ /**
189
+ * Return the delay in ms before the next rendering.
190
+ */
191
+ getRefreshTimeInMs() {
192
+ return super.getRefreshTimeInMs(this.map.getZoom());
193
+ }
194
+ getFeatureInfoAtCoordinate(coordinate, options = {}) {
195
+ const resolution = getMercatorResolution(this.map);
196
+ return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
197
+ }
198
+ onVisibilityChange() {
199
+ if (this.visible && !this.map.getLayer(this.key)) {
200
+ this.map.addLayer(this.layer, this.beforeId);
201
+ }
202
+ else if (this.map.getLayer(this.key)) {
203
+ this.map.removeLayer(this.key);
204
+ }
205
+ // We can't use setLayoutProperty it triggers an error probably a bug in mapbox
206
+ // this.map.setLayoutProperty(
207
+ // this.key,
208
+ // 'visibilty',
209
+ // this.visible ? 'visible' : 'none',
210
+ // );
211
+ }
212
+ /**
213
+ * Remove the trajectory form the list if necessary.
214
+ *
215
+ * @private
216
+ */
217
+ purgeTrajectory(trajectory, extent, zoom) {
218
+ return super.purgeTrajectory(trajectory, extent || this.getMercatorExtent(), zoom || Math.floor(this.getOlZoom()));
219
+ }
220
+ /**
221
+ * Send the current bbox to the websocket
222
+ */
223
+ setBbox(extent, zoom) {
224
+ let newExtent = extent;
225
+ let newZoom = zoom;
226
+ if (!newExtent && this.isUpdateBboxOnMoveEnd) {
227
+ newExtent = extent || this.getMercatorExtent();
228
+ newZoom = Math.floor(this.getOlZoom());
229
+ }
230
+ super.setBbox(newExtent, newZoom);
231
+ }
232
+ /**
233
+ * Callback on 'move' event.
234
+ *
235
+ * @private
236
+ */
237
+ onMove() {
238
+ this.renderTrajectories();
239
+ }
240
+ renderTrajectoriesInternal(viewState, noInterpolate = false) {
241
+ const render = super.renderTrajectoriesInternal(viewState, noInterpolate);
242
+ if (render && this.map.style) {
243
+ const extent = getSourceCoordinates(this.map, this.pixelRatio);
244
+ const source = this.map.getSource(this.key);
245
+ if (source) {
246
+ source.setCoordinates(extent);
247
+ }
248
+ }
249
+ return render;
250
+ }
251
+ /**
252
+ * Send the new BBOX to the websocket.
253
+ *
254
+ * @private
255
+ * @override
256
+ */
257
+ onMoveEnd() {
258
+ this.renderTrajectories();
259
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
260
+ this.setBbox();
261
+ }
262
+ }
263
+ /**
264
+ * Update the cursor style when hovering a vehicle.
265
+ *
266
+ * @private
267
+ * @override
268
+ */
269
+ onFeatureHover(features, layer, coordinate) {
270
+ super.onFeatureHover(features, layer, coordinate);
271
+ this.map.getCanvasContainer().style.cursor = features.length
272
+ ? 'pointer'
273
+ : 'auto';
274
+ }
275
+ }
276
+ export default RealtimeLayer;
@@ -0,0 +1,3 @@
1
+ export { default as Layer } from "./Layer";
2
+ export { default as RealtimeLayer } from "./RealtimeLayer";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mapbox/layers/index.js"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { default as Layer } from './Layer';
2
+ export { default as RealtimeLayer } from './RealtimeLayer';
@@ -0,0 +1,9 @@
1
+ import { AnyMapboxMap } from '../../types';
2
+ /**
3
+ * Get the current resolution of a Mapbox map.
4
+ * @param {mapboxgl.Map} map A map object.
5
+ * @private
6
+ */
7
+ declare const getMercatorResolution: (map: AnyMapboxMap) => number;
8
+ export default getMercatorResolution;
9
+ //# sourceMappingURL=getMercatorResolution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMercatorResolution.d.ts","sourceRoot":"","sources":["../../../src/mapbox/utils/getMercatorResolution.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,QAAS,YAAY,WAS/C,CAAC;AAEF,eAAe,qBAAqB,CAAC"}