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,340 @@
1
+ import GeoJSON from 'ol/format/GeoJSON';
2
+ import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
3
+ import Source from 'ol/source/Source';
4
+ import { composeCssTransform } from 'ol/transform';
5
+ import { Vector as VectorSource } from 'ol/source';
6
+ import Layer from './Layer';
7
+ import mixin from '../../common/mixins/RealtimeLayerMixin';
8
+ import { fullTrajectoryStyle } from '../styles';
9
+ /** @private */
10
+ const format = new GeoJSON();
11
+ /**
12
+ * Responsible for loading and display data from a Realtime service.
13
+ *
14
+ * @example
15
+ * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
16
+ *
17
+ * const layer = new RealtimeLayer({
18
+ * url: [yourUrl],
19
+ * apiKey: [yourApiKey],
20
+ * });
21
+ *
22
+ *
23
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
24
+ *
25
+ * @extends {Layer}
26
+ * @implements {UserInteractionsLayerInterface}
27
+ * @implements {RealtimeLayerInterface}
28
+ */
29
+ // @ts-ignore
30
+ class RealtimeLayer extends mixin(Layer) {
31
+ /**
32
+ * Constructor.
33
+ *
34
+ * @param {Object} options
35
+ * @private
36
+ */
37
+ constructor(options) {
38
+ // We use a group to be able to add custom vector layer in extended class.
39
+ // For example TrajservLayer use a vectorLayer to display the complete trajectory.
40
+ super(Object.assign({}, options));
41
+ this.allowRenderWhenAnimating = false;
42
+ this.allowRenderWhenAnimating = !!options.allowRenderWhenAnimating;
43
+ /** @ignore */
44
+ this.olLayer =
45
+ options.olLayer ||
46
+ new Group({
47
+ layers: [
48
+ new VectorLayer({
49
+ source: new VectorSource({ features: [] }),
50
+ style: (feature, resolution) => {
51
+ return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
52
+ },
53
+ }),
54
+ new OLLayer({
55
+ source: new Source({}),
56
+ render: (frameState) => {
57
+ var _a, _b, _c;
58
+ if (!this.container) {
59
+ this.container = document.createElement('div');
60
+ this.container.style.position = 'absolute';
61
+ this.container.style.width = '100%';
62
+ this.container.style.height = '100%';
63
+ this.transformContainer = document.createElement('div');
64
+ this.transformContainer.style.position = 'absolute';
65
+ this.transformContainer.style.width = '100%';
66
+ this.transformContainer.style.height = '100%';
67
+ this.container.appendChild(this.transformContainer);
68
+ if (this.canvas) {
69
+ this.canvas.style.position =
70
+ 'absolute';
71
+ this.canvas.style.top = '0';
72
+ this.canvas.style.left = '0';
73
+ this.canvas.style.transformOrigin =
74
+ 'top left';
75
+ this.transformContainer.appendChild(this.canvas);
76
+ }
77
+ }
78
+ if (this.renderedViewState) {
79
+ const { center, resolution, rotation } = frameState.viewState;
80
+ const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = this.renderedViewState;
81
+ if (renderedResolution / resolution >= 3) {
82
+ // Avoid having really big points when zooming fast.
83
+ const context = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.getContext('2d');
84
+ context === null || context === void 0 ? void 0 : context.clearRect(0, 0, (_b = this.canvas) === null || _b === void 0 ? void 0 : _b.width, (_c = this.canvas) === null || _c === void 0 ? void 0 : _c.height);
85
+ }
86
+ else {
87
+ const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
88
+ const pixelCenter = this.map.getPixelFromCoordinate(center);
89
+ this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
90
+ }
91
+ }
92
+ return this.container;
93
+ },
94
+ }),
95
+ ],
96
+ });
97
+ // We store the layer used to highlight the full Trajectory
98
+ this.vectorLayer = this.olLayer.getLayers().item(0);
99
+ // Options the last render run did happen. If something changes
100
+ // we have to render again
101
+ /** @ignore */
102
+ this.renderState = {
103
+ center: [0, 0],
104
+ zoom: undefined,
105
+ rotation: 0,
106
+ };
107
+ }
108
+ attachToMap(map) {
109
+ super.attachToMap(map);
110
+ if (this.map) {
111
+ this.olListenersKeys.push(...this.map.on(['moveend', 'change:target'], (evt) => {
112
+ const view = (evt.map || evt.target).getView();
113
+ if (view.getAnimating() || view.getInteracting()) {
114
+ return;
115
+ }
116
+ const zoom = view.getZoom();
117
+ // Update the interval between render updates
118
+ if (this.currentZoom !== zoom) {
119
+ this.onZoomEnd();
120
+ }
121
+ this.currentZoom = zoom;
122
+ this.onMoveEnd(evt);
123
+ }));
124
+ }
125
+ }
126
+ /**
127
+ * Destroy the container of the tracker.
128
+ */
129
+ detachFromMap() {
130
+ super.detachFromMap();
131
+ this.container = null;
132
+ }
133
+ /**
134
+ * Detect in the canvas if there is data to query at a specific coordinate.
135
+ * @param {ol/coordinate~Coordinate} coordinate The coordinate to test
136
+ * @returns
137
+ */
138
+ hasFeatureInfoAtCoordinate(coordinate) {
139
+ if (this.map && this.canvas) {
140
+ const context = this.canvas.getContext('2d', {
141
+ willReadFrequently: true,
142
+ });
143
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
144
+ return !!(context === null || context === void 0 ? void 0 : context.getImageData(pixel[0] * (this.pixelRatio || 1), pixel[1] * (this.pixelRatio || 1), 1, 1).data[3]);
145
+ }
146
+ return false;
147
+ }
148
+ /**
149
+ * Render the trajectories using current map's size, resolution and rotation.
150
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
151
+ * @overrides
152
+ */
153
+ // @ts-ignore
154
+ renderTrajectories(noInterpolate) {
155
+ if (!this.map) {
156
+ return;
157
+ }
158
+ const view = this.map.getView();
159
+ // it could happen that the view is set but without center yet,
160
+ // so the calcualteExtent will trigger an error.
161
+ if (!view.getCenter()) {
162
+ return;
163
+ }
164
+ super.renderTrajectories({
165
+ size: this.map.getSize(),
166
+ center: view.getCenter(),
167
+ extent: view.calculateExtent(),
168
+ resolution: view.getResolution(),
169
+ rotation: view.getRotation(),
170
+ zoom: view.getZoom(),
171
+ pixelRatio: this.pixelRatio,
172
+ }, noInterpolate);
173
+ }
174
+ /**
175
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
176
+ * @private
177
+ * @override
178
+ */
179
+ renderTrajectoriesInternal(viewState, noInterpolate) {
180
+ if (!this.map) {
181
+ return false;
182
+ }
183
+ let isRendered = false;
184
+ const blockRendering = this.allowRenderWhenAnimating
185
+ ? false
186
+ : this.map.getView().getAnimating() ||
187
+ this.map.getView().getInteracting();
188
+ // Don't render the map when the map is animating or interacting.
189
+ isRendered = blockRendering
190
+ ? false
191
+ : super.renderTrajectoriesInternal(viewState, noInterpolate);
192
+ // We update the current render state.
193
+ if (isRendered) {
194
+ this.renderedViewState = Object.assign({}, viewState);
195
+ if (this.transformContainer) {
196
+ this.transformContainer.style.transform = '';
197
+ }
198
+ }
199
+ return isRendered;
200
+ }
201
+ /**
202
+ * Return the delay in ms before the next rendering.
203
+ */
204
+ getRefreshTimeInMs() {
205
+ return super.getRefreshTimeInMs(this.map.getView().getZoom());
206
+ }
207
+ getFeatureInfoAtCoordinate(coordinate, options = {}) {
208
+ if (!this.map || !this.map.getView()) {
209
+ return Promise.resolve({
210
+ layer: this,
211
+ features: [],
212
+ coordinate,
213
+ });
214
+ }
215
+ const resolution = this.map.getView().getResolution();
216
+ return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
217
+ }
218
+ /**
219
+ * On move end we update the websocket with the new bbox.
220
+ *
221
+ * @private
222
+ * @override
223
+ */
224
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
225
+ onMoveEnd(evt) {
226
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
227
+ this.setBbox();
228
+ }
229
+ if (this.visible &&
230
+ this.isUpdateBboxOnMoveEnd &&
231
+ this.userClickInteractions &&
232
+ this.selectedVehicleId) {
233
+ this.highlightTrajectory(this.selectedVehicleId);
234
+ }
235
+ }
236
+ /**
237
+ * Function called on moveend event only when the zoom has changed.
238
+ *
239
+ * @param {ol/MapEvent~MapEvent} evt Moveend event.
240
+ * @private
241
+ * @override
242
+ */
243
+ // eslint-disable-next-line no-unused-vars
244
+ onZoomEnd() {
245
+ super.onZoomEnd();
246
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
247
+ this.setBbox();
248
+ }
249
+ if (this.visible &&
250
+ this.isUpdateBboxOnMoveEnd &&
251
+ this.userClickInteractions &&
252
+ this.selectedVehicleId) {
253
+ this.highlightTrajectory(this.selectedVehicleId);
254
+ }
255
+ }
256
+ /**
257
+ * Update the cursor style when hovering a vehicle.
258
+ *
259
+ * @private
260
+ * @override
261
+ */
262
+ onFeatureHover(features, layer, coordinate) {
263
+ super.onFeatureHover(features, layer, coordinate);
264
+ this.map.getTargetElement().style.cursor = features.length
265
+ ? 'pointer'
266
+ : 'auto';
267
+ }
268
+ /**
269
+ * Display the complete trajectory of the vehicle.
270
+ *
271
+ * @private
272
+ * @override
273
+ */
274
+ onFeatureClick(features, layer, coordinate) {
275
+ super.onFeatureClick(features, layer, coordinate);
276
+ if (!features.length && this.vectorLayer) {
277
+ this.vectorLayer.getSource().clear();
278
+ }
279
+ if (this.selectedVehicleId) {
280
+ this.highlightTrajectory(this.selectedVehicleId);
281
+ }
282
+ }
283
+ /**
284
+ * Remove the trajectory form the list if necessary.
285
+ *
286
+ * @private
287
+ */
288
+ purgeTrajectory(trajectory, extent, zoom) {
289
+ const center = this.map.getView().getCenter();
290
+ if (!extent && !center) {
291
+ // In that case the view is not zoomed yet so we can't calculate the extent of the map,
292
+ // it will trigger a js error on calculateExtent function.
293
+ return false;
294
+ }
295
+ return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
296
+ }
297
+ /**
298
+ * Send the current bbox to the websocket
299
+ *
300
+ * @private
301
+ */
302
+ setBbox(extent, zoom) {
303
+ let newExtent = extent;
304
+ let newZoom = zoom;
305
+ if (!newExtent && this.isUpdateBboxOnMoveEnd) {
306
+ newExtent = extent || this.map.getView().calculateExtent();
307
+ newZoom = Math.floor(this.map.getView().getZoom());
308
+ }
309
+ super.setBbox(newExtent, newZoom);
310
+ }
311
+ /**
312
+ * Highlight the trajectory of journey.
313
+ * @private
314
+ */
315
+ highlightTrajectory(id) {
316
+ return this.api
317
+ .getFullTrajectory(id, this.mode, this.generalizationLevel)
318
+ .then((data) => {
319
+ const fullTrajectory = data.content;
320
+ this.vectorLayer.getSource().clear();
321
+ if (!fullTrajectory ||
322
+ !fullTrajectory.features ||
323
+ !fullTrajectory.features.length) {
324
+ return undefined;
325
+ }
326
+ const features = format.readFeatures(fullTrajectory);
327
+ this.vectorLayer.getSource().addFeatures(features);
328
+ return features;
329
+ });
330
+ }
331
+ /**
332
+ * Create a copy of the RealtimeLayer.
333
+ * @param {Object} newOptions Options to override
334
+ * @return {RealtimeLayer} A RealtimeLayer
335
+ */
336
+ clone(newOptions) {
337
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
338
+ }
339
+ }
340
+ export default RealtimeLayer;
@@ -0,0 +1,34 @@
1
+ import { Vector as VectorSource } from 'ol/source';
2
+ import { Vector } from 'ol/layer';
3
+ import type { StyleLike } from 'ol/style/Style';
4
+ import { Geometry } from 'ol/geom';
5
+ import Layer from './Layer';
6
+ import type { OlLayerOptions } from './Layer';
7
+ export type OlRoutingLayerOptions = OlLayerOptions & {
8
+ olLayer?: Vector<VectorSource<Geometry>>;
9
+ style?: StyleLike;
10
+ };
11
+ /**
12
+ * A class use to display vector data.
13
+ *
14
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
15
+ * @extends {Layer}
16
+ */
17
+ declare class RoutingLayer extends Layer {
18
+ olLayer?: Vector<VectorSource<Geometry>>;
19
+ options: OlRoutingLayerOptions;
20
+ /**
21
+ * Constructor.
22
+ * @param {Object} [options]
23
+ * @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
24
+ */
25
+ constructor(options: OlRoutingLayerOptions);
26
+ /**
27
+ * Create a copy of the RoutingLayer.
28
+ * @param {Object} newOptions Options to override
29
+ * @return {RoutingLayer} A RoutingLayer
30
+ */
31
+ clone(newOptions: OlRoutingLayerOptions): RoutingLayer;
32
+ }
33
+ export default RoutingLayer;
34
+ //# sourceMappingURL=RoutingLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB,CAAC;AA8DF;;;;;GAKG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzC,OAAO,EAAE,qBAAqB,CAAM;IAEpC;;;;OAIG;gBACS,OAAO,EAAE,qBAAqB;IAW1C;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,qBAAqB;CAGxC;AAED,eAAe,YAAY,CAAC"}
@@ -1,61 +1,85 @@
1
- import { Circle, Fill, Stroke, Style } from "ol/style";
2
- import { Vector as VectorSource } from "ol/source";
3
- import { Vector } from "ol/layer";
4
- import Layer from "./Layer";
1
+ import { Circle, Fill, Stroke, Style } from 'ol/style';
2
+ import { Vector as VectorSource } from 'ol/source';
3
+ import { Vector } from 'ol/layer';
4
+ import Layer from './Layer';
5
+ /** @private */
5
6
  const circleStyle = new Circle({
6
- radius: 6,
7
- fill: new Fill({
8
- color: [255, 0, 0, 1]
9
- }),
10
- stroke: new Stroke({
11
- color: [0, 0, 0, 1],
12
- width: 1
13
- })
7
+ radius: 6,
8
+ fill: new Fill({
9
+ color: [255, 0, 0, 1],
10
+ }),
11
+ stroke: new Stroke({
12
+ color: [0, 0, 0, 1],
13
+ width: 1,
14
+ }),
14
15
  });
16
+ /** @private */
15
17
  const blackBorder = new Style({
16
- stroke: new Stroke({
17
- color: [0, 0, 0, 1],
18
- width: 5
19
- })
18
+ stroke: new Stroke({
19
+ color: [0, 0, 0, 1],
20
+ width: 5,
21
+ }),
20
22
  });
23
+ /** @private */
21
24
  const redLine = new Style({
22
- image: circleStyle,
23
- stroke: new Stroke({
24
- color: [255, 0, 0, 1],
25
- width: 3
26
- })
25
+ image: circleStyle,
26
+ stroke: new Stroke({
27
+ color: [255, 0, 0, 1],
28
+ width: 3,
29
+ }),
27
30
  });
31
+ /** @private */
28
32
  const dashedRedLine = new Style({
29
- image: circleStyle,
30
- stroke: new Stroke({
31
- color: [255, 0, 0, 1],
32
- width: 3,
33
- lineDash: [1, 10]
34
- })
33
+ image: circleStyle,
34
+ stroke: new Stroke({
35
+ color: [255, 0, 0, 1],
36
+ width: 3,
37
+ lineDash: [1, 10],
38
+ }),
35
39
  });
40
+ /** @private */
36
41
  const defaultStyleFunction = (feature, resolution) => {
37
- const minResolution = feature.get("minResolution");
38
- const maxResolution = feature.get("maxResolution");
39
- const inRange = resolution <= minResolution && resolution > maxResolution;
40
- if (minResolution && maxResolution && !inRange) {
41
- return null;
42
- }
43
- const mot = feature.get("mot");
44
- if (mot !== "foot") {
45
- return [blackBorder, redLine];
46
- }
47
- return [dashedRedLine];
42
+ const minResolution = feature.get('minResolution');
43
+ const maxResolution = feature.get('maxResolution');
44
+ const inRange = resolution <= minResolution && resolution > maxResolution;
45
+ if (minResolution && maxResolution && !inRange) {
46
+ return [];
47
+ }
48
+ const mot = feature.get('mot');
49
+ if (mot !== 'foot') {
50
+ return [blackBorder, redLine];
51
+ }
52
+ return [dashedRedLine];
48
53
  };
54
+ /**
55
+ * A class use to display vector data.
56
+ *
57
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
58
+ * @extends {Layer}
59
+ */
49
60
  class RoutingLayer extends Layer {
50
- constructor(options = {}) {
51
- super(options);
52
- this.olLayer = options.olLayer || new Vector({
53
- source: new VectorSource(),
54
- style: options.style || defaultStyleFunction
55
- });
56
- }
57
- clone(newOptions) {
58
- return new RoutingLayer({ ...this.options, ...newOptions });
59
- }
61
+ /**
62
+ * Constructor.
63
+ * @param {Object} [options]
64
+ * @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
65
+ */
66
+ constructor(options) {
67
+ super(options);
68
+ this.options = {};
69
+ this.olLayer =
70
+ options.olLayer ||
71
+ new Vector({
72
+ source: new VectorSource(),
73
+ style: options.style || defaultStyleFunction,
74
+ });
75
+ }
76
+ /**
77
+ * Create a copy of the RoutingLayer.
78
+ * @param {Object} newOptions Options to override
79
+ * @return {RoutingLayer} A RoutingLayer
80
+ */
81
+ clone(newOptions) {
82
+ return new RoutingLayer(Object.assign(Object.assign({}, this.options), newOptions));
83
+ }
60
84
  }
61
85
  export default RoutingLayer;
@@ -0,0 +1,25 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { LayerGetFeatureInfoResponse } from '../../types';
3
+ import Layer, { OlLayerOptions } from './Layer';
4
+ /**
5
+ * A class use to display vector data.
6
+ *
7
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
8
+ * @extends {Layer}
9
+ */
10
+ declare class VectorLayer extends Layer {
11
+ /**
12
+ * Request feature information for a given coordinate.
13
+ * @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
14
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
15
+ */
16
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
17
+ /**
18
+ * Create a copy of the VectorLayer.
19
+ * @param {Object} newOptions Options to override
20
+ * @return {VectorLayer} A VectorLayer
21
+ */
22
+ clone(newOptions: OlLayerOptions): VectorLayer;
23
+ }
24
+ export default VectorLayer;
25
+ //# sourceMappingURL=VectorLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/VectorLayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;GAKG;AACH,cAAM,WAAY,SAAQ,KAAK;IAC7B;;;;OAIG;IACH,0BAA0B,CACxB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,2BAA2B,CAAC;IAkBvC;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,cAAc;CAGjC;AAED,eAAe,WAAW,CAAC"}
@@ -1,22 +1,38 @@
1
- import Layer from "./Layer";
1
+ import Layer from './Layer';
2
+ /**
3
+ * A class use to display vector data.
4
+ *
5
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
6
+ * @extends {Layer}
7
+ */
2
8
  class VectorLayer extends Layer {
3
- getFeatureInfoAtCoordinate(coordinate) {
4
- let features = [];
5
- if (this.map) {
6
- const pixel = this.map.getPixelFromCoordinate(coordinate);
7
- features = this.map.getFeaturesAtPixel(pixel, {
8
- layerFilter: (l) => l === this.olLayer,
9
- hitTolerance: this.hitTolerance
10
- });
9
+ /**
10
+ * Request feature information for a given coordinate.
11
+ * @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
12
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
13
+ */
14
+ getFeatureInfoAtCoordinate(coordinate) {
15
+ let features = [];
16
+ if (this.map) {
17
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
18
+ features = this.map.getFeaturesAtPixel(pixel, {
19
+ layerFilter: (l) => l === this.olLayer,
20
+ hitTolerance: this.hitTolerance,
21
+ });
22
+ }
23
+ return Promise.resolve({
24
+ features,
25
+ layer: this,
26
+ coordinate,
27
+ });
28
+ }
29
+ /**
30
+ * Create a copy of the VectorLayer.
31
+ * @param {Object} newOptions Options to override
32
+ * @return {VectorLayer} A VectorLayer
33
+ */
34
+ clone(newOptions) {
35
+ return new VectorLayer(Object.assign(Object.assign({}, this.options), newOptions));
11
36
  }
12
- return Promise.resolve({
13
- features,
14
- layer: this,
15
- coordinate
16
- });
17
- }
18
- clone(newOptions) {
19
- return new VectorLayer({ ...this.options, ...newOptions });
20
- }
21
37
  }
22
38
  export default VectorLayer;
@@ -0,0 +1,42 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import GeoJSON from 'ol/format/GeoJSON';
3
+ import ImageLayer from 'ol/layer/Image';
4
+ import TileLayer from 'ol/layer/Tile';
5
+ import { ImageWMS, TileWMS } from 'ol/source';
6
+ import { LayerGetFeatureInfoResponse } from '../../types';
7
+ import Layer, { OlLayerOptions } from './Layer';
8
+ /**
9
+ * Class use to display a WMS layer.
10
+ *
11
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
12
+ * @extends {Layer}
13
+ */
14
+ declare class WMSLayer extends Layer {
15
+ abortController?: AbortController;
16
+ format: GeoJSON;
17
+ olLayer?: TileLayer<TileWMS> | ImageLayer<ImageWMS>;
18
+ /**
19
+ * @override
20
+ */
21
+ constructor(options: OlLayerOptions);
22
+ /**
23
+ * Get features infos' Url.
24
+ * @param {ol/coordinate~Coordinate} coord
25
+ * @return {ol/layer/Layer~Layer}
26
+ */
27
+ getFeatureInfoUrl(coord: Coordinate): string | undefined;
28
+ /**
29
+ * Request feature information for a given coordinate.
30
+ * @param {ol/coordinate~Coordinate} coordinate to request the information at.
31
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
32
+ */
33
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
34
+ /**
35
+ * Create a copy of the WMSLayer.
36
+ * @param {Object} newOptions Options to override
37
+ * @return {WMSLayer} A WMSLayer
38
+ */
39
+ clone(newOptions: OlLayerOptions): WMSLayer;
40
+ }
41
+ export default WMSLayer;
42
+ //# sourceMappingURL=WMSLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WMSLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/WMSLayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,OAAO,MAAM,mBAAmB,CAAC;AACxC,OAAO,UAAU,MAAM,gBAAgB,CAAC;AACxC,OAAO,SAAS,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;GAKG;AACH,cAAM,QAAS,SAAQ,KAAK;IAC1B,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC,MAAM,EAAE,OAAO,CAAC;IAEhB,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpD;;OAEG;gBACS,OAAO,EAAE,cAAc;IASnC;;;;OAIG;IACH,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS;IAuBxD;;;;OAIG;IACH,0BAA0B,CACxB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,2BAA2B,CAAC;IAkCvC;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,cAAc;CAGjC;AAED,eAAe,QAAQ,CAAC"}