mobility-toolbox-js 1.7.8-beta.7 → 1.7.9

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/common/Tracker.js CHANGED
@@ -98,7 +98,6 @@ export default class Tracker {
98
98
 
99
99
  // We simplify the trajectory object
100
100
  const { train_id: id, timeOffset } = trajectory.properties;
101
-
102
101
  // We set the rotation and the timeFraction of the trajectory (used by tralis).
103
102
  // if rotation === null that seems there is no rotation available.
104
103
  const { coord, rotation: rotationIcon } = getVehiclePosition(
@@ -535,14 +535,14 @@ const TrackerLayerMixin = (Base) =>
535
535
  trajectories.sort(this.sort);
536
536
  }
537
537
  // console.timeEnd('sort');
538
- window.trajectories = trajectories;
539
538
 
540
539
  // console.time('render');
541
540
  this.renderState = this.tracker.renderTrajectories(
542
541
  trajectories,
543
542
  { ...viewState, pixelRatio: this.pixelRatio, time },
544
543
  {
545
- noInterpolate,
544
+ noInterpolate:
545
+ viewState.zoom < this.minZoomInterpolation ? true : noInterpolate,
546
546
  hoverVehicleId: this.hoverVehicleId,
547
547
  selectedVehicleId: this.selectedVehicleId,
548
548
  iconScale: this.iconScale,
@@ -21,6 +21,7 @@ export class TralisLayerInterface {
21
21
  * @param {string} options.apiKey Access key for [geOps services](https://developer.geops.io/).
22
22
  * @param {boolean} [options.debug=false] Display additional debug informations.
23
23
  * @param {TralisMode} [options.mode=TralisMode.TOPOGRAPHIC] Tralis's Mode.
24
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom when trains positions start to be interpolated.
24
25
  * @param {number} [options.minZoomNonTrain=9] Minimal zoom when non trains vehicles are allowed to be displayed.
25
26
  */
26
27
  constructor(options = {}) {}
@@ -87,6 +88,7 @@ const TralisLayerMixin = (TrackerLayer) =>
87
88
  this.api = options.api || new TralisAPI(options);
88
89
  this.tenant = options.tenant || ''; // sbb,sbh or sbm
89
90
  this.minZoomNonTrain = options.minZoomNonTrain || 9; // Min zoom level from which non trains are allowed to be displayed. Min value is 9 (as configured by the server
91
+ this.minZoomInterpolation = options.minZoomInterpolation || 8; // Min zoom level from which trains positions are not interpolated.
90
92
  this.format = new GeoJSON();
91
93
  this.generalizationLevelByZoom = options.generalizationLevelByZoom || {
92
94
  0: 5,
@@ -112,6 +114,27 @@ const TralisLayerMixin = (TrackerLayer) =>
112
114
  this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
113
115
  this.onDeleteTrajectoryMessage =
114
116
  this.onDeleteTrajectoryMessage.bind(this);
117
+ this.onDocumentVisibilityChange =
118
+ this.onDocumentVisibilityChange.bind(this);
119
+ }
120
+
121
+ init(map) {
122
+ super.init(map);
123
+
124
+ // To avoid browser hanging when the tab is not visible for a certain amount of time,
125
+ // We stop the rendering and the websocket when hide and start again when show.
126
+ document.addEventListener(
127
+ 'visibilitychange',
128
+ this.onDocumentVisibilityChange,
129
+ );
130
+ }
131
+
132
+ terminate() {
133
+ document.removeEventListener(
134
+ 'visibilitychange',
135
+ this.onDocumentVisibilityChange,
136
+ );
137
+ super.terminate();
115
138
  }
116
139
 
117
140
  start() {
@@ -254,6 +277,16 @@ const TralisLayerMixin = (TrackerLayer) =>
254
277
  // getRefreshTimeInMs() {
255
278
  // return 5000;
256
279
  // }
280
+ onDocumentVisibilityChange() {
281
+ if (!this.visible) {
282
+ return;
283
+ }
284
+ if (document.hidden) {
285
+ this.stop();
286
+ } else {
287
+ this.start();
288
+ }
289
+ }
257
290
 
258
291
  /**
259
292
  * Callback on websocket's trajectory channel events.
@@ -5,7 +5,8 @@ import GeomType from 'ol/geom/GeometryType';
5
5
  *
6
6
  * @param {number} now Current date to interpolate a position with. In ms.
7
7
  * @param {TralisTrajectory} trajectory The trajectory to interpolate.
8
- @returns
8
+ * @param {boolean} noInterpolate If true, the vehicle position is not interpolated on each render but only once.
9
+ * @returns
9
10
  */
10
11
  const getVehiclePosition = (now, trajectory, noInterpolate) => {
11
12
  const {