mobility-toolbox-js 3.0.1-beta.8 → 3.1.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.
@@ -76,6 +76,7 @@ declare class RealtimeLayer extends Layer {
76
76
  */
77
77
  constructor(options: RealtimeLayerOptions);
78
78
  attachToMap(): void;
79
+ cleanVectorLayer(): void;
79
80
  /**
80
81
  * Create a copy of the RealtimeLayer.
81
82
  *
@@ -141,6 +142,7 @@ declare class RealtimeLayer extends Layer {
141
142
  */
142
143
  highlightTrajectory(id: RealtimeTrainId): Promise<Feature[] | undefined>;
143
144
  onMoveEnd(): void;
145
+ onRealtimeEngineIdle(): void;
144
146
  /**
145
147
  * Callback when the RealtimeEngine has rendered successfully.
146
148
  */
@@ -106,7 +106,7 @@ class RealtimeLayer extends Layer {
106
106
  this.olEventsKeys = [];
107
107
  // For backward compatibility with v2
108
108
  defineDeprecatedProperties(this, options);
109
- this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
109
+ this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onIdle: this.onRealtimeEngineIdle.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
110
110
  this.allowRenderWhenAnimating = !!options.allowRenderWhenAnimating;
111
111
  // We store the layer used to highlight the full Trajectory
112
112
  this.vectorLayer = new VectorLayer({
@@ -128,7 +128,11 @@ class RealtimeLayer extends Layer {
128
128
  if (this.getVisible()) {
129
129
  this.engine.start();
130
130
  }
131
- this.olEventsKeys.push(...mapInternal.on(['moveend', 'change:target'],
131
+ this.olEventsKeys.push(mapInternal.on('movestart', () => {
132
+ if (this.engine.isUpdateBboxOnMoveEnd) {
133
+ this.engine.updateIdleState();
134
+ }
135
+ }), ...mapInternal.on(['moveend', 'change:target'],
132
136
  // @ts-expect-error - bad ol definitions
133
137
  (evt) => {
134
138
  const view = (evt.map || evt.target).getView();
@@ -157,6 +161,11 @@ class RealtimeLayer extends Layer {
157
161
  }));
158
162
  }
159
163
  }
164
+ cleanVectorLayer() {
165
+ var _a, _b, _c;
166
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
167
+ (_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
168
+ }
160
169
  /**
161
170
  * Create a copy of the RealtimeLayer.
162
171
  *
@@ -259,29 +268,35 @@ class RealtimeLayer extends Layer {
259
268
  */
260
269
  highlightTrajectory(id) {
261
270
  return __awaiter(this, void 0, void 0, function* () {
262
- var _a, _b, _c, _d, _e, _f, _g, _h;
263
- (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
264
- (_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
271
+ var _a, _b, _c, _d, _e, _f;
265
272
  if (!id) {
273
+ this.cleanVectorLayer();
266
274
  return;
267
275
  }
268
276
  const features = yield this.getFullTrajectory(id);
269
277
  if (!(features === null || features === void 0 ? void 0 : features.length)) {
278
+ this.cleanVectorLayer();
270
279
  return;
271
280
  }
272
281
  if (features.length) {
273
- (_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
282
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.addFeatures(features);
283
+ }
284
+ if (this.vectorLayer.getMapInternal() &&
285
+ this.vectorLayer.getMapInternal() !== this.getMapInternal()) {
286
+ (_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
274
287
  }
275
288
  // Add the vector layer to the map
276
289
  const zIndex = this.getZIndex();
277
290
  if (zIndex !== undefined) {
278
291
  this.vectorLayer.setZIndex(zIndex - 1);
279
- (_f = this.getMapInternal()) === null || _f === void 0 ? void 0 : _f.addLayer(this.vectorLayer);
292
+ if (!this.vectorLayer.getMapInternal()) {
293
+ (_d = this.getMapInternal()) === null || _d === void 0 ? void 0 : _d.addLayer(this.vectorLayer);
294
+ }
280
295
  }
281
- else {
282
- const index = ((_g = this.getMapInternal()) === null || _g === void 0 ? void 0 : _g.getLayers().getArray().indexOf(this)) || 0;
296
+ else if (!this.vectorLayer.getMapInternal()) {
297
+ const index = ((_e = this.getMapInternal()) === null || _e === void 0 ? void 0 : _e.getLayers().getArray().indexOf(this)) || 0;
283
298
  if (index) {
284
- (_h = this.getMapInternal()) === null || _h === void 0 ? void 0 : _h.getLayers().insertAt(index, this.vectorLayer);
299
+ (_f = this.getMapInternal()) === null || _f === void 0 ? void 0 : _f.getLayers().insertAt(index, this.vectorLayer);
285
300
  }
286
301
  }
287
302
  return features;
@@ -293,6 +308,9 @@ class RealtimeLayer extends Layer {
293
308
  }
294
309
  this.engine.setBbox();
295
310
  }
311
+ onRealtimeEngineIdle() {
312
+ this.changed();
313
+ }
296
314
  /**
297
315
  * Callback when the RealtimeEngine has rendered successfully.
298
316
  */
@@ -55,8 +55,10 @@ export default class RealtimeLayerRenderer extends CanvasLayerRenderer {
55
55
  return true;
56
56
  }
57
57
  renderFrame(frameState) {
58
- const { canvas, renderedViewState } = this.getLayer();
58
+ var _a;
59
+ const { canvas, engine, renderedViewState } = this.getLayer();
59
60
  this.getLayer().engine.pixelRatio = frameState.pixelRatio;
61
+ this.ready = !!((_a = engine.renderState) === null || _a === void 0 ? void 0 : _a.renderedTrajectories) && engine.isIdle;
60
62
  if (!this.container) {
61
63
  this.container = document.createElement('div');
62
64
  this.container.className = this.getLayer().getClassName();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mobility-toolbox-js",
3
3
  "license": "MIT",
4
4
  "description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
5
- "version": "3.0.1-beta.8",
5
+ "version": "3.1.0-beta.0",
6
6
  "homepage": "https://mobility-toolbox-js.geops.io/",
7
7
  "exports": {
8
8
  ".": "./index.js",