mobility-toolbox-js 3.0.1-beta.6 → 3.0.1-beta.8

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.
package/mbt.js CHANGED
@@ -45998,6 +45998,11 @@ uniform ${i3} ${a3} u_${s3};
45998
45998
  detachFromMap() {
45999
45999
  unByKey(this.olEventsKeys);
46000
46000
  }
46001
+ disposeInternal() {
46002
+ const source = this.getSource();
46003
+ super.disposeInternal();
46004
+ this.setSource(source);
46005
+ }
46001
46006
  getStyle() {
46002
46007
  if (this.style && typeof this.style === "object" && this.style.name && this.style.version) {
46003
46008
  return this.style;
@@ -47438,11 +47443,6 @@ uniform ${i3} ${a3} u_${s3};
47438
47443
  if (this.getVisible()) {
47439
47444
  this.engine.start();
47440
47445
  }
47441
- const index = mapInternal.getLayers().getArray().indexOf(this);
47442
- if (this.vectorLayer.getMapInternal() === mapInternal) {
47443
- this.getMapInternal()?.removeLayer(this.vectorLayer);
47444
- }
47445
- mapInternal.getLayers().insertAt(index, this.vectorLayer);
47446
47446
  this.olEventsKeys.push(
47447
47447
  ...mapInternal.on(
47448
47448
  ["moveend", "change:target"],
@@ -47499,29 +47499,49 @@ uniform ${i3} ${a3} u_${s3};
47499
47499
  this.engine.detachFromMap();
47500
47500
  }
47501
47501
  /**
47502
- * Get some informations about a trajectory.
47502
+ * Get the full trajectory of a vehicle as features.
47503
47503
  *
47504
- * @param {RealtimeTrainId} id A vehicle's id.
47505
- * @returns
47506
- */
47507
- getTrajectoryInfos(id) {
47508
- const promises = [
47509
- this.engine.api.getStopSequence(id),
47510
- this.engine.api.getFullTrajectory(
47511
- id,
47512
- this.engine.mode,
47513
- this.engine.getGeneralizationLevelByZoom(
47514
- Math.floor(this.getMapInternal()?.getView()?.getZoom() || 0)
47515
- )
47504
+ * @param {string} id A vehicle's id.
47505
+ * @returns {Promise<Feature[]>} A list of features representing a full trajectory.
47506
+ * @public
47507
+ */
47508
+ async getFullTrajectory(id) {
47509
+ const data = await this.engine.api.getFullTrajectory(
47510
+ id,
47511
+ this.engine.mode,
47512
+ this.engine.getGeneralizationLevelByZoom(
47513
+ Math.floor(this.getMapInternal()?.getView()?.getZoom() || 0)
47516
47514
  )
47517
- ];
47518
- return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
47519
- const response = {
47520
- fullTrajectory,
47521
- stopSequence
47522
- };
47523
- return response;
47524
- });
47515
+ );
47516
+ if (data?.content?.features?.length) {
47517
+ return format2.readFeatures(data?.content);
47518
+ }
47519
+ return [];
47520
+ }
47521
+ /**
47522
+ * Get the stop sequences of a vehicle.
47523
+ *
47524
+ * @param {string} id A vehicle's id.
47525
+ * @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences.
47526
+ * @public
47527
+ */
47528
+ async getStopSequences(id) {
47529
+ const data = await this.engine.api.getStopSequence(id);
47530
+ return data?.content;
47531
+ }
47532
+ /**
47533
+ * Get full trajectory and stop sequences of a vehicle.
47534
+ *
47535
+ * @param {RealtimeTrainId} id A vehicle's id.
47536
+ * @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences.
47537
+ */
47538
+ async getTrajectoryInfos(id) {
47539
+ const promises = [this.getStopSequences(id), this.getFullTrajectory(id)];
47540
+ const [stopSequences, fullTrajectory] = await Promise.all(promises);
47541
+ return {
47542
+ fullTrajectory,
47543
+ stopSequences
47544
+ };
47525
47545
  }
47526
47546
  getVehicles(filterFunc) {
47527
47547
  return this.engine.getVehicles(filterFunc);
@@ -47553,32 +47573,30 @@ uniform ${i3} ${a3} u_${s3};
47553
47573
  /**
47554
47574
  * Highlight the trajectory of journey.
47555
47575
  */
47556
- highlightTrajectory(id) {
47576
+ async highlightTrajectory(id) {
47577
+ this.vectorLayer?.getSource()?.clear(true);
47578
+ this.vectorLayer.getMapInternal()?.removeLayer(this.vectorLayer);
47557
47579
  if (!id) {
47558
- this.vectorLayer?.getSource()?.clear(true);
47559
- return Promise.resolve([]);
47580
+ return;
47560
47581
  }
47561
- return this.engine.api.getFullTrajectory(
47562
- id,
47563
- this.engine.mode,
47564
- this.engine.getGeneralizationLevelByZoom(
47565
- Math.floor(this.getMapInternal()?.getView()?.getZoom() || 0)
47566
- )
47567
- ).then((data) => {
47568
- const fullTrajectory = data.content;
47569
- if (!fullTrajectory?.features?.length) {
47570
- return [];
47571
- }
47572
- const features = format2.readFeatures(fullTrajectory);
47573
- this.vectorLayer?.getSource()?.clear(true);
47574
- if (features.length) {
47575
- this.vectorLayer?.getSource()?.addFeatures(features);
47582
+ const features = await this.getFullTrajectory(id);
47583
+ if (!features?.length) {
47584
+ return;
47585
+ }
47586
+ if (features.length) {
47587
+ this.vectorLayer?.getSource()?.addFeatures(features);
47588
+ }
47589
+ const zIndex = this.getZIndex();
47590
+ if (zIndex !== void 0) {
47591
+ this.vectorLayer.setZIndex(zIndex - 1);
47592
+ this.getMapInternal()?.addLayer(this.vectorLayer);
47593
+ } else {
47594
+ const index = this.getMapInternal()?.getLayers().getArray().indexOf(this) || 0;
47595
+ if (index) {
47596
+ this.getMapInternal()?.getLayers().insertAt(index, this.vectorLayer);
47576
47597
  }
47577
- return features;
47578
- }).catch(() => {
47579
- this.vectorLayer?.getSource()?.clear(true);
47580
- return [];
47581
- });
47598
+ }
47599
+ return features;
47582
47600
  }
47583
47601
  onMoveEnd() {
47584
47602
  if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {