mobility-toolbox-js 3.0.1-beta.9 → 3.1.0-beta.1

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.
@@ -25,6 +25,7 @@ export interface RealtimeEngineOptions {
25
25
  minZoomInterpolation?: number;
26
26
  mode?: RealtimeMode;
27
27
  motsByZoom?: RealtimeMot[][];
28
+ onIdle?: (realtimeEngine: RealtimeEngine) => void;
28
29
  onRender?: (renderState: RealtimeRenderState, viewState: ViewState) => void;
29
30
  onStart?: (realtimeEngine: RealtimeEngine) => void;
30
31
  onStop?: (realtimeEngine: RealtimeEngine) => void;
@@ -52,6 +53,7 @@ export interface RealtimeEngineOptions {
52
53
  * This class is totally agnostic from Maplibre or OpenLayers and must stay taht way.
53
54
  */
54
55
  declare class RealtimeEngine {
56
+ _idleTimeout?: number;
55
57
  _mode: RealtimeMode;
56
58
  _speed: number;
57
59
  _style: RealtimeStyleFunction;
@@ -69,11 +71,13 @@ declare class RealtimeEngine {
69
71
  getMotsByZoom: (zoom: number) => RealtimeMot[];
70
72
  getRenderTimeIntervalByZoom: (zoom: number) => number;
71
73
  hoverVehicleId?: RealtimeTrainId;
74
+ isIdle: boolean;
72
75
  isUpdateBboxOnMoveEnd: boolean;
73
76
  live?: boolean;
74
77
  minZoomInterpolation: number;
75
78
  mots?: RealtimeMot[];
76
79
  motsByZoom: RealtimeMot[][];
80
+ onIdle?: (realtimeLayer: RealtimeEngine) => void;
77
81
  onRender?: (renderState: RealtimeRenderState, viewState: ViewState) => void;
78
82
  onStart?: (realtimeLayer: RealtimeEngine) => void;
79
83
  onStop?: (realtimeLayer: RealtimeEngine) => void;
@@ -210,5 +214,6 @@ declare class RealtimeEngine {
210
214
  * @private
211
215
  */
212
216
  stopUpdateTime(): void;
217
+ updateIdleState(): void;
213
218
  }
214
219
  export default RealtimeEngine;
@@ -52,6 +52,7 @@ class RealtimeEngine {
52
52
  this.renderTrajectories();
53
53
  }
54
54
  constructor(options) {
55
+ this.isIdle = false;
55
56
  this.getViewState = () => ({});
56
57
  this.shouldRender = () => true;
57
58
  this._mode = options.mode || RealtimeModes.TOPOGRAPHIC;
@@ -88,6 +89,7 @@ class RealtimeEngine {
88
89
  this.getViewState = options.getViewState || (() => ({}));
89
90
  this.shouldRender = options.shouldRender || (() => true);
90
91
  this.onRender = options.onRender;
92
+ this.onIdle = options.onIdle;
91
93
  this.onStart = options.onStart;
92
94
  this.onStop = options.onStop;
93
95
  this.format = new GeoJSON();
@@ -279,6 +281,7 @@ class RealtimeEngine {
279
281
  * @private
280
282
  */
281
283
  onTrajectoryMessage(data) {
284
+ this.updateIdleState();
282
285
  if (!data.content) {
283
286
  return;
284
287
  }
@@ -439,6 +442,7 @@ class RealtimeEngine {
439
442
  return true;
440
443
  }
441
444
  setBbox() {
445
+ this.updateIdleState();
442
446
  const viewState = this.getViewState();
443
447
  const extent = viewState.extent;
444
448
  const zoom = viewState.zoom || 0;
@@ -550,5 +554,14 @@ class RealtimeEngine {
550
554
  this.updateTimeInterval = undefined;
551
555
  }
552
556
  }
557
+ updateIdleState() {
558
+ this.isIdle = false;
559
+ clearTimeout(this._idleTimeout);
560
+ this._idleTimeout = window.setTimeout(() => {
561
+ var _a;
562
+ this.isIdle = true;
563
+ (_a = this.onIdle) === null || _a === void 0 ? void 0 : _a.call(this, this);
564
+ }, 1000);
565
+ }
553
566
  }
554
567
  export default RealtimeEngine;
@@ -28,7 +28,10 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
28
28
  const context = canvas.getContext('2d');
29
29
  context === null || context === void 0 ? void 0 : context.clearRect(0, 0, canvas.width, canvas.height);
30
30
  const [width, height] = size;
31
- if (width && height && (canvas.width !== width || canvas.height !== height)) {
31
+ if (width &&
32
+ height &&
33
+ (canvas.width !== width * pixelRatio ||
34
+ canvas.height !== height * pixelRatio)) {
32
35
  [canvas.width, canvas.height] = [width * pixelRatio, height * pixelRatio];
33
36
  }
34
37
  const coordinateToPixelTransform = compose(create(), size[0] / 2, size[1] / 2, 1 / resolution, -1 / resolution, -rotation, -center[0], -center[1]);
@@ -105,6 +108,7 @@ const renderTrajectories = (canvas, trajectories, style, viewState, options) =>
105
108
  context === null || context === void 0 ? void 0 : context.drawImage(hoverVehicleImg, Math.floor(hoverVehiclePx[0] - hoverVehicleImg.width / 2), Math.floor(hoverVehiclePx[1] - hoverVehicleImg.height / 2));
106
109
  }
107
110
  return {
111
+ // isReady: true,
108
112
  renderedTrajectories,
109
113
  };
110
114
  };
package/mbt.js CHANGED
@@ -25318,7 +25318,7 @@ uniform ${i3} ${a3} u_${s3};
25318
25318
  const context = canvas2.getContext("2d");
25319
25319
  context?.clearRect(0, 0, canvas2.width, canvas2.height);
25320
25320
  const [width, height] = size;
25321
- if (width && height && (canvas2.width !== width || canvas2.height !== height)) {
25321
+ if (width && height && (canvas2.width !== width * pixelRatio || canvas2.height !== height * pixelRatio)) {
25322
25322
  [canvas2.width, canvas2.height] = [width * pixelRatio, height * pixelRatio];
25323
25323
  }
25324
25324
  const coordinateToPixelTransform = compose(
@@ -25400,6 +25400,7 @@ uniform ${i3} ${a3} u_${s3};
25400
25400
  );
25401
25401
  }
25402
25402
  return {
25403
+ // isReady: true,
25403
25404
  renderedTrajectories
25404
25405
  };
25405
25406
  };
@@ -46563,6 +46564,7 @@ uniform ${i3} ${a3} u_${s3};
46563
46564
  var import_lodash5 = __toESM(require_lodash2());
46564
46565
  var RealtimeEngine = class {
46565
46566
  constructor(options) {
46567
+ this.isIdle = false;
46566
46568
  this.getViewState = () => ({});
46567
46569
  this.shouldRender = () => true;
46568
46570
  this._mode = options.mode || RealtimeModes.TOPOGRAPHIC;
@@ -46589,6 +46591,7 @@ uniform ${i3} ${a3} u_${s3};
46589
46591
  this.getViewState = options.getViewState || (() => ({}));
46590
46592
  this.shouldRender = options.shouldRender || (() => true);
46591
46593
  this.onRender = options.onRender;
46594
+ this.onIdle = options.onIdle;
46592
46595
  this.onStart = options.onStart;
46593
46596
  this.onStop = options.onStop;
46594
46597
  this.format = new GeoJSON_default();
@@ -46850,6 +46853,7 @@ uniform ${i3} ${a3} u_${s3};
46850
46853
  * @private
46851
46854
  */
46852
46855
  onTrajectoryMessage(data) {
46856
+ this.updateIdleState();
46853
46857
  if (!data.content) {
46854
46858
  return;
46855
46859
  }
@@ -47008,6 +47012,7 @@ uniform ${i3} ${a3} u_${s3};
47008
47012
  return true;
47009
47013
  }
47010
47014
  setBbox() {
47015
+ this.updateIdleState();
47011
47016
  const viewState = this.getViewState();
47012
47017
  const extent = viewState.extent;
47013
47018
  const zoom = viewState.zoom || 0;
@@ -47113,6 +47118,14 @@ uniform ${i3} ${a3} u_${s3};
47113
47118
  this.updateTimeInterval = void 0;
47114
47119
  }
47115
47120
  }
47121
+ updateIdleState() {
47122
+ this.isIdle = false;
47123
+ clearTimeout(this._idleTimeout);
47124
+ this._idleTimeout = window.setTimeout(() => {
47125
+ this.isIdle = true;
47126
+ this.onIdle?.(this);
47127
+ }, 1e3);
47128
+ }
47116
47129
  };
47117
47130
  var RealtimeEngine_default = RealtimeEngine;
47118
47131
 
@@ -47165,8 +47178,9 @@ uniform ${i3} ${a3} u_${s3};
47165
47178
  return true;
47166
47179
  }
47167
47180
  renderFrame(frameState) {
47168
- const { canvas: canvas2, renderedViewState } = this.getLayer();
47181
+ const { canvas: canvas2, engine, renderedViewState } = this.getLayer();
47169
47182
  this.getLayer().engine.pixelRatio = frameState.pixelRatio;
47183
+ this.ready = !!engine.renderState?.renderedTrajectories && engine.isIdle;
47170
47184
  if (!this.container) {
47171
47185
  this.container = document.createElement("div");
47172
47186
  this.container.className = this.getLayer().getClassName();
@@ -47372,6 +47386,7 @@ uniform ${i3} ${a3} u_${s3};
47372
47386
  defineDeprecatedProperties_default(this, options);
47373
47387
  this.engine = new RealtimeEngine_default({
47374
47388
  getViewState: this.getViewState.bind(this),
47389
+ onIdle: this.onRealtimeEngineIdle.bind(this),
47375
47390
  onRender: this.onRealtimeEngineRender.bind(this),
47376
47391
  ...options
47377
47392
  });
@@ -47444,6 +47459,11 @@ uniform ${i3} ${a3} u_${s3};
47444
47459
  this.engine.start();
47445
47460
  }
47446
47461
  this.olEventsKeys.push(
47462
+ mapInternal.on("movestart", () => {
47463
+ if (this.engine.isUpdateBboxOnMoveEnd) {
47464
+ this.engine.updateIdleState();
47465
+ }
47466
+ }),
47447
47467
  ...mapInternal.on(
47448
47468
  ["moveend", "change:target"],
47449
47469
  // @ts-expect-error - bad ol definitions
@@ -47613,6 +47633,9 @@ uniform ${i3} ${a3} u_${s3};
47613
47633
  }
47614
47634
  this.engine.setBbox();
47615
47635
  }
47636
+ onRealtimeEngineIdle() {
47637
+ this.changed();
47638
+ }
47616
47639
  /**
47617
47640
  * Callback when the RealtimeEngine has rendered successfully.
47618
47641
  */