mobility-toolbox-js 3.0.0-beta.9 → 3.0.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 (105) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +5 -16
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +188 -143
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +21 -11
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +20 -14
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +60 -66
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +0 -102
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +13 -13
  16. package/common/controls/StopFinderControlCommon.js +32 -32
  17. package/common/index.d.ts +1 -1
  18. package/common/index.js +1 -1
  19. package/common/styles/realtimeDefaultStyle.js +6 -11
  20. package/common/styles/realtimeHeadingStyle.js +5 -10
  21. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  22. package/common/styles/realtimeSimpleStyle.js +0 -1
  23. package/common/typedefs.d.ts +11 -121
  24. package/common/typedefs.js +6 -31
  25. package/common/utils/RealtimeEngine.d.ts +214 -0
  26. package/common/utils/RealtimeEngine.js +554 -0
  27. package/common/utils/compareDepartures.d.ts +2 -2
  28. package/common/utils/compareDepartures.js +2 -2
  29. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  30. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  31. package/common/utils/getLayersAsFlatArray.js +0 -1
  32. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  33. package/common/utils/getMapGlCopyrights.js +3 -3
  34. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  35. package/common/utils/getRealtimeModeSuffix.js +1 -0
  36. package/common/utils/getVehiclePosition.d.ts +5 -4
  37. package/common/utils/getVehiclePosition.js +6 -3
  38. package/common/utils/realtimeConfig.d.ts +1 -1
  39. package/common/utils/realtimeConfig.js +0 -1
  40. package/common/utils/renderTrajectories.d.ts +2 -1
  41. package/common/utils/renderTrajectories.js +7 -6
  42. package/common/utils/sortAndFilterDepartures.d.ts +2 -1
  43. package/common/utils/sortAndFilterDepartures.js +2 -1
  44. package/common/utils/sortByDelay.d.ts +2 -2
  45. package/common/utils/sortByDelay.js +5 -1
  46. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  47. package/maplibre/controls/CopyrightControl.js +11 -8
  48. package/maplibre/layers/Layer.d.ts +8 -7
  49. package/maplibre/layers/Layer.js +2 -3
  50. package/maplibre/layers/RealtimeLayer.d.ts +82 -118
  51. package/maplibre/layers/RealtimeLayer.js +154 -118
  52. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  53. package/maplibre/utils/getSourceCoordinates.js +6 -5
  54. package/mbt.js +14611 -14591
  55. package/mbt.js.map +4 -4
  56. package/mbt.min.js +75 -75
  57. package/mbt.min.js.map +4 -4
  58. package/ol/controls/CopyrightControl.d.ts +13 -5
  59. package/ol/controls/CopyrightControl.js +13 -5
  60. package/ol/controls/RoutingControl.d.ts +105 -101
  61. package/ol/controls/RoutingControl.js +250 -264
  62. package/ol/controls/StopFinderControl.d.ts +24 -5
  63. package/ol/controls/StopFinderControl.js +24 -5
  64. package/ol/layers/Layer.d.ts +26 -0
  65. package/ol/layers/Layer.js +39 -0
  66. package/ol/layers/MaplibreLayer.d.ts +56 -28
  67. package/ol/layers/MaplibreLayer.js +154 -31
  68. package/ol/layers/MaplibreStyleLayer.d.ts +71 -149
  69. package/ol/layers/MaplibreStyleLayer.js +281 -210
  70. package/ol/layers/RealtimeLayer.d.ts +95 -230
  71. package/ol/layers/RealtimeLayer.js +209 -211
  72. package/ol/layers/VectorLayer.d.ts +17 -0
  73. package/ol/layers/VectorLayer.js +33 -0
  74. package/ol/layers/index.d.ts +2 -0
  75. package/ol/layers/index.js +3 -0
  76. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  77. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  78. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  79. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  80. package/ol/renderers/RealtimeLayerRenderer.d.ts +7 -7
  81. package/ol/renderers/RealtimeLayerRenderer.js +46 -66
  82. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  83. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  84. package/ol/styles/fullTrajectoryStyle.js +5 -7
  85. package/ol/styles/routingStyle.d.ts +0 -1
  86. package/ol/styles/routingStyle.js +13 -10
  87. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  88. package/ol/utils/defineDeprecatedProperties.js +180 -0
  89. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  90. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  91. package/package.json +44 -44
  92. package/setupTests.js +17 -4
  93. package/types/common.d.ts +53 -69
  94. package/types/index.d.ts +1 -1
  95. package/types/realtime.d.ts +98 -95
  96. package/types/routing.d.ts +60 -60
  97. package/types/stops.d.ts +62 -62
  98. package/common/mixins/RealtimeLayerMixin.d.ts +0 -273
  99. package/common/mixins/RealtimeLayerMixin.js +0 -743
  100. package/ol/layers/MapGlLayer.d.ts +0 -144
  101. package/ol/layers/MapGlLayer.js +0 -144
  102. package/ol/mixins/MobilityLayerMixin.d.ts +0 -98
  103. package/ol/mixins/MobilityLayerMixin.js +0 -6
  104. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -127
  105. package/ol/mixins/PropertiesLayerMixin.js +0 -143
@@ -1,17 +1,17 @@
1
- import GeoJSON from 'ol/format/GeoJSON';
2
- import { Vector as VectorLayer } from 'ol/layer';
3
- import Source from 'ol/source/Source';
4
- import { Vector as VectorSource } from 'ol/source';
5
1
  import debounce from 'lodash.debounce';
2
+ import GeoJSON from 'ol/format/GeoJSON';
6
3
  import Layer from 'ol/layer/Layer';
7
- import RealtimeLayerMixin from '../../common/mixins/RealtimeLayerMixin';
8
- import { fullTrajectoryStyle } from '../styles';
9
- import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
4
+ import VectorLayer from 'ol/layer/Vector';
5
+ import { unByKey } from 'ol/Observable';
6
+ import { Vector as VectorSource } from 'ol/source';
7
+ import Source from 'ol/source/Source';
8
+ import RealtimeEngine from '../../common/utils/RealtimeEngine';
10
9
  import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
11
- /** @private */
10
+ import { fullTrajectoryStyle } from '../styles';
11
+ import defineDeprecatedProperties from '../utils/defineDeprecatedProperties';
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';
@@ -24,76 +24,108 @@ const format = new GeoJSON();
24
24
  *
25
25
  *
26
26
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
27
+ * @see <a href="/example/ol-realtime">OpenLayers Realtime layer example</a>
28
+ *
27
29
  *
28
30
  * @extends {ol/layer/Layer~Layer}
29
31
  *
32
+ *
30
33
  * @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
31
34
  * @public
32
35
  */
33
- // @ts-ignore
34
- class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
36
+ class RealtimeLayer extends Layer {
37
+ get api() {
38
+ return this.engine.api;
39
+ }
40
+ set api(api) {
41
+ this.engine.api = api;
42
+ }
43
+ get canvas() {
44
+ return this.engine.canvas;
45
+ }
46
+ get filter() {
47
+ return this.engine.filter;
48
+ }
49
+ set filter(filter) {
50
+ this.engine.filter = filter;
51
+ }
52
+ get hoverVehicleId() {
53
+ return this.engine.hoverVehicleId;
54
+ }
55
+ set hoverVehicleId(id) {
56
+ this.engine.hoverVehicleId = id;
57
+ }
58
+ get mode() {
59
+ return this.engine.mode;
60
+ }
61
+ set mode(mode) {
62
+ this.engine.mode = mode;
63
+ }
64
+ get pixelRatio() {
65
+ return this.engine.pixelRatio;
66
+ }
67
+ get selectedVehicleId() {
68
+ return this.engine.selectedVehicleId;
69
+ }
70
+ set selectedVehicleId(id) {
71
+ this.engine.selectedVehicleId = id;
72
+ }
73
+ get sort() {
74
+ return this.engine.sort;
75
+ }
76
+ set sort(sort) {
77
+ this.engine.sort = sort;
78
+ }
79
+ get trajectories() {
80
+ return this.engine.trajectories;
81
+ }
35
82
  /**
36
83
  * Constructor.
37
84
  *
38
85
  * @param {RealtimeLayerOptions} options
39
86
  * @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
40
- * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
41
- * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps realtime API url.
42
- *
87
+ * @param {string} options.apiKey Access key for [geOps APIs](https://developer.geops.io/).
88
+ * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The [geOps Realtime API](https://developer.geops.io/apis/realtime/) url.
89
+ * @public
43
90
  */
44
91
  constructor(options) {
45
92
  // We use a group to be able to add custom vector layer in extended class.
46
93
  // For example TrajservLayer use a vectorLayer to display the complete trajectory.
47
94
  super(Object.assign({ source: new Source({}) }, options));
48
- /** @private */
49
95
  this.allowRenderWhenAnimating = false;
50
- /** @private */
96
+ this.maxNbFeaturesRequested = 100;
97
+ this.olEventsKeys = [];
98
+ // For backward compatibility with v2
99
+ defineDeprecatedProperties(this, options);
100
+ this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
51
101
  this.allowRenderWhenAnimating = !!options.allowRenderWhenAnimating;
52
102
  // We store the layer used to highlight the full Trajectory
53
- /** @private */
54
103
  this.vectorLayer = new VectorLayer({
55
- updateWhileAnimating: this.allowRenderWhenAnimating,
56
- updateWhileInteracting: true,
57
104
  source: new VectorSource({ features: [] }),
58
105
  style: (feature, resolution) => {
59
- return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
106
+ return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.engine.styleOptions);
60
107
  },
108
+ updateWhileAnimating: this.allowRenderWhenAnimating,
109
+ updateWhileInteracting: true,
61
110
  });
62
- // Options the last render run did happen. If something changes
63
- // we have to render again
64
- /** @private */
65
- this.renderState = {
66
- center: [0, 0],
67
- zoom: undefined,
68
- rotation: 0,
69
- };
70
- /** @private */
71
111
  this.onZoomEndDebounced = debounce(this.onZoomEnd, 100);
72
- /** @private */
73
112
  this.onMoveEndDebounced = debounce(this.onMoveEnd, 100);
74
113
  }
75
- /**
76
- * @private
77
- */
78
- createRenderer() {
79
- return new RealtimeLayerRenderer(this);
80
- }
81
- /** @private */
82
- attachToMap(map) {
83
- super.attachToMap(map);
84
- if (this.map) {
114
+ attachToMap() {
115
+ this.engine.attachToMap();
116
+ const mapInternal = this.getMapInternal();
117
+ if (mapInternal) {
85
118
  // If the layer is visible we start the rendering clock
86
- if (this.visible) {
87
- this.start();
119
+ if (this.getVisible()) {
120
+ this.engine.start();
88
121
  }
89
- // @ts-expect-error - bad ts check RealtimeLayer is a BaseLayer
90
- const index = this.map.getLayers().getArray().indexOf(this);
91
- this.map.getLayers().insertAt(index, this.vectorLayer);
92
- this.olListenersKeys.push(...this.map.on(['moveend', 'change:target'],
93
- // @ts-expect-error - bad ol definitions
122
+ const index = mapInternal.getLayers().getArray().indexOf(this);
123
+ mapInternal.getLayers().insertAt(index, this.vectorLayer);
124
+ this.olEventsKeys.push(...mapInternal.on(['moveend', 'change:target'],
125
+ // @ts-expect-error - bad ol definitions
94
126
  (evt) => {
95
127
  const view = (evt.map || evt.target).getView();
96
- if (view.getAnimating() || view.getInteracting()) {
128
+ if (!view || (view === null || view === void 0 ? void 0 : view.getAnimating()) || (view === null || view === void 0 ? void 0 : view.getInteracting())) {
97
129
  return;
98
130
  }
99
131
  const zoom = view.getZoom();
@@ -101,15 +133,14 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
101
133
  if (this.currentZoom !== zoom) {
102
134
  this.onZoomEndDebounced(evt);
103
135
  }
104
- /** @private */
105
136
  this.currentZoom = zoom;
106
137
  this.onMoveEndDebounced(evt);
107
138
  }), this.on('change:visible', (evt) => {
108
- if (evt.target.visible) {
109
- this.start();
139
+ if (evt.target.getVisible()) {
140
+ this.engine.start();
110
141
  }
111
142
  else {
112
- this.stop();
143
+ this.engine.stop();
113
144
  }
114
145
  }), this.on('propertychange', (evt) => {
115
146
  // We apply every property change event related to visiblity to the vectorlayer
@@ -119,206 +150,173 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
119
150
  }));
120
151
  }
121
152
  }
153
+ /**
154
+ * Create a copy of the RealtimeLayer.
155
+ *
156
+ * @param {Object} newOptions Options to override. See constructor.
157
+ * @return {RealtimeLayer} A RealtimeLayer
158
+ * @public
159
+ */
160
+ clone(newOptions) {
161
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.get('options')), newOptions));
162
+ }
163
+ createRenderer() {
164
+ return new RealtimeLayerRenderer(this);
165
+ }
122
166
  /**
123
167
  * Destroy the container of the tracker.
124
- * @private
125
168
  */
126
169
  detachFromMap() {
127
170
  var _a;
128
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
129
- super.detachFromMap();
171
+ unByKey(this.olEventsKeys);
172
+ (_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
173
+ this.engine.detachFromMap();
130
174
  }
131
175
  /**
132
- * Render the trajectories using current map's size, resolution and rotation.
133
- * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
134
- * @overrides
135
- * @private
176
+ * Get some informations about a trajectory.
177
+ *
178
+ * @param {RealtimeTrainId} id A vehicle's id.
179
+ * @returns
136
180
  */
137
- // @ts-ignore
138
- renderTrajectories(noInterpolate) {
139
- if (!this.map) {
140
- return;
141
- }
142
- const view = this.map.getView();
143
- // it could happen that the view is set but without center yet,
144
- // so the calcualteExtent will trigger an error.
145
- if (!view.getCenter()) {
146
- return;
181
+ getTrajectoryInfos(id) {
182
+ var _a, _b;
183
+ // When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
184
+ // Then we combine them in one response and send them to inherited layers.
185
+ const promises = [
186
+ this.engine.api.getStopSequence(id),
187
+ this.engine.api.getFullTrajectory(id, this.engine.mode, this.engine.getGeneralizationLevelByZoom(Math.floor(((_b = (_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.getZoom()) || 0))),
188
+ ];
189
+ return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
190
+ const response = {
191
+ fullTrajectory,
192
+ stopSequence,
193
+ };
194
+ return response;
195
+ });
196
+ }
197
+ getVehicles(filterFunc) {
198
+ return this.engine.getVehicles(filterFunc);
199
+ }
200
+ getViewState() {
201
+ const mapInternal = this.getMapInternal();
202
+ if (!(mapInternal === null || mapInternal === void 0 ? void 0 : mapInternal.getView())) {
203
+ return {};
147
204
  }
148
- super.renderTrajectories({
149
- size: this.map.getSize(),
205
+ const view = mapInternal.getView();
206
+ return {
150
207
  center: view.getCenter(),
151
208
  extent: view.calculateExtent(),
209
+ pixelRatio: this.engine.pixelRatio,
152
210
  resolution: view.getResolution(),
153
211
  rotation: view.getRotation(),
212
+ size: mapInternal.getSize(),
213
+ visible: this.getVisible(),
154
214
  zoom: view.getZoom(),
155
- pixelRatio: this.pixelRatio,
156
- }, noInterpolate);
157
- }
158
- /**
159
- * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
160
- * @private
161
- * @override
162
- */
163
- renderTrajectoriesInternal(viewState, noInterpolate) {
164
- if (!this.map) {
165
- return false;
166
- }
167
- let isRendered = false;
168
- const blockRendering = this.allowRenderWhenAnimating
169
- ? false
170
- : this.map.getView().getAnimating() ||
171
- this.map.getView().getInteracting();
172
- // Don't render the map when the map is animating or interacting.
173
- isRendered = blockRendering
174
- ? false
175
- : super.renderTrajectoriesInternal(viewState, noInterpolate);
176
- // We update the current render state.
177
- if (isRendered) {
178
- /** @private */
179
- this.renderedViewState = Object.assign({}, viewState);
180
- // @ts-expect-error - we are in the same class
181
- const { container } = this.getRenderer();
182
- if (container) {
183
- container.style.transform = '';
184
- }
185
- }
186
- return isRendered;
187
- }
188
- /**
189
- * Return the delay in ms before the next rendering.
190
- * @private
191
- */
192
- getRefreshTimeInMs() {
193
- return super.getRefreshTimeInMs(this.map.getView().getZoom());
194
- }
195
- /**
196
- * On move end we update the websocket with the new bbox.
197
- *
198
- * @private
199
- * @override
200
- */
201
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
202
- onMoveEnd(evt) {
203
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
204
- return;
205
- }
206
- this.setBbox();
207
- }
208
- /**
209
- * Function called on moveend event only when the zoom has changed.
210
- *
211
- * @param {ol/MapEvent~MapEvent} evt Moveend event.
212
- * @private
213
- * @override
214
- */
215
- // eslint-disable-next-line no-unused-vars
216
- onZoomEnd() {
217
- super.onZoomEnd();
218
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
219
- return;
220
- }
221
- if (this.selectedVehicleId) {
222
- this.highlightTrajectory(this.selectedVehicleId);
223
- }
215
+ };
224
216
  }
225
217
  highlight(feature) {
226
- this.highlightVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
227
- }
228
- select(feature) {
229
- this.selectVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
230
- this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
231
- }
232
- // /**
233
- // * Update the cursor style when hovering a vehicle.
234
- // *
235
- // * @private
236
- // * @override
237
- // */
238
- // onFeatureHover(
239
- // features: Feature[],
240
- // layer: RealtimeLayer,
241
- // coordinate: Coordinate,
242
- // ) {
243
- // super.onFeatureHover(features, layer, coordinate);
244
- // this.map.getTargetElement().style.cursor = features.length
245
- // ? 'pointer'
246
- // : 'auto';
247
- // }
248
- // /**
249
- // * Display the complete trajectory of the vehicle.
250
- // *
251
- // * @private
252
- // * @override
253
- // */
254
- // onFeatureClick(
255
- // features: Feature[],
256
- // layer: RealtimeLayer,
257
- // coordinate: Coordinate,
258
- // ) {
259
- // super.onFeatureClick(features, layer, coordinate);
260
- // this.highlightTrajectory(this.selectedVehicleId);
261
- // }
262
- /**
263
- * Remove the trajectory form the list if necessary.
264
- *
265
- * @private
266
- */
267
- purgeTrajectory(trajectory, extent, zoom) {
268
- const center = this.map.getView().getCenter();
269
- if (!extent && !center) {
270
- // In that case the view is not zoomed yet so we can't calculate the extent of the map,
271
- // it will trigger a js error on calculateExtent function.
272
- return false;
218
+ const id = feature === null || feature === void 0 ? void 0 : feature.get('train_id');
219
+ if (this.hoverVehicleId !== id) {
220
+ this.hoverVehicleId = id;
221
+ this.engine.renderTrajectories(true);
273
222
  }
274
- return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom() || 0);
275
- }
276
- /**
277
- * Send the current bbox to the websocket
278
- *
279
- * @private
280
- */
281
- setBbox(extent, zoom) {
282
- super.setBbox(extent ||
283
- this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom() || 0);
284
223
  }
285
224
  /**
286
225
  * Highlight the trajectory of journey.
287
- * @private
288
226
  */
289
227
  highlightTrajectory(id) {
290
- var _a, _b;
228
+ var _a, _b, _c, _d;
291
229
  if (!id) {
292
- this.vectorLayer.getSource().clear(true);
230
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
293
231
  return Promise.resolve([]);
294
232
  }
295
- return this.api
296
- .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)))
233
+ return this.engine.api
234
+ .getFullTrajectory(id, this.engine.mode, this.engine.getGeneralizationLevelByZoom(Math.floor(((_d = (_c = this.getMapInternal()) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0)))
297
235
  .then((data) => {
298
- var _a;
236
+ var _a, _b, _c, _d, _e;
299
237
  const fullTrajectory = data.content;
300
238
  if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
301
239
  return [];
302
240
  }
303
241
  const features = format.readFeatures(fullTrajectory);
304
- this.vectorLayer.getSource().clear(true);
242
+ (_c = (_b = this.vectorLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear(true);
305
243
  if (features.length) {
306
- this.vectorLayer.getSource().addFeatures(features);
244
+ (_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
307
245
  }
308
246
  return features;
309
247
  })
310
248
  .catch(() => {
311
- this.vectorLayer.getSource().clear(true);
249
+ var _a, _b;
250
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
312
251
  return [];
313
252
  });
314
253
  }
254
+ onMoveEnd() {
255
+ if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {
256
+ return;
257
+ }
258
+ this.engine.setBbox();
259
+ }
315
260
  /**
316
- * Create a copy of the RealtimeLayer.
317
- * @param {Object} newOptions Options to override
318
- * @return {RealtimeLayer} A RealtimeLayer
261
+ * Callback when the RealtimeEngine has rendered successfully.
319
262
  */
320
- clone(newOptions) {
321
- return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
263
+ onRealtimeEngineRender(renderState, viewState) {
264
+ this.renderedViewState = Object.assign({}, viewState);
265
+ // @ts-expect-error - we are in the same class
266
+ const { container } = this.getRenderer();
267
+ if (container) {
268
+ container.style.transform = '';
269
+ }
270
+ }
271
+ onZoomEnd() {
272
+ this.engine.onZoomEnd();
273
+ if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {
274
+ return;
275
+ }
276
+ if (this.selectedVehicleId) {
277
+ this.highlightTrajectory(this.selectedVehicleId);
278
+ }
279
+ }
280
+ select(feature) {
281
+ const id = feature === null || feature === void 0 ? void 0 : feature.get('train_id');
282
+ if (this.selectedVehicleId !== id) {
283
+ this.selectedVehicleId = id;
284
+ this.engine.renderTrajectories(true);
285
+ }
286
+ this.highlightTrajectory(id);
287
+ }
288
+ setMapInternal(map) {
289
+ if (map) {
290
+ super.setMapInternal(map);
291
+ this.attachToMap();
292
+ }
293
+ else {
294
+ this.detachFromMap();
295
+ super.setMapInternal(map);
296
+ }
297
+ }
298
+ shouldRender() {
299
+ var _a, _b;
300
+ return this.allowRenderWhenAnimating
301
+ ? false
302
+ : ((_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getView().getAnimating()) ||
303
+ ((_b = this.getMapInternal()) === null || _b === void 0 ? void 0 : _b.getView().getInteracting());
304
+ }
305
+ /**
306
+ * Start the rendering.
307
+ *
308
+ * @public
309
+ */
310
+ start() {
311
+ this.engine.start();
312
+ }
313
+ /**
314
+ * Stop the rendering.
315
+ *
316
+ * @public
317
+ */
318
+ stop() {
319
+ this.engine.stop();
322
320
  }
323
321
  }
324
322
  export default RealtimeLayer;
@@ -0,0 +1,17 @@
1
+ import { Coordinate } from 'ol/coordinate';
2
+ import { LayerGetFeatureInfoResponse } from '../../types';
3
+ import Layer, { MobilityLayerOptions } from './Layer';
4
+ /**
5
+ * @deprecated
6
+ */
7
+ declare class VectorLayer extends Layer {
8
+ /**
9
+ * @deprecated
10
+ */
11
+ clone(newOptions: MobilityLayerOptions): VectorLayer;
12
+ /**
13
+ * @deprecated
14
+ */
15
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
16
+ }
17
+ export default VectorLayer;
@@ -0,0 +1,33 @@
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.get('options')), newOptions));
11
+ }
12
+ /**
13
+ * @deprecated
14
+ */
15
+ getFeatureInfoAtCoordinate(coordinate) {
16
+ let features = [];
17
+ const mapInternal = this.getMapInternal();
18
+ if (mapInternal) {
19
+ const pixel = mapInternal.getPixelFromCoordinate(coordinate);
20
+ features =
21
+ mapInternal.getFeaturesAtPixel(pixel, {
22
+ hitTolerance: this.get('hitTolerance') || 5,
23
+ layerFilter: (l) => l === this,
24
+ }) || [];
25
+ }
26
+ return Promise.resolve({
27
+ coordinate,
28
+ features,
29
+ layer: this,
30
+ });
31
+ }
32
+ }
33
+ export default VectorLayer;
@@ -1,3 +1,5 @@
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
+ 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';
@@ -1,20 +0,0 @@
1
- import { FrameState } from 'ol/Map';
2
- import LayerRenderer from 'ol/renderer/Layer';
3
- import { Coordinate } from 'ol/coordinate';
4
- import { FeatureCallback } from 'ol/renderer/vector';
5
- import { Feature } from 'ol';
6
- import { Geometry } from 'ol/geom';
7
- import { Pixel } from 'ol/pixel';
8
- import type MaplibreLayer from '../layers/MaplibreLayer';
9
- /**
10
- * This class is a renderer for Maplibre Layer to be able to use the native ol
11
- * functionnalities like map.getFeaturesAtPixel or map.hasFeatureAtPixel.
12
- * @private
13
- */
14
- export default class MaplibreLayerRenderer extends LayerRenderer<MaplibreLayer> {
15
- getFeaturesAtCoordinate(coordinate: Coordinate | undefined, hitTolerance?: number): Feature<Geometry>[];
16
- prepareFrame(): boolean;
17
- renderFrame(frameState: FrameState): HTMLElement | null;
18
- getFeatures(pixel: Pixel): Promise<Feature<Geometry>[]>;
19
- forEachFeatureAtCoordinate<Feature>(coordinate: Coordinate, frameState: FrameState, hitTolerance: number, callback: FeatureCallback<Feature>): Feature | undefined;
20
- }