mobility-toolbox-js 2.0.0-beta.53 → 2.0.0-beta.55
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/api/RealtimeAPI.d.ts +71 -81
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +98 -265
- package/common/api/WebSocketAPI.d.ts +13 -15
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +11 -8
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -1
- package/common/mixins/RealtimeLayerMixin.js +36 -7
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/index.d.ts +3 -0
- package/common/utils/index.js +3 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/mapbox/layers/RealtimeLayer.d.ts +7 -5
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mbt.js +203 -246
- package/mbt.js.map +3 -3
- package/mbt.min.js +11 -11
- package/mbt.min.js.map +3 -3
- package/ol/layers/RealtimeLayer.d.ts +9 -6
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +3 -3
- package/package.json +1 -1
- package/types/common.d.ts +1 -1
- package/types/realtime.d.ts +0 -2
- package/common/utils/cleanStopTime.d.ts +0 -8
- package/common/utils/cleanStopTime.d.ts.map +0 -1
- package/common/utils/cleanStopTime.js +0 -25
package/mbt.js
CHANGED
|
@@ -33294,6 +33294,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33294
33294
|
VectorLayer: () => VectorLayer_default2,
|
|
33295
33295
|
WMSLayer: () => WMSLayer_default,
|
|
33296
33296
|
createRealtimeFilters: () => createRealtimeFilters_default,
|
|
33297
|
+
debounceDeparturesMessages: () => debounceDeparturesMessages_default,
|
|
33298
|
+
debounceWebsocketMessages: () => debounceWebsocketMessages_default,
|
|
33297
33299
|
fullTrajectoryDelayStyle: () => fullTrajectoryDelayStyle_default,
|
|
33298
33300
|
fullTrajectoryStyle: () => fullTrajectoryStyle_default,
|
|
33299
33301
|
getCircleCanvas: () => getCircleCanvas,
|
|
@@ -33315,6 +33317,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
33315
33317
|
realtimeSimpleStyle: () => realtimeSimpleStyle_default,
|
|
33316
33318
|
removeDuplicate: () => removeDuplicate_default,
|
|
33317
33319
|
renderTrajectories: () => renderTrajectories_default,
|
|
33320
|
+
sortAndFilterDepartures: () => sortAndFilterDepartures_default,
|
|
33318
33321
|
sortByDelay: () => sortByDelay_default
|
|
33319
33322
|
});
|
|
33320
33323
|
|
|
@@ -34136,55 +34139,33 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34136
34139
|
};
|
|
34137
34140
|
var WebSocketAPI_default = WebSocketAPI;
|
|
34138
34141
|
|
|
34139
|
-
// src/common/utils/
|
|
34140
|
-
var
|
|
34141
|
-
|
|
34142
|
-
|
|
34143
|
-
|
|
34144
|
-
|
|
34145
|
-
}
|
|
34146
|
-
if (
|
|
34147
|
-
|
|
34148
|
-
|
|
34149
|
-
|
|
34150
|
-
|
|
34142
|
+
// src/common/utils/debounceWebsocketMessages.ts
|
|
34143
|
+
var debounceWebsocketMessages = (onUpdate, getObjectId, timeout = 100) => {
|
|
34144
|
+
const updateTimeout = {};
|
|
34145
|
+
const objectsById = {};
|
|
34146
|
+
const objects = [];
|
|
34147
|
+
return (data) => {
|
|
34148
|
+
const { source, content } = data;
|
|
34149
|
+
if (updateTimeout[source]) {
|
|
34150
|
+
window.clearTimeout(updateTimeout[source]);
|
|
34151
|
+
}
|
|
34152
|
+
if (getObjectId) {
|
|
34153
|
+
objectsById[getObjectId(content)] = content;
|
|
34154
|
+
} else {
|
|
34155
|
+
objects.push(content);
|
|
34151
34156
|
}
|
|
34152
|
-
|
|
34153
|
-
|
|
34157
|
+
updateTimeout[source] = window.setTimeout(() => {
|
|
34158
|
+
const objectToReturn = getObjectId ? Object.values(objectsById) : objects;
|
|
34159
|
+
onUpdate(objectToReturn);
|
|
34160
|
+
}, timeout);
|
|
34161
|
+
};
|
|
34154
34162
|
};
|
|
34155
|
-
var
|
|
34163
|
+
var debounceWebsocketMessages_default = debounceWebsocketMessages;
|
|
34156
34164
|
|
|
34157
34165
|
// src/common/utils/getRealtimeModeSuffix.ts
|
|
34158
34166
|
var getModeSuffix = (mode, modes) => mode === modes.SCHEMATIC ? "_schematic" : "";
|
|
34159
34167
|
var getRealtimeModeSuffix_default = getModeSuffix;
|
|
34160
34168
|
|
|
34161
|
-
// src/common/utils/compareDepartures.ts
|
|
34162
|
-
var compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
34163
|
-
const topStates = ["HIDDEN", "LEAVING", "BOARDING"];
|
|
34164
|
-
const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
|
|
34165
|
-
const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
|
|
34166
|
-
if (aTop || bTop) {
|
|
34167
|
-
if (aTop !== bTop) {
|
|
34168
|
-
return aTop ? -1 : 1;
|
|
34169
|
-
}
|
|
34170
|
-
if (a.state !== b.state) {
|
|
34171
|
-
return topStates.indexOf(a.state) - topStates.indexOf(b.state);
|
|
34172
|
-
}
|
|
34173
|
-
}
|
|
34174
|
-
let aDuration = null;
|
|
34175
|
-
let bDuration = null;
|
|
34176
|
-
const now = Date.now();
|
|
34177
|
-
if (sortByMinArrivalTime) {
|
|
34178
|
-
aDuration = new Date(a.min_arrival_time || a.time).getTime() - now;
|
|
34179
|
-
bDuration = new Date(b.min_arrival_time || b.time).getTime() - now;
|
|
34180
|
-
} else {
|
|
34181
|
-
aDuration = new Date(a.time).getTime() - now;
|
|
34182
|
-
bDuration = new Date(b.time).getTime() - now;
|
|
34183
|
-
}
|
|
34184
|
-
return aDuration - bDuration;
|
|
34185
|
-
};
|
|
34186
|
-
var compareDepartures_default = compareDepartures;
|
|
34187
|
-
|
|
34188
34169
|
// src/api/RealtimeAPI.ts
|
|
34189
34170
|
var RealtimeModes = {
|
|
34190
34171
|
RAW: "raw",
|
|
@@ -34194,10 +34175,6 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34194
34175
|
var RealtimeAPI = class {
|
|
34195
34176
|
constructor(options = {}) {
|
|
34196
34177
|
this.defineProperties(options);
|
|
34197
|
-
this.subscribedStationUic = void 0;
|
|
34198
|
-
this.departureUpdateTimeout = void 0;
|
|
34199
|
-
this.maxDepartureAge = 30;
|
|
34200
|
-
this.extraGeoms = {};
|
|
34201
34178
|
this.prefix = options.prefix || "";
|
|
34202
34179
|
this.onOpen = this.onOpen.bind(this);
|
|
34203
34180
|
}
|
|
@@ -34309,92 +34286,32 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34309
34286
|
this.reconnectTimeout = window.setTimeout(() => this.open(), this.reconnectTimeoutMs);
|
|
34310
34287
|
}
|
|
34311
34288
|
}
|
|
34312
|
-
subscribe(channel, onSuccess, onError
|
|
34289
|
+
subscribe(channel, onSuccess, onError = () => {
|
|
34290
|
+
}, quiet = false) {
|
|
34313
34291
|
if (!channel || !onSuccess) {
|
|
34314
34292
|
return;
|
|
34315
34293
|
}
|
|
34316
34294
|
this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
|
|
34317
34295
|
}
|
|
34318
|
-
unsubscribe(channel, suffix = "",
|
|
34319
|
-
|
|
34320
|
-
|
|
34321
|
-
|
|
34322
|
-
|
|
34323
|
-
const departures = Object.keys(depObject).map((k) => depObject[k]);
|
|
34324
|
-
departures.sort((a, b) => compareDepartures_default(a, b, sortByMinArrivalTime));
|
|
34325
|
-
const futureDate = new Date();
|
|
34326
|
-
futureDate.setMinutes(futureDate.getMinutes() + this.maxDepartureAge);
|
|
34327
|
-
const future = futureDate.getTime();
|
|
34328
|
-
const pastDate = new Date();
|
|
34329
|
-
pastDate.setMinutes(pastDate.getMinutes() - this.maxDepartureAge);
|
|
34330
|
-
const past = pastDate.getTime();
|
|
34331
|
-
const departureArray = [];
|
|
34332
|
-
const platformsBoarding = [];
|
|
34333
|
-
let previousDeparture = null;
|
|
34334
|
-
for (let i = departures.length - 1; i >= 0; i -= 1) {
|
|
34335
|
-
const departure = {
|
|
34336
|
-
...departures[i]
|
|
34337
|
-
};
|
|
34338
|
-
const time = new Date(departure.time).getTime();
|
|
34339
|
-
if (time > past && time < future) {
|
|
34340
|
-
if (departure.state === "BOARDING") {
|
|
34341
|
-
if (platformsBoarding.indexOf(departure.platform) === -1) {
|
|
34342
|
-
platformsBoarding.push(departure.platform);
|
|
34343
|
-
} else {
|
|
34344
|
-
departure.state = "HIDDEN";
|
|
34345
|
-
}
|
|
34346
|
-
}
|
|
34347
|
-
if (previousDeparture && departure.to[0] === previousDeparture.to[0] && Math.abs(time - previousDeparture.time) < 1e3 && departure.line.name === previousDeparture.line.name) {
|
|
34348
|
-
departure.state = "HIDDEN";
|
|
34349
|
-
}
|
|
34350
|
-
if (/(STOP_CANCELLED|JOURNEY_CANCELLED)/.test(departure.state)) {
|
|
34351
|
-
departure.cancelled = true;
|
|
34352
|
-
}
|
|
34353
|
-
previousDeparture = departure;
|
|
34354
|
-
previousDeparture.time = time;
|
|
34355
|
-
departureArray.unshift(departure);
|
|
34356
|
-
}
|
|
34357
|
-
}
|
|
34358
|
-
return departureArray;
|
|
34296
|
+
unsubscribe(channel, suffix = "", onMessage) {
|
|
34297
|
+
const suffixSchenatic = getRealtimeModeSuffix_default(RealtimeModes.SCHEMATIC, RealtimeModes);
|
|
34298
|
+
const suffixTopographic = getRealtimeModeSuffix_default(RealtimeModes.TOPOGRAPHIC, RealtimeModes);
|
|
34299
|
+
this.wsApi.unsubscribe(`${channel}${suffixSchenatic}${suffix || ""}`, onMessage);
|
|
34300
|
+
this.wsApi.unsubscribe(`${channel}${suffixTopographic}${suffix || ""}`, onMessage);
|
|
34359
34301
|
}
|
|
34360
|
-
subscribeDepartures(stationId,
|
|
34361
|
-
|
|
34362
|
-
this.
|
|
34363
|
-
this.subscribedStationUic = stationId;
|
|
34364
|
-
const channel = stationId ? `timetable_${stationId}` : null;
|
|
34365
|
-
const departureObject = {};
|
|
34366
|
-
if (!channel) {
|
|
34367
|
-
return;
|
|
34368
|
-
}
|
|
34369
|
-
const onSuccess = (data) => {
|
|
34370
|
-
if (data.source === channel) {
|
|
34371
|
-
const content = data.content || {};
|
|
34372
|
-
const tDiff = new Date(content.timestamp).getTime() - Date.now();
|
|
34373
|
-
departureObject[content.call_id] = { ...content, timediff: tDiff };
|
|
34374
|
-
window.clearTimeout(this.departureUpdateTimeout);
|
|
34375
|
-
this.departureUpdateTimeout = window.setTimeout(() => {
|
|
34376
|
-
const departures = this.filterDepartures(departureObject, sortByMinArrivalTime || false);
|
|
34377
|
-
onMessage(departures);
|
|
34378
|
-
}, 100);
|
|
34379
|
-
}
|
|
34380
|
-
};
|
|
34381
|
-
this.subscribe(channel, onSuccess, () => {
|
|
34382
|
-
onMessage([]);
|
|
34383
|
-
});
|
|
34302
|
+
subscribeDepartures(stationId, onMessage, onError = () => {
|
|
34303
|
+
}, quiet = false) {
|
|
34304
|
+
this.subscribe(`timetable_${stationId}`, onMessage, onError, quiet);
|
|
34384
34305
|
}
|
|
34385
|
-
unsubscribeDepartures(
|
|
34386
|
-
|
|
34387
|
-
this.unsubscribe(`timetable_${this.subscribedStationUic}`, "", cb);
|
|
34388
|
-
this.subscribedStationUic = void 0;
|
|
34389
|
-
}
|
|
34306
|
+
unsubscribeDepartures(id, onMessage) {
|
|
34307
|
+
this.unsubscribe(`timetable_${id}`, "", onMessage);
|
|
34390
34308
|
}
|
|
34391
|
-
subscribeDisruptions(onMessage) {
|
|
34392
|
-
|
|
34393
|
-
|
|
34394
|
-
});
|
|
34309
|
+
subscribeDisruptions(onMessage, onError = () => {
|
|
34310
|
+
}, quiet = false) {
|
|
34311
|
+
this.subscribe(`${this.prefix}newsticker`, onMessage, onError, quiet);
|
|
34395
34312
|
}
|
|
34396
|
-
unsubscribeDisruptions(
|
|
34397
|
-
this.unsubscribe(`${this.prefix}newsticker`, "",
|
|
34313
|
+
unsubscribeDisruptions(onMessage) {
|
|
34314
|
+
this.unsubscribe(`${this.prefix}newsticker`, "", onMessage);
|
|
34398
34315
|
}
|
|
34399
34316
|
getStation(uic, mode) {
|
|
34400
34317
|
const params = {
|
|
@@ -34402,77 +34319,45 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34402
34319
|
args: uic
|
|
34403
34320
|
};
|
|
34404
34321
|
return new Promise((resolve, reject) => {
|
|
34405
|
-
this.wsApi.get(params,
|
|
34406
|
-
if (data.content) {
|
|
34407
|
-
resolve(data.content);
|
|
34408
|
-
} else {
|
|
34409
|
-
reject();
|
|
34410
|
-
}
|
|
34411
|
-
});
|
|
34322
|
+
this.wsApi.get(params, resolve, reject);
|
|
34412
34323
|
});
|
|
34413
34324
|
}
|
|
34414
|
-
getStations(mode) {
|
|
34415
|
-
|
|
34416
|
-
|
|
34417
|
-
|
|
34418
|
-
|
|
34419
|
-
window.clearTimeout(this.stationUpdateTimeout);
|
|
34420
|
-
return new Promise((resolve, reject) => {
|
|
34421
|
-
this.wsApi.get(params, (data) => {
|
|
34422
|
-
if (data.content) {
|
|
34423
|
-
stations.push(data.content);
|
|
34424
|
-
window.clearTimeout(this.stationUpdateTimeout);
|
|
34425
|
-
this.stationUpdateTimeout = window.setTimeout(() => {
|
|
34426
|
-
resolve(stations);
|
|
34427
|
-
}, 50);
|
|
34428
|
-
} else {
|
|
34429
|
-
reject(data.content);
|
|
34430
|
-
}
|
|
34431
|
-
});
|
|
34325
|
+
getStations(mode, timeout = 100) {
|
|
34326
|
+
return new Promise((resolve) => {
|
|
34327
|
+
this.wsApi.get({
|
|
34328
|
+
channel: `station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`
|
|
34329
|
+
}, debounceWebsocketMessages_default(resolve, void 0, timeout));
|
|
34432
34330
|
});
|
|
34433
34331
|
}
|
|
34434
|
-
subscribeStations(mode, onMessage) {
|
|
34435
|
-
|
|
34436
|
-
this.subscribe(`station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`,
|
|
34437
|
-
if (data.content) {
|
|
34438
|
-
onMessage(data.content);
|
|
34439
|
-
}
|
|
34440
|
-
});
|
|
34332
|
+
subscribeStations(mode, onMessage, onError = () => {
|
|
34333
|
+
}, quiet = false) {
|
|
34334
|
+
this.subscribe(`station${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
|
|
34441
34335
|
}
|
|
34442
|
-
unsubscribeStations(
|
|
34443
|
-
|
|
34444
|
-
this.unsubscribe("station", "", cb);
|
|
34445
|
-
}
|
|
34446
|
-
subscribeExtraGeoms(onMessage) {
|
|
34447
|
-
this.subscribe("extra_geoms", (data) => {
|
|
34448
|
-
const extraGeom = data.content;
|
|
34449
|
-
if (extraGeom) {
|
|
34450
|
-
const { ref } = extraGeom.properties;
|
|
34451
|
-
if (extraGeom.type === "Feature") {
|
|
34452
|
-
this.extraGeoms[ref] = extraGeom;
|
|
34453
|
-
} else {
|
|
34454
|
-
delete this.extraGeoms[ref];
|
|
34455
|
-
}
|
|
34456
|
-
onMessage(Object.keys(this.extraGeoms).map((key) => this.extraGeoms[key]));
|
|
34457
|
-
}
|
|
34458
|
-
});
|
|
34336
|
+
unsubscribeStations(onMessage) {
|
|
34337
|
+
this.unsubscribe("station", "", onMessage);
|
|
34459
34338
|
}
|
|
34460
|
-
|
|
34461
|
-
|
|
34339
|
+
subscribeExtraGeoms(onMessage, onError = () => {
|
|
34340
|
+
}, quiet = false) {
|
|
34341
|
+
this.subscribe("extra_geoms", onMessage, onError, quiet);
|
|
34462
34342
|
}
|
|
34463
|
-
|
|
34343
|
+
unsubscribeExtraGeoms(onMessage) {
|
|
34344
|
+
this.unsubscribe("extra_geoms", "", onMessage);
|
|
34345
|
+
}
|
|
34346
|
+
subscribeTrajectory(mode, onMessage, onError = () => {
|
|
34347
|
+
}, quiet = false) {
|
|
34464
34348
|
this.unsubscribeTrajectory(onMessage);
|
|
34465
|
-
this.subscribe(`trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage,
|
|
34349
|
+
this.subscribe(`trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
|
|
34466
34350
|
}
|
|
34467
|
-
unsubscribeTrajectory(
|
|
34468
|
-
this.unsubscribe(`trajectory`, "",
|
|
34351
|
+
unsubscribeTrajectory(onMessage) {
|
|
34352
|
+
this.unsubscribe(`trajectory`, "", onMessage);
|
|
34469
34353
|
}
|
|
34470
|
-
subscribeDeletedVehicles(mode, onMessage,
|
|
34354
|
+
subscribeDeletedVehicles(mode, onMessage, onError = () => {
|
|
34355
|
+
}, quiet = false) {
|
|
34471
34356
|
this.unsubscribeDeletedVehicles(onMessage);
|
|
34472
|
-
this.subscribe(`deleted_vehicles${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage,
|
|
34357
|
+
this.subscribe(`deleted_vehicles${getRealtimeModeSuffix_default(mode, RealtimeModes)}`, onMessage, onError, quiet);
|
|
34473
34358
|
}
|
|
34474
|
-
unsubscribeDeletedVehicles(
|
|
34475
|
-
this.unsubscribe("deleted_vehicles", "",
|
|
34359
|
+
unsubscribeDeletedVehicles(onMessage) {
|
|
34360
|
+
this.unsubscribe("deleted_vehicles", "", onMessage);
|
|
34476
34361
|
}
|
|
34477
34362
|
getFullTrajectory(id, mode, generalizationLevel) {
|
|
34478
34363
|
const channel = [`full_trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}`];
|
|
@@ -34485,72 +34370,37 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
34485
34370
|
const params = {
|
|
34486
34371
|
channel: channel.join("_")
|
|
34487
34372
|
};
|
|
34488
|
-
return new Promise((resolve) => {
|
|
34489
|
-
this.wsApi.get(params,
|
|
34490
|
-
if (data.content) {
|
|
34491
|
-
resolve(data.content);
|
|
34492
|
-
}
|
|
34493
|
-
});
|
|
34373
|
+
return new Promise((resolve, reject) => {
|
|
34374
|
+
this.wsApi.get(params, resolve, reject);
|
|
34494
34375
|
});
|
|
34495
34376
|
}
|
|
34496
|
-
|
|
34497
|
-
|
|
34498
|
-
|
|
34499
|
-
}
|
|
34500
|
-
subscribeFullTrajectory(id, mode) {
|
|
34501
|
-
this.unsubscribeFullTrajectory(id);
|
|
34502
|
-
this.subscribe(`full_trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}_${id}`, (data) => {
|
|
34503
|
-
console.log("subscribe full_trajectory", data);
|
|
34504
|
-
}, (err) => {
|
|
34505
|
-
console.log("subscribe full_trajectory error", err);
|
|
34506
|
-
});
|
|
34377
|
+
subscribeFullTrajectory(id, mode, onMessage, onError = () => {
|
|
34378
|
+
}, quiet = false) {
|
|
34379
|
+
this.subscribe(`full_trajectory${getRealtimeModeSuffix_default(mode, RealtimeModes)}_${id}`, onMessage, onError, quiet);
|
|
34507
34380
|
}
|
|
34508
|
-
unsubscribeFullTrajectory(id,
|
|
34509
|
-
this.unsubscribe("full_trajectory", `_${id}`,
|
|
34381
|
+
unsubscribeFullTrajectory(id, onMessage) {
|
|
34382
|
+
this.unsubscribe("full_trajectory", `_${id}`, onMessage);
|
|
34510
34383
|
}
|
|
34511
34384
|
getStopSequence(id) {
|
|
34512
|
-
const params = {
|
|
34513
|
-
channel: `stopsequence_${id}`
|
|
34514
|
-
};
|
|
34515
34385
|
return new Promise((resolve, reject) => {
|
|
34516
|
-
this.wsApi.get(
|
|
34517
|
-
|
|
34518
|
-
|
|
34519
|
-
const stopSequences = content.map((stopSequence) => cleanStopTime_default(stopSequence));
|
|
34520
|
-
resolve(stopSequences);
|
|
34521
|
-
}
|
|
34522
|
-
resolve([]);
|
|
34523
|
-
}, (err) => {
|
|
34524
|
-
reject(err);
|
|
34525
|
-
});
|
|
34386
|
+
this.wsApi.get({
|
|
34387
|
+
channel: `stopsequence_${id}`
|
|
34388
|
+
}, resolve, reject);
|
|
34526
34389
|
});
|
|
34527
34390
|
}
|
|
34528
|
-
|
|
34529
|
-
|
|
34530
|
-
|
|
34531
|
-
}
|
|
34532
|
-
subscribeStopSequence(id, onMessage) {
|
|
34533
|
-
window.clearTimeout(this.fullTrajectoryUpdateTimeout);
|
|
34534
|
-
this.unsubscribeStopSequence(id);
|
|
34535
|
-
this.subscribe(`stopsequence_${id}`, (data) => {
|
|
34536
|
-
const content = data.content;
|
|
34537
|
-
if (content && content.length) {
|
|
34538
|
-
const stopSequences = content.map((stopSequence) => cleanStopTime_default(stopSequence));
|
|
34539
|
-
onMessage(stopSequences);
|
|
34540
|
-
}
|
|
34541
|
-
}, (err) => {
|
|
34542
|
-
console.log("subscribe stopsequence error", err);
|
|
34543
|
-
});
|
|
34391
|
+
subscribeStopSequence(id, onMessage, onError = () => {
|
|
34392
|
+
}, quiet = false) {
|
|
34393
|
+
this.subscribe(`stopsequence_${id}`, onMessage, onError, quiet);
|
|
34544
34394
|
}
|
|
34545
|
-
unsubscribeStopSequence(id,
|
|
34546
|
-
this.unsubscribe(`stopsequence`, `_${id}`,
|
|
34395
|
+
unsubscribeStopSequence(id, onMessage) {
|
|
34396
|
+
this.unsubscribe(`stopsequence`, `_${id}`, onMessage);
|
|
34547
34397
|
}
|
|
34548
|
-
subscribeHealthCheck(onMessage) {
|
|
34549
|
-
|
|
34550
|
-
this.subscribe("healthcheck", onMessage);
|
|
34398
|
+
subscribeHealthCheck(onMessage, onError = () => {
|
|
34399
|
+
}, quiet = false) {
|
|
34400
|
+
this.subscribe("healthcheck", onMessage, onError, quiet);
|
|
34551
34401
|
}
|
|
34552
|
-
unsubscribeHealthCheck() {
|
|
34553
|
-
this.unsubscribe("healthcheck");
|
|
34402
|
+
unsubscribeHealthCheck(onMessage) {
|
|
34403
|
+
this.unsubscribe("healthcheck", "", onMessage);
|
|
34554
34404
|
}
|
|
34555
34405
|
};
|
|
34556
34406
|
var RealtimeAPI_default = RealtimeAPI;
|
|
@@ -35960,6 +35810,92 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
35960
35810
|
};
|
|
35961
35811
|
}
|
|
35962
35812
|
|
|
35813
|
+
// src/common/utils/compareDepartures.ts
|
|
35814
|
+
var compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
35815
|
+
const topStates = ["HIDDEN", "LEAVING", "BOARDING"];
|
|
35816
|
+
const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
|
|
35817
|
+
const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
|
|
35818
|
+
if (aTop || bTop) {
|
|
35819
|
+
if (aTop !== bTop) {
|
|
35820
|
+
return aTop ? -1 : 1;
|
|
35821
|
+
}
|
|
35822
|
+
if (a.state !== b.state) {
|
|
35823
|
+
return topStates.indexOf(a.state) - topStates.indexOf(b.state);
|
|
35824
|
+
}
|
|
35825
|
+
}
|
|
35826
|
+
let aDuration = null;
|
|
35827
|
+
let bDuration = null;
|
|
35828
|
+
const now = Date.now();
|
|
35829
|
+
if (sortByMinArrivalTime) {
|
|
35830
|
+
aDuration = new Date(a.min_arrival_time || a.time).getTime() - now;
|
|
35831
|
+
bDuration = new Date(b.min_arrival_time || b.time).getTime() - now;
|
|
35832
|
+
} else {
|
|
35833
|
+
aDuration = new Date(a.time).getTime() - now;
|
|
35834
|
+
bDuration = new Date(b.time).getTime() - now;
|
|
35835
|
+
}
|
|
35836
|
+
return aDuration - bDuration;
|
|
35837
|
+
};
|
|
35838
|
+
var compareDepartures_default = compareDepartures;
|
|
35839
|
+
|
|
35840
|
+
// src/common/utils/sortAndFilterDepartures.ts
|
|
35841
|
+
var sortAndfilterDepartures = (depObject, sortByMinArrivalTime = false, maxDepartureAge = 30) => {
|
|
35842
|
+
const departures = Object.keys(depObject).map((k) => depObject[k]);
|
|
35843
|
+
departures.sort((a, b) => compareDepartures_default(a, b, sortByMinArrivalTime));
|
|
35844
|
+
const futureDate = new Date();
|
|
35845
|
+
futureDate.setMinutes(futureDate.getMinutes() + maxDepartureAge);
|
|
35846
|
+
const future = futureDate.getTime();
|
|
35847
|
+
const pastDate = new Date();
|
|
35848
|
+
pastDate.setMinutes(pastDate.getMinutes() - maxDepartureAge);
|
|
35849
|
+
const past = pastDate.getTime();
|
|
35850
|
+
const departureArray = [];
|
|
35851
|
+
const platformsBoarding = [];
|
|
35852
|
+
let previousDeparture = null;
|
|
35853
|
+
for (let i = departures.length - 1; i >= 0; i -= 1) {
|
|
35854
|
+
const departure = {
|
|
35855
|
+
...departures[i]
|
|
35856
|
+
};
|
|
35857
|
+
const time = new Date(departure.time).getTime();
|
|
35858
|
+
if (time > past && time < future) {
|
|
35859
|
+
if (departure.state === "BOARDING") {
|
|
35860
|
+
if (!platformsBoarding.includes(departure.platform)) {
|
|
35861
|
+
platformsBoarding.push(departure.platform);
|
|
35862
|
+
} else {
|
|
35863
|
+
departure.state = "HIDDEN";
|
|
35864
|
+
}
|
|
35865
|
+
}
|
|
35866
|
+
if (previousDeparture && departure.to[0] === previousDeparture.to[0] && Math.abs(time - previousDeparture.time) < 1e3 && departure.line.name === previousDeparture.line.name) {
|
|
35867
|
+
departure.state = "HIDDEN";
|
|
35868
|
+
}
|
|
35869
|
+
if (/(STOP_CANCELLED|JOURNEY_CANCELLED)/.test(departure.state)) {
|
|
35870
|
+
departure.cancelled = true;
|
|
35871
|
+
}
|
|
35872
|
+
previousDeparture = departure;
|
|
35873
|
+
previousDeparture.time = time;
|
|
35874
|
+
departureArray.unshift(departure);
|
|
35875
|
+
}
|
|
35876
|
+
}
|
|
35877
|
+
return departureArray;
|
|
35878
|
+
};
|
|
35879
|
+
var sortAndFilterDepartures_default = sortAndfilterDepartures;
|
|
35880
|
+
|
|
35881
|
+
// src/common/utils/debounceDeparturesMessages.ts
|
|
35882
|
+
var debounceDeparturesMessages = (onDeparturesUpdate, sortByMinArrivalTime = true, maxDepartureAge = 30, timeout = 100) => {
|
|
35883
|
+
const departureUpdateTimeout = {};
|
|
35884
|
+
const departureObject = {};
|
|
35885
|
+
return (data) => {
|
|
35886
|
+
const { source, content: departure } = data;
|
|
35887
|
+
if (departureUpdateTimeout[source]) {
|
|
35888
|
+
window.clearTimeout(departureUpdateTimeout[source]);
|
|
35889
|
+
}
|
|
35890
|
+
departureObject[departure.call_id] = departure;
|
|
35891
|
+
departureUpdateTimeout[source] = window.setTimeout(() => {
|
|
35892
|
+
const departures = sortAndFilterDepartures_default(departureObject, sortByMinArrivalTime || false, maxDepartureAge);
|
|
35893
|
+
onDeparturesUpdate(departures);
|
|
35894
|
+
}, timeout);
|
|
35895
|
+
};
|
|
35896
|
+
};
|
|
35897
|
+
var debounceDeparturesMessages_default = debounceDeparturesMessages;
|
|
35898
|
+
|
|
35963
35899
|
// src/common/utils/realtimeConfig.ts
|
|
35964
35900
|
var realtimeConfig_exports = {};
|
|
35965
35901
|
__export(realtimeConfig_exports, {
|
|
@@ -49199,9 +49135,23 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49199
49135
|
this.mode = options.mode || RealtimeModes.TOPOGRAPHIC;
|
|
49200
49136
|
this.api = options.api || new RealtimeAPI_default(options);
|
|
49201
49137
|
this.tenant = options.tenant || "";
|
|
49202
|
-
this.minZoomNonTrain = options.minZoomNonTrain || 9;
|
|
49203
49138
|
this.minZoomInterpolation = options.minZoomInterpolation || 8;
|
|
49204
49139
|
this.format = new GeoJSON_default();
|
|
49140
|
+
const allMots = [
|
|
49141
|
+
"tram",
|
|
49142
|
+
"subway",
|
|
49143
|
+
"rail",
|
|
49144
|
+
"bus",
|
|
49145
|
+
"ferry",
|
|
49146
|
+
"cablecar",
|
|
49147
|
+
"gondola",
|
|
49148
|
+
"funicular",
|
|
49149
|
+
"coach"
|
|
49150
|
+
];
|
|
49151
|
+
this.motsByZoom = options.motsByZoom || [allMots];
|
|
49152
|
+
this.getMotsByZoom = (zoom) => {
|
|
49153
|
+
return options.getMotsByZoom && options.getMotsByZoom(zoom, this.motsByZoom) || this.motsByZoom[zoom] || this.motsByZoom[this.motsByZoom.length - 1];
|
|
49154
|
+
};
|
|
49205
49155
|
this.generalizationLevelByZoom = options.generalizationLevelByZoom || [
|
|
49206
49156
|
5,
|
|
49207
49157
|
5,
|
|
@@ -49370,8 +49320,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49370
49320
|
this.renderTrajectories();
|
|
49371
49321
|
this.startUpdateTime();
|
|
49372
49322
|
this.api.open();
|
|
49373
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
49374
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
49323
|
+
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, void 0, this.isUpdateBboxOnMoveEnd);
|
|
49324
|
+
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, void 0, this.isUpdateBboxOnMoveEnd);
|
|
49375
49325
|
if (this.isUpdateBboxOnMoveEnd) {
|
|
49376
49326
|
this.setBbox();
|
|
49377
49327
|
}
|
|
@@ -49463,6 +49413,10 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49463
49413
|
if (this.generalizationLevel) {
|
|
49464
49414
|
bbox.push(`gen=${this.generalizationLevel}`);
|
|
49465
49415
|
}
|
|
49416
|
+
this.mots = this.getMotsByZoom(zoom);
|
|
49417
|
+
if (this.mots) {
|
|
49418
|
+
bbox.push(`mots=${this.mots}`);
|
|
49419
|
+
}
|
|
49466
49420
|
}
|
|
49467
49421
|
this.api.bbox = bbox;
|
|
49468
49422
|
}
|
|
@@ -49471,8 +49425,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49471
49425
|
return;
|
|
49472
49426
|
}
|
|
49473
49427
|
this.mode = mode;
|
|
49474
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
49475
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
49428
|
+
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, void 0, this.isUpdateBboxOnMoveEnd);
|
|
49429
|
+
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, void 0, this.isUpdateBboxOnMoveEnd);
|
|
49476
49430
|
}
|
|
49477
49431
|
getRefreshTimeInMs(zoom = 0) {
|
|
49478
49432
|
const roundedZoom = zoom !== void 0 ? Math.round(zoom) : -1;
|
|
@@ -49530,7 +49484,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49530
49484
|
}
|
|
49531
49485
|
purgeTrajectory(trajectory, extent, zoom) {
|
|
49532
49486
|
const { type, bounds } = trajectory.properties;
|
|
49533
|
-
if (!intersects(extent, bounds) || type !== "rail" && zoom <
|
|
49487
|
+
if (!intersects(extent, bounds) || !this.mots?.includes(type) || type !== "rail" && zoom < 9) {
|
|
49534
49488
|
this.removeTrajectory(trajectory);
|
|
49535
49489
|
return true;
|
|
49536
49490
|
}
|
|
@@ -49878,9 +49832,9 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49878
49832
|
super.setBbox(newExtent, newZoom);
|
|
49879
49833
|
}
|
|
49880
49834
|
highlightTrajectory(id) {
|
|
49881
|
-
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel).then((
|
|
49882
|
-
const
|
|
49883
|
-
|
|
49835
|
+
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel).then((data) => {
|
|
49836
|
+
const fullTrajectory = data.content;
|
|
49837
|
+
this.vectorLayer.getSource().clear();
|
|
49884
49838
|
if (!fullTrajectory || !fullTrajectory.features || !fullTrajectory.features.length) {
|
|
49885
49839
|
return;
|
|
49886
49840
|
}
|
|
@@ -49977,6 +49931,8 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49977
49931
|
RoutingAPI: () => RoutingAPI_default,
|
|
49978
49932
|
StopsAPI: () => StopsAPI_default,
|
|
49979
49933
|
createRealtimeFilters: () => createRealtimeFilters_default,
|
|
49934
|
+
debounceDeparturesMessages: () => debounceDeparturesMessages_default,
|
|
49935
|
+
debounceWebsocketMessages: () => debounceWebsocketMessages_default,
|
|
49980
49936
|
getCircleCanvas: () => getCircleCanvas,
|
|
49981
49937
|
getDelayBgCanvas: () => getDelayBgCanvas,
|
|
49982
49938
|
getDelayTextCanvas: () => getDelayTextCanvas,
|
|
@@ -49998,6 +49954,7 @@ uniform ${i3} ${o3} u_${a3};
|
|
|
49998
49954
|
realtimeSimpleStyle: () => realtimeSimpleStyle_default,
|
|
49999
49955
|
removeDuplicate: () => removeDuplicate_default,
|
|
50000
49956
|
renderTrajectories: () => renderTrajectories_default,
|
|
49957
|
+
sortAndFilterDepartures: () => sortAndFilterDepartures_default,
|
|
50001
49958
|
sortByDelay: () => sortByDelay_default
|
|
50002
49959
|
});
|
|
50003
49960
|
|