mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.21

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 (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +16 -10
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +22103 -14430
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +4 -1
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +101 -0
  87. package/ol/layers/Layer.js +25 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +97 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -267
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +31 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +112 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -1,17 +1,17 @@
1
+ import debounce from 'lodash.debounce';
1
2
  import GeoJSON from 'ol/format/GeoJSON';
2
3
  import { Vector as VectorLayer } from 'ol/layer';
3
- import Source from 'ol/source/Source';
4
- import { Vector as VectorSource } from 'ol/source';
5
- import debounce from 'lodash.debounce';
6
4
  import Layer from 'ol/layer/Layer';
5
+ import { Vector as VectorSource } from 'ol/source';
6
+ import Source from 'ol/source/Source';
7
7
  import RealtimeLayerMixin from '../../common/mixins/RealtimeLayerMixin';
8
- import { fullTrajectoryStyle } from '../styles';
9
8
  import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
10
9
  import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
10
+ import { fullTrajectoryStyle } from '../styles';
11
11
  /** @private */
12
12
  const format = new GeoJSON();
13
13
  /**
14
- * Responsible for loading and display data from the geOps Realtime API.
14
+ * An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
15
15
  *
16
16
  * @example
17
17
  * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
@@ -30,7 +30,7 @@ const format = new GeoJSON();
30
30
  * @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
31
31
  * @public
32
32
  */
33
- // @ts-ignore
33
+ // @ts-expect-error
34
34
  class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
35
35
  /**
36
36
  * Constructor.
@@ -52,45 +52,42 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
52
52
  // We store the layer used to highlight the full Trajectory
53
53
  /** @private */
54
54
  this.vectorLayer = new VectorLayer({
55
- updateWhileAnimating: this.allowRenderWhenAnimating,
56
- updateWhileInteracting: true,
57
55
  source: new VectorSource({ features: [] }),
58
56
  style: (feature, resolution) => {
59
57
  return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
60
58
  },
59
+ updateWhileAnimating: this.allowRenderWhenAnimating,
60
+ updateWhileInteracting: true,
61
61
  });
62
62
  // Options the last render run did happen. If something changes
63
63
  // we have to render again
64
64
  /** @private */
65
65
  this.renderState = {
66
66
  center: [0, 0],
67
- zoom: undefined,
68
67
  rotation: 0,
68
+ zoom: undefined,
69
69
  };
70
70
  /** @private */
71
71
  this.onZoomEndDebounced = debounce(this.onZoomEnd, 100);
72
72
  /** @private */
73
73
  this.onMoveEndDebounced = debounce(this.onMoveEnd, 100);
74
74
  }
75
- /**
76
- * @private
77
- */
78
- createRenderer() {
79
- return new RealtimeLayerRenderer(this);
80
- }
81
75
  /** @private */
82
76
  attachToMap(map) {
83
77
  super.attachToMap(map);
84
78
  if (this.map) {
85
79
  // If the layer is visible we start the rendering clock
86
- if (this.visible) {
80
+ if (this.getVisible()) {
87
81
  this.start();
88
82
  }
83
+ // @ts-expect-error - bad ts check RealtimeLayer is a BaseLayer
89
84
  const index = this.map.getLayers().getArray().indexOf(this);
90
85
  this.map.getLayers().insertAt(index, this.vectorLayer);
91
- this.olListenersKeys.push(...this.map.on(['moveend', 'change:target'], (evt) => {
86
+ this.olEventsKeys.push(...this.map.on(['moveend', 'change:target'],
87
+ // @ts-expect-error - bad ol definitions
88
+ (evt) => {
92
89
  const view = (evt.map || evt.target).getView();
93
- if (view.getAnimating() || view.getInteracting()) {
90
+ if (!view || (view === null || view === void 0 ? void 0 : view.getAnimating()) || (view === null || view === void 0 ? void 0 : view.getInteracting())) {
94
91
  return;
95
92
  }
96
93
  const zoom = view.getZoom();
@@ -102,7 +99,7 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
102
99
  this.currentZoom = zoom;
103
100
  this.onMoveEndDebounced(evt);
104
101
  }), this.on('change:visible', (evt) => {
105
- if (evt.target.visible) {
102
+ if (evt.target.getVisible()) {
106
103
  this.start();
107
104
  }
108
105
  else {
@@ -117,13 +114,18 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
117
114
  }
118
115
  }
119
116
  /**
120
- * Destroy the container of the tracker.
117
+ * Create a copy of the RealtimeLayer.
118
+ * @param {Object} newOptions Options to override
119
+ * @return {RealtimeLayer} A RealtimeLayer
120
+ */
121
+ clone(newOptions) {
122
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
123
+ }
124
+ /**
121
125
  * @private
122
126
  */
123
- detachFromMap() {
124
- var _a;
125
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
126
- super.detachFromMap();
127
+ createRenderer() {
128
+ return new RealtimeLayerRenderer(this);
127
129
  }
128
130
  /**
129
131
  * Render the trajectories using current map's size, resolution and rotation.
@@ -131,61 +133,25 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
131
133
  * @overrides
132
134
  * @private
133
135
  */
134
- // @ts-ignore
135
- renderTrajectories(noInterpolate) {
136
- if (!this.map) {
137
- return;
138
- }
139
- const view = this.map.getView();
140
- // it could happen that the view is set but without center yet,
141
- // so the calcualteExtent will trigger an error.
142
- if (!view.getCenter()) {
143
- return;
144
- }
145
- super.renderTrajectories({
146
- size: this.map.getSize(),
147
- center: view.getCenter(),
148
- extent: view.calculateExtent(),
149
- resolution: view.getResolution(),
150
- rotation: view.getRotation(),
151
- zoom: view.getZoom(),
152
- pixelRatio: this.pixelRatio,
153
- }, noInterpolate);
154
- }
155
136
  /**
156
- * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
137
+ * Destroy the container of the tracker.
157
138
  * @private
158
- * @override
159
139
  */
160
- renderTrajectoriesInternal(viewState, noInterpolate) {
161
- if (!this.map) {
162
- return false;
163
- }
164
- let isRendered = false;
165
- const blockRendering = this.allowRenderWhenAnimating
166
- ? false
167
- : this.map.getView().getAnimating() ||
168
- this.map.getView().getInteracting();
169
- // Don't render the map when the map is animating or interacting.
170
- isRendered = blockRendering
171
- ? false
172
- : super.renderTrajectoriesInternal(viewState, noInterpolate);
173
- // We update the current render state.
174
- if (isRendered) {
175
- /** @private */
176
- this.renderedViewState = Object.assign({}, viewState);
177
- if (this.getRenderer().container) {
178
- this.getRenderer().container.style.transform = '';
179
- }
180
- }
181
- return isRendered;
140
+ detachFromMap() {
141
+ var _a;
142
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
143
+ super.detachFromMap();
182
144
  }
183
145
  /**
184
146
  * Return the delay in ms before the next rendering.
185
147
  * @private
186
148
  */
187
149
  getRefreshTimeInMs() {
188
- return super.getRefreshTimeInMs(this.map.getView().getZoom());
150
+ var _a;
151
+ return super.getRefreshTimeInMs(((_a = this.map.getView()) === null || _a === void 0 ? void 0 : _a.getZoom()) || 0);
152
+ }
153
+ highlight(feature) {
154
+ this.highlightVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
189
155
  }
190
156
  /**
191
157
  * On move end we update the websocket with the new bbox.
@@ -193,12 +159,36 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
193
159
  * @private
194
160
  * @override
195
161
  */
196
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
197
- onMoveEnd(evt) {
198
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
199
- return;
162
+ /**
163
+ * Highlight the trajectory of journey.
164
+ * @private
165
+ */
166
+ highlightTrajectory(id) {
167
+ var _a, _b, _c, _d;
168
+ if (!id) {
169
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
170
+ return Promise.resolve([]);
200
171
  }
201
- this.setBbox();
172
+ return this.api
173
+ .getFullTrajectory(id, this.mode, this.getGeneralizationLevelByZoom(Math.floor(((_d = (_c = this.map) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0)))
174
+ .then((data) => {
175
+ var _a, _b, _c, _d, _e;
176
+ const fullTrajectory = data.content;
177
+ if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
178
+ return [];
179
+ }
180
+ const features = format.readFeatures(fullTrajectory);
181
+ (_c = (_b = this.vectorLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear(true);
182
+ if (features.length) {
183
+ (_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
184
+ }
185
+ return features;
186
+ })
187
+ .catch(() => {
188
+ var _a, _b;
189
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
190
+ return [];
191
+ });
202
192
  }
203
193
  /**
204
194
  * Function called on moveend event only when the zoom has changed.
@@ -207,22 +197,37 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
207
197
  * @private
208
198
  * @override
209
199
  */
200
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
201
+ onMoveEnd(evt) {
202
+ if (!this.isUpdateBboxOnMoveEnd || !this.getVisible()) {
203
+ return;
204
+ }
205
+ this.setBbox();
206
+ }
210
207
  // eslint-disable-next-line no-unused-vars
211
208
  onZoomEnd() {
212
209
  super.onZoomEnd();
213
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
210
+ if (!this.isUpdateBboxOnMoveEnd || !this.getVisible()) {
214
211
  return;
215
212
  }
216
213
  if (this.selectedVehicleId) {
217
214
  this.highlightTrajectory(this.selectedVehicleId);
218
215
  }
219
216
  }
220
- highlight(feature) {
221
- this.highlightVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
222
- }
223
- select(feature) {
224
- this.selectVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
225
- this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
217
+ /**
218
+ * Remove the trajectory form the list if necessary.
219
+ *
220
+ * @private
221
+ */
222
+ purgeTrajectory(trajectory, extent, zoom) {
223
+ var _a;
224
+ const center = (_a = this.map.getView()) === null || _a === void 0 ? void 0 : _a.getCenter();
225
+ if (!extent && !center) {
226
+ // In that case the view is not zoomed yet so we can't calculate the extent of the map,
227
+ // it will trigger a js error on calculateExtent function.
228
+ return false;
229
+ }
230
+ return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom() || 0);
226
231
  }
227
232
  // /**
228
233
  // * Update the cursor style when hovering a vehicle.
@@ -254,19 +259,61 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
254
259
  // super.onFeatureClick(features, layer, coordinate);
255
260
  // this.highlightTrajectory(this.selectedVehicleId);
256
261
  // }
262
+ // @ts-expect-error
263
+ renderTrajectories(noInterpolate) {
264
+ if (!this.map) {
265
+ return;
266
+ }
267
+ const view = this.map.getView();
268
+ // it could happen that the view is set but without center yet,
269
+ // so the calcualteExtent will trigger an error.
270
+ if (!(view === null || view === void 0 ? void 0 : view.getCenter())) {
271
+ return;
272
+ }
273
+ super.renderTrajectories({
274
+ center: view.getCenter(),
275
+ extent: view.calculateExtent(),
276
+ pixelRatio: this.pixelRatio,
277
+ resolution: view.getResolution(),
278
+ rotation: view.getRotation(),
279
+ size: this.map.getSize(),
280
+ zoom: view.getZoom(),
281
+ }, noInterpolate);
282
+ }
257
283
  /**
258
- * Remove the trajectory form the list if necessary.
259
- *
284
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
260
285
  * @private
286
+ * @override
261
287
  */
262
- purgeTrajectory(trajectory, extent, zoom) {
263
- const center = this.map.getView().getCenter();
264
- if (!extent && !center) {
265
- // In that case the view is not zoomed yet so we can't calculate the extent of the map,
266
- // it will trigger a js error on calculateExtent function.
288
+ renderTrajectoriesInternal(viewState, noInterpolate) {
289
+ var _a;
290
+ if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getView())) {
267
291
  return false;
268
292
  }
269
- return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
293
+ let isRendered = false;
294
+ const blockRendering = this.allowRenderWhenAnimating
295
+ ? false
296
+ : this.map.getView().getAnimating() ||
297
+ this.map.getView().getInteracting();
298
+ // Don't render the map when the map is animating or interacting.
299
+ isRendered = blockRendering
300
+ ? false
301
+ : super.renderTrajectoriesInternal(viewState, noInterpolate);
302
+ // We update the current render state.
303
+ if (isRendered) {
304
+ /** @private */
305
+ this.renderedViewState = Object.assign({}, viewState);
306
+ // @ts-expect-error - we are in the same class
307
+ const { container } = this.getRenderer();
308
+ if (container) {
309
+ container.style.transform = '';
310
+ }
311
+ }
312
+ return isRendered;
313
+ }
314
+ select(feature) {
315
+ this.selectVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
316
+ this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
270
317
  }
271
318
  /**
272
319
  * Send the current bbox to the websocket
@@ -274,45 +321,13 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
274
321
  * @private
275
322
  */
276
323
  setBbox(extent, zoom) {
277
- super.setBbox(extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
278
- }
279
- /**
280
- * Highlight the trajectory of journey.
281
- * @private
282
- */
283
- highlightTrajectory(id) {
284
- var _a, _b;
285
- if (!id) {
286
- this.vectorLayer.getSource().clear(true);
287
- return Promise.resolve([]);
324
+ var _a, _b, _c, _d;
325
+ const extentt = extent ||
326
+ ((_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.calculateExtent());
327
+ if (!extentt) {
328
+ return;
288
329
  }
289
- return this.api
290
- .getFullTrajectory(id, this.mode, this.getGeneralizationLevelByZoom(Math.floor(((_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.getZoom()) || 0)))
291
- .then((data) => {
292
- var _a;
293
- const fullTrajectory = data.content;
294
- if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
295
- return [];
296
- }
297
- const features = format.readFeatures(fullTrajectory);
298
- this.vectorLayer.getSource().clear(true);
299
- if (features.length) {
300
- this.vectorLayer.getSource().addFeatures(features);
301
- }
302
- return features;
303
- })
304
- .catch(() => {
305
- this.vectorLayer.getSource().clear(true);
306
- return [];
307
- });
308
- }
309
- /**
310
- * Create a copy of the RealtimeLayer.
311
- * @param {Object} newOptions Options to override
312
- * @return {RealtimeLayer} A RealtimeLayer
313
- */
314
- clone(newOptions) {
315
- return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
330
+ super.setBbox(extentt, zoom || ((_d = (_c = this.map) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0);
316
331
  }
317
332
  }
318
333
  export default RealtimeLayer;
@@ -0,0 +1,18 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { LayerGetFeatureInfoResponse } from '../../types';
3
+ import { MobilityLayerOptions } from '../mixins/MobilityLayerMixin';
4
+ import Layer from './Layer';
5
+ /**
6
+ * @deprecated
7
+ */
8
+ declare class VectorLayer extends Layer {
9
+ /**
10
+ * @deprecated
11
+ */
12
+ clone(newOptions: MobilityLayerOptions): VectorLayer;
13
+ /**
14
+ * @deprecated
15
+ */
16
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
17
+ }
18
+ export default VectorLayer;
@@ -0,0 +1,31 @@
1
+ import Layer from './Layer';
2
+ /**
3
+ * @deprecated
4
+ */
5
+ class VectorLayer extends Layer {
6
+ /**
7
+ * @deprecated
8
+ */
9
+ clone(newOptions) {
10
+ return new VectorLayer(Object.assign(Object.assign({}, this.options), newOptions));
11
+ }
12
+ /**
13
+ * @deprecated
14
+ */
15
+ getFeatureInfoAtCoordinate(coordinate) {
16
+ let features = [];
17
+ if (this.map) {
18
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
19
+ features = this.map.getFeaturesAtPixel(pixel, {
20
+ hitTolerance: this.hitTolerance || 5,
21
+ layerFilter: (l) => l === this.olLayer,
22
+ });
23
+ }
24
+ return Promise.resolve({
25
+ coordinate,
26
+ features,
27
+ layer: this,
28
+ });
29
+ }
30
+ }
31
+ export default VectorLayer;
@@ -0,0 +1,5 @@
1
+ export { default as MaplibreLayer } from "./MaplibreLayer";
2
+ export { default as MaplibreStyleLayer } from "./MaplibreStyleLayer";
3
+ export { default as RealtimeLayer } from "./RealtimeLayer";
4
+ export { default as Layer } from "./Layer";
5
+ export { default as VectorLayer } from "./VectorLayer";
@@ -1,3 +1,6 @@
1
1
  export { default as MaplibreLayer } from './MaplibreLayer';
2
2
  export { default as MaplibreStyleLayer } from './MaplibreStyleLayer';
3
3
  export { default as RealtimeLayer } from './RealtimeLayer';
4
+ // Deprecated export
5
+ export { default as Layer } from './Layer';
6
+ export { default as VectorLayer } from './VectorLayer';
@@ -0,0 +1,96 @@
1
+ import { Layer } from 'ol/layer';
2
+ import { PropertiesLayerMixinOptions } from './PropertiesLayerMixin';
3
+ export type MobilityLayerOptions = PropertiesLayerMixinOptions & Record<string, any>;
4
+ type GConstructor<T = object> = new (...args: any[]) => T;
5
+ export type Layerable = GConstructor<Omit<Layer, keyof string>>;
6
+ declare function MobilityLayerMixin<TBase extends Layerable>(Base: TBase): {
7
+ new (...args: any[]): {
8
+ olEventsKeys: import("ol/events").EventsKey[];
9
+ options?: PropertiesLayerMixinOptions;
10
+ attachToMap(map: import("ol").Map): void;
11
+ detachFromMap(): void;
12
+ flat(): any[];
13
+ onChildrenChange(oldValue: Layer[]): void;
14
+ setMapInternal: ((map: import("ol").Map) => void) & ((map: import("ol").default | null) => void);
15
+ children: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>[];
16
+ get copyrights(): string;
17
+ set copyrights(newCopyrights: string | string[]);
18
+ disabled: boolean;
19
+ readonly group: string;
20
+ readonly hitTolerance: number;
21
+ readonly key: string;
22
+ readonly map: import("ol").Map;
23
+ readonly name: string;
24
+ olLayer: Layer;
25
+ parent: Layer<import("ol/source").Source, import("ol/renderer/Layer").default<any>>;
26
+ visible: boolean;
27
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
28
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
29
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
30
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
31
+ getSource: () => import("ol/source").Source | null;
32
+ getRenderSource: () => import("ol/source").Source | null;
33
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
34
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
35
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
36
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
37
+ unrender: () => void;
38
+ getDeclutter: () => string;
39
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
40
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
41
+ getMapInternal: () => import("ol").default | null;
42
+ setMap: (map: import("ol").default | null) => void;
43
+ setSource: (source: import("ol/source").Source | null) => void;
44
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
45
+ hasRenderer: () => boolean;
46
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
47
+ getClassName: () => string;
48
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
49
+ getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
50
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
51
+ getExtent: () => import("ol/extent").Extent | undefined;
52
+ getMaxResolution: () => number;
53
+ getMinResolution: () => number;
54
+ getMinZoom: () => number;
55
+ getMaxZoom: () => number;
56
+ getOpacity: () => number;
57
+ getSourceState: () => import("ol/source/Source").State;
58
+ getVisible: () => boolean;
59
+ getZIndex: () => number | undefined;
60
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
61
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
62
+ setMaxResolution: (maxResolution: number) => void;
63
+ setMinResolution: (minResolution: number) => void;
64
+ setMaxZoom: (maxZoom: number) => void;
65
+ setMinZoom: (minZoom: number) => void;
66
+ setOpacity: (opacity: number) => void;
67
+ setVisible: (visible: boolean) => void;
68
+ setZIndex: (zindex: number) => void;
69
+ get: (key: string) => any;
70
+ getKeys: () => Array<string>;
71
+ getProperties: () => {
72
+ [x: string]: any;
73
+ };
74
+ getPropertiesInternal: () => {
75
+ [x: string]: any;
76
+ } | null;
77
+ hasProperties: () => boolean;
78
+ notify: (key: string, oldValue: any) => void;
79
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
80
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
81
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
82
+ setProperties: (values: {
83
+ [x: string]: any;
84
+ }, silent?: boolean | undefined) => void;
85
+ unset: (key: string, silent?: boolean | undefined) => void;
86
+ changed: () => void;
87
+ getRevision: () => number;
88
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
89
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
90
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
91
+ hasListener: (type?: string | undefined) => boolean;
92
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
93
+ dispose: () => void;
94
+ };
95
+ } & TBase;
96
+ export default MobilityLayerMixin;
@@ -1,9 +1,6 @@
1
1
  import PropertiesLayerMixin from './PropertiesLayerMixin';
2
2
  function MobilityLayerMixin(Base) {
3
- return class extends PropertiesLayerMixin(Base) {
4
- constructor(options = {}) {
5
- super(options);
6
- }
3
+ return class MobilityLayer extends PropertiesLayerMixin(Base) {
7
4
  };
8
5
  }
9
6
  export default MobilityLayerMixin;