mobility-toolbox-js 2.0.0-beta.59 → 2.0.0-beta.60

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
@@ -34164,14 +34164,8 @@ uniform ${i3} ${o3} u_${a3};
34164
34164
  var debounceWebsocketMessages_default = debounceWebsocketMessages;
34165
34165
 
34166
34166
  // src/common/utils/getRealtimeModeSuffix.ts
34167
- var getRealtimeModeSuffix = (mode, modes, tenant) => {
34168
- const schematicSuffix = ["", "schematic"];
34169
- if (tenant) {
34170
- schematicSuffix.push(tenant);
34171
- }
34172
- return mode === modes.SCHEMATIC ? schematicSuffix.join("_") : "";
34173
- };
34174
- var getRealtimeModeSuffix_default = getRealtimeModeSuffix;
34167
+ var getModeSuffix = (mode, modes) => mode === modes.SCHEMATIC ? "_schematic" : "";
34168
+ var getRealtimeModeSuffix_default = getModeSuffix;
34175
34169
 
34176
34170
  // src/api/RealtimeAPI.ts
34177
34171
  var RealtimeModes = {
@@ -34182,7 +34176,7 @@ uniform ${i3} ${o3} u_${a3};
34182
34176
  var RealtimeAPI = class {
34183
34177
  constructor(options = {}) {
34184
34178
  this.defineProperties(options);
34185
- this.tenant = options.tenant;
34179
+ this.prefix = options.prefix || "";
34186
34180
  this.onOpen = this.onOpen.bind(this);
34187
34181
  }
34188
34182
  defineProperties(options) {
@@ -34301,9 +34295,9 @@ uniform ${i3} ${o3} u_${a3};
34301
34295
  this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
34302
34296
  }
34303
34297
  unsubscribe(channel, suffix = "", onMessage) {
34304
- const suffixSchematic = getRealtimeModeSuffix_default(RealtimeModes.SCHEMATIC, RealtimeModes, this.tenant);
34305
- const suffixTopographic = getRealtimeModeSuffix_default(RealtimeModes.TOPOGRAPHIC, RealtimeModes, this.tenant);
34306
- this.wsApi.unsubscribe(`${channel}${suffixSchematic}${suffix || ""}`, onMessage);
34298
+ const suffixSchenatic = getRealtimeModeSuffix_default(RealtimeModes.SCHEMATIC, RealtimeModes);
34299
+ const suffixTopographic = getRealtimeModeSuffix_default(RealtimeModes.TOPOGRAPHIC, RealtimeModes);
34300
+ this.wsApi.unsubscribe(`${channel}${suffixSchenatic}${suffix || ""}`, onMessage);
34307
34301
  this.wsApi.unsubscribe(`${channel}${suffixTopographic}${suffix || ""}`, onMessage);
34308
34302
  }
34309
34303
  subscribeDepartures(stationId, onMessage, onError = () => {
@@ -34315,16 +34309,14 @@ uniform ${i3} ${o3} u_${a3};
34315
34309
  }
34316
34310
  subscribeDisruptions(onMessage, onError = () => {
34317
34311
  }, quiet = false) {
34318
- const channel = [this.tenant, "newsticker"];
34319
- this.subscribe(channel.join("_"), onMessage, onError, quiet);
34312
+ this.subscribe(`${this.prefix}newsticker`, onMessage, onError, quiet);
34320
34313
  }
34321
34314
  unsubscribeDisruptions(onMessage) {
34322
- const channel = [this.tenant, "newsticker"];
34323
- this.unsubscribe(channel.join("_"), "", onMessage);
34315
+ this.unsubscribe(`${this.prefix}newsticker`, "", onMessage);
34324
34316
  }
34325
34317
  getStation(uic, mode) {
34326
34318
  const params = {
34327
- channel: `station${getRealtimeModeSuffix_default(mode, RealtimeModes, this.tenant)}`,
34319
+ channel: `station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`,
34328
34320
  args: uic
34329
34321
  };
34330
34322
  return new Promise((resolve, reject) => {
@@ -34334,13 +34326,13 @@ uniform ${i3} ${o3} u_${a3};
34334
34326
  getStations(mode, timeout = 100) {
34335
34327
  return new Promise((resolve) => {
34336
34328
  this.wsApi.get({
34337
- channel: `station${getRealtimeModeSuffix_default(mode, RealtimeModes, this.tenant)}`
34329
+ channel: `station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`
34338
34330
  }, debounceWebsocketMessages_default(resolve, void 0, timeout));
34339
34331
  });
34340
34332
  }
34341
34333
  subscribeStations(mode, onMessage, onError = () => {
34342
34334
  }, quiet = false) {
34343
- this.subscribe(`station${getRealtimeModeSuffix_default(mode, RealtimeModes, this.tenant)}`, onMessage, onError, quiet);
34335
+ this.subscribe(`station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
34344
34336
  }
34345
34337
  unsubscribeStations(onMessage) {
34346
34338
  this.unsubscribe("station", "", onMessage);
@@ -34355,7 +34347,7 @@ uniform ${i3} ${o3} u_${a3};
34355
34347
  subscribeTrajectory(mode, onMessage, onError = () => {
34356
34348
  }, quiet = false) {
34357
34349
  this.unsubscribeTrajectory(onMessage);
34358
- this.subscribe(`trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes, this.tenant)}`, onMessage, onError, quiet);
34350
+ this.subscribe(`trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
34359
34351
  }
34360
34352
  unsubscribeTrajectory(onMessage) {
34361
34353
  this.unsubscribe(`trajectory`, "", onMessage);
@@ -34363,15 +34355,13 @@ uniform ${i3} ${o3} u_${a3};
34363
34355
  subscribeDeletedVehicles(mode, onMessage, onError = () => {
34364
34356
  }, quiet = false) {
34365
34357
  this.unsubscribeDeletedVehicles(onMessage);
34366
- this.subscribe(`deleted_vehicles${getRealtimeModeSuffix_default(mode, RealtimeModes, this.tenant)}`, onMessage, onError, quiet);
34358
+ this.subscribe(`deleted_vehicles${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
34367
34359
  }
34368
34360
  unsubscribeDeletedVehicles(onMessage) {
34369
34361
  this.unsubscribe("deleted_vehicles", "", onMessage);
34370
34362
  }
34371
34363
  getFullTrajectory(id, mode, generalizationLevel) {
34372
- const channel = [
34373
- `full_trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`
34374
- ];
34364
+ const channel = [`full_trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`];
34375
34365
  if (id) {
34376
34366
  channel.push(id);
34377
34367
  }
@@ -35737,10 +35727,13 @@ uniform ${i3} ${o3} u_${a3};
35737
35727
 
35738
35728
  // src/common/utils/getMaplibreRender.ts
35739
35729
  function getMaplibreRender(maplibreLayer) {
35740
- const emptyDiv = document.createElement("div");
35730
+ let emptyDiv;
35741
35731
  return (frameState) => {
35742
35732
  const { map, mbMap, olLayer } = maplibreLayer;
35743
35733
  if (!map || !mbMap) {
35734
+ if (!emptyDiv) {
35735
+ emptyDiv = document.createElement("div");
35736
+ }
35744
35737
  return emptyDiv;
35745
35738
  }
35746
35739
  const canvas2 = mbMap.getCanvas();
@@ -35764,10 +35757,13 @@ uniform ${i3} ${o3} u_${a3};
35764
35757
 
35765
35758
  // src/common/utils/getMapboxRender.ts
35766
35759
  function getMapboxRender(mapoxLayer) {
35767
- const emptyDiv = document.createElement("div");
35760
+ let emptyDiv;
35768
35761
  return (frameState) => {
35769
35762
  const { map, mbMap, renderState, olLayer } = mapoxLayer;
35770
35763
  if (!map || !mbMap) {
35764
+ if (!emptyDiv) {
35765
+ emptyDiv = document.createElement("div");
35766
+ }
35771
35767
  return emptyDiv;
35772
35768
  }
35773
35769
  let changed = false;
@@ -49116,8 +49112,9 @@ uniform ${i3} ${o3} u_${a3};
49116
49112
  }
49117
49113
  if (filterFunc) {
49118
49114
  const visibilityValue = visible ? "visible" : "none";
49119
- for (let i = 0; i < style.layers.length; i += 1) {
49120
- const styleLayer = style.layers[i];
49115
+ const layers = style.layers || [];
49116
+ for (let i = 0; i < layers.length; i += 1) {
49117
+ const styleLayer = layers[i];
49121
49118
  if (filterFunc(styleLayer)) {
49122
49119
  if (mbMap.getLayer(styleLayer.id)) {
49123
49120
  mbMap.setLayoutProperty(styleLayer.id, "visibility", visibilityValue);
@@ -49142,14 +49139,11 @@ uniform ${i3} ${o3} u_${a3};
49142
49139
  hitTolerance: 10,
49143
49140
  ...options
49144
49141
  });
49145
- this.minZoomInterpolation = 8;
49146
49142
  this.debug = options.debug || false;
49147
49143
  this.mode = options.mode || RealtimeModes.TOPOGRAPHIC;
49148
49144
  this.api = options.api || new RealtimeAPI_default(options);
49149
49145
  this.tenant = options.tenant || "";
49150
- if (!Number.isNaN(options.minZoomInterpolation)) {
49151
- this.minZoomInterpolation = options.minZoomInterpolation || 0;
49152
- }
49146
+ this.minZoomInterpolation = options.minZoomInterpolation || 8;
49153
49147
  this.format = new GeoJSON_default();
49154
49148
  const allMots = [
49155
49149
  "tram",
@@ -49235,6 +49229,7 @@ uniform ${i3} ${o3} u_${a3};
49235
49229
  canvas: canvas2,
49236
49230
  styleOptions
49237
49231
  } = options;
49232
+ let currCanvas = canvas2;
49238
49233
  let currSpeed = speed || 1;
49239
49234
  let currTime = time || new Date();
49240
49235
  let currStyle = style || realtimeDefaultStyle_default;
@@ -49242,7 +49237,15 @@ uniform ${i3} ${o3} u_${a3};
49242
49237
  Object.defineProperties(this, {
49243
49238
  isTrackerLayer: { value: true },
49244
49239
  canvas: {
49245
- value: canvas2 || document.createElement("canvas")
49240
+ get: () => {
49241
+ if (!currCanvas) {
49242
+ currCanvas = document.createElement("canvas");
49243
+ }
49244
+ return currCanvas;
49245
+ },
49246
+ set: (cnvas) => {
49247
+ currCanvas = cnvas;
49248
+ }
49246
49249
  },
49247
49250
  style: {
49248
49251
  get: () => currStyle,
@@ -49336,6 +49339,7 @@ uniform ${i3} ${o3} u_${a3};
49336
49339
  }
49337
49340
  start() {
49338
49341
  this.stop();
49342
+ this.purgeOutOfDateTrajectories();
49339
49343
  this.renderTrajectories();
49340
49344
  this.startUpdateTime();
49341
49345
  this.api.open();
@@ -49501,6 +49505,17 @@ uniform ${i3} ${o3} u_${a3};
49501
49505
  return response;
49502
49506
  });
49503
49507
  }
49508
+ purgeOutOfDateTrajectories() {
49509
+ Object.entries(this.trajectories || {}).forEach(([key, trajectory]) => {
49510
+ const timeIntervals = trajectory?.properties?.time_intervals;
49511
+ if (this.time && timeIntervals.length) {
49512
+ const lastTimeInterval = timeIntervals[timeIntervals.length - 1][0];
49513
+ if (lastTimeInterval < this.time) {
49514
+ this.trackerLayer.removeTrajectory(key);
49515
+ }
49516
+ }
49517
+ });
49518
+ }
49504
49519
  purgeTrajectory(trajectory, extent, zoom) {
49505
49520
  const { type, bounds } = trajectory.properties;
49506
49521
  if (!intersects(extent, bounds) || this.mots && !this.mots.includes(type) || type !== "rail" && zoom < 9) {
@@ -49539,6 +49554,7 @@ uniform ${i3} ${o3} u_${a3};
49539
49554
  }
49540
49555
  if (document.hidden) {
49541
49556
  this.stop();
49557
+ this.trajectories = {};
49542
49558
  } else {
49543
49559
  this.start();
49544
49560
  }