mobility-toolbox-js 3.0.1-beta.7 → 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
@@ -47443,11 +47443,6 @@ uniform ${i3} ${a3} u_${s3};
47443
47443
  if (this.getVisible()) {
47444
47444
  this.engine.start();
47445
47445
  }
47446
- const index = mapInternal.getLayers().getArray().indexOf(this);
47447
- if (this.vectorLayer.getMapInternal() === mapInternal) {
47448
- this.getMapInternal()?.removeLayer(this.vectorLayer);
47449
- }
47450
- mapInternal.getLayers().insertAt(index, this.vectorLayer);
47451
47446
  this.olEventsKeys.push(
47452
47447
  ...mapInternal.on(
47453
47448
  ["moveend", "change:target"],
@@ -47504,29 +47499,49 @@ uniform ${i3} ${a3} u_${s3};
47504
47499
  this.engine.detachFromMap();
47505
47500
  }
47506
47501
  /**
47507
- * Get some informations about a trajectory.
47502
+ * Get the full trajectory of a vehicle as features.
47508
47503
  *
47509
- * @param {RealtimeTrainId} id A vehicle's id.
47510
- * @returns
47511
- */
47512
- getTrajectoryInfos(id) {
47513
- const promises = [
47514
- this.engine.api.getStopSequence(id),
47515
- this.engine.api.getFullTrajectory(
47516
- id,
47517
- this.engine.mode,
47518
- this.engine.getGeneralizationLevelByZoom(
47519
- Math.floor(this.getMapInternal()?.getView()?.getZoom() || 0)
47520
- )
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)
47521
47514
  )
47522
- ];
47523
- return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
47524
- const response = {
47525
- fullTrajectory,
47526
- stopSequence
47527
- };
47528
- return response;
47529
- });
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
+ };
47530
47545
  }
47531
47546
  getVehicles(filterFunc) {
47532
47547
  return this.engine.getVehicles(filterFunc);
@@ -47558,32 +47573,30 @@ uniform ${i3} ${a3} u_${s3};
47558
47573
  /**
47559
47574
  * Highlight the trajectory of journey.
47560
47575
  */
47561
- highlightTrajectory(id) {
47576
+ async highlightTrajectory(id) {
47577
+ this.vectorLayer?.getSource()?.clear(true);
47578
+ this.vectorLayer.getMapInternal()?.removeLayer(this.vectorLayer);
47562
47579
  if (!id) {
47563
- this.vectorLayer?.getSource()?.clear(true);
47564
- return Promise.resolve([]);
47580
+ return;
47565
47581
  }
47566
- return this.engine.api.getFullTrajectory(
47567
- id,
47568
- this.engine.mode,
47569
- this.engine.getGeneralizationLevelByZoom(
47570
- Math.floor(this.getMapInternal()?.getView()?.getZoom() || 0)
47571
- )
47572
- ).then((data) => {
47573
- const fullTrajectory = data.content;
47574
- if (!fullTrajectory?.features?.length) {
47575
- return [];
47576
- }
47577
- const features = format2.readFeatures(fullTrajectory);
47578
- this.vectorLayer?.getSource()?.clear(true);
47579
- if (features.length) {
47580
- 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);
47581
47597
  }
47582
- return features;
47583
- }).catch(() => {
47584
- this.vectorLayer?.getSource()?.clear(true);
47585
- return [];
47586
- });
47598
+ }
47599
+ return features;
47587
47600
  }
47588
47601
  onMoveEnd() {
47589
47602
  if (!this.engine.isUpdateBboxOnMoveEnd || !this.getVisible()) {