add stops info
This commit is contained in:
@@ -14,6 +14,7 @@ export default class MhdMapApp {
|
||||
this.stops = null;
|
||||
this.oldVehicles = null;
|
||||
this.vehicles = null;
|
||||
this.stopCache = {};
|
||||
this.lastUpdatedStatic = null;
|
||||
this.lastUpdatedDynamic = null;
|
||||
this.lastDelta = null;
|
||||
@@ -92,6 +93,22 @@ export default class MhdMapApp {
|
||||
}
|
||||
}
|
||||
|
||||
async getStopInfo(stationStopId) {
|
||||
let cached = this.stopCache[stationStopId] || null;
|
||||
if (cached && cached.t.getTime() > (Date.now() - 15 * 1000)) { // cache for 15 seconds
|
||||
return cached;
|
||||
}
|
||||
|
||||
const data = await this.opendata.fetchOneStop(stationStopId);
|
||||
if (!data)
|
||||
return cached; // null or stale
|
||||
|
||||
return (this.stopCache[stationStopId] = {
|
||||
t: new Date(),
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
calculateVehiclesDelta(beforeObj, afterObj) {
|
||||
let delta = {};
|
||||
|
||||
@@ -216,6 +233,8 @@ export default class MhdMapApp {
|
||||
return await this.recorder.getVehicleTrace(data.vehicle, data.count || 20);
|
||||
} else if (action === 'requestLineTrace') {
|
||||
return await this.recorder.getSimpleLineTrace(data.line, data.count || 20);
|
||||
} else if (action === 'requestStopInfo') {
|
||||
return await this.getStopInfo(data.stationStopId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user