add stops info
This commit is contained in:
@@ -68,11 +68,13 @@ export default class MhdMapClient {
|
||||
|
||||
this.baseMapLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© OpenStreetMap',
|
||||
maxZoom: 19
|
||||
maxZoom: this.map.options.maxZoom,
|
||||
maxNativeZoom: 19
|
||||
}).addTo(this.map);
|
||||
|
||||
this.georefLayer = L.tileLayer('https://maps.georeferencer.com/georeferences/e886f898-04e0-4479-8cd3-bbe4ae7537b3/2022-06-22T09:24:26.012877Z/map/{z}/{x}/{y}.png?key=c0WCCJEkXmpgh7TxHg2U', {
|
||||
maxZoom: 17
|
||||
maxZoom: this.map.options.maxZoom,
|
||||
maxNativeZoom: 17,
|
||||
});
|
||||
|
||||
this.layerControl = L.control.layers({
|
||||
@@ -277,6 +279,16 @@ export default class MhdMapClient {
|
||||
|
||||
}
|
||||
|
||||
async fillStopInfo(stop, event) {
|
||||
let stopData = await this.sendWs('requestStopInfo', {
|
||||
stationStopId: stop.stationStopId,
|
||||
});
|
||||
if (stopData.data.departures.length === 0)
|
||||
return;
|
||||
|
||||
console.log(stopData.data.departures.length);
|
||||
}
|
||||
|
||||
async drawVehicleTrace(vehId) {
|
||||
this.currentVehicleTrace.clearLayers();
|
||||
if (vehId === null)
|
||||
@@ -414,6 +426,12 @@ export default class MhdMapClient {
|
||||
this.drawVehicleTrace(veh.vehicleNumber);
|
||||
}
|
||||
|
||||
let stop = event?.popup?._source?.options?.data?.stop;
|
||||
if (stop) {
|
||||
// the user has clicked a stop marker
|
||||
this.fillStopInfo(stop, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_popupCloseEvent(event) {
|
||||
|
||||
@@ -6,8 +6,8 @@ export default class BratislavaOpendata {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
async fetchOneStop(stationId) {
|
||||
return this.request('/stationstop/' + stationId);
|
||||
async fetchOneStop(stationStopId) {
|
||||
return this.request('/stationstop/' + stationStopId);
|
||||
}
|
||||
|
||||
async fetchAllStops() {
|
||||
|
||||
@@ -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