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', {
|
this.baseMapLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© OpenStreetMap',
|
attribution: '© OpenStreetMap',
|
||||||
maxZoom: 19
|
maxZoom: this.map.options.maxZoom,
|
||||||
|
maxNativeZoom: 19
|
||||||
}).addTo(this.map);
|
}).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', {
|
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({
|
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) {
|
async drawVehicleTrace(vehId) {
|
||||||
this.currentVehicleTrace.clearLayers();
|
this.currentVehicleTrace.clearLayers();
|
||||||
if (vehId === null)
|
if (vehId === null)
|
||||||
@@ -414,6 +426,12 @@ export default class MhdMapClient {
|
|||||||
this.drawVehicleTrace(veh.vehicleNumber);
|
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) {
|
_popupCloseEvent(event) {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ export default class BratislavaOpendata {
|
|||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchOneStop(stationId) {
|
async fetchOneStop(stationStopId) {
|
||||||
return this.request('/stationstop/' + stationId);
|
return this.request('/stationstop/' + stationStopId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchAllStops() {
|
async fetchAllStops() {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export default class MhdMapApp {
|
|||||||
this.stops = null;
|
this.stops = null;
|
||||||
this.oldVehicles = null;
|
this.oldVehicles = null;
|
||||||
this.vehicles = null;
|
this.vehicles = null;
|
||||||
|
this.stopCache = {};
|
||||||
this.lastUpdatedStatic = null;
|
this.lastUpdatedStatic = null;
|
||||||
this.lastUpdatedDynamic = null;
|
this.lastUpdatedDynamic = null;
|
||||||
this.lastDelta = 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) {
|
calculateVehiclesDelta(beforeObj, afterObj) {
|
||||||
let delta = {};
|
let delta = {};
|
||||||
|
|
||||||
@@ -216,6 +233,8 @@ export default class MhdMapApp {
|
|||||||
return await this.recorder.getVehicleTrace(data.vehicle, data.count || 20);
|
return await this.recorder.getVehicleTrace(data.vehicle, data.count || 20);
|
||||||
} else if (action === 'requestLineTrace') {
|
} else if (action === 'requestLineTrace') {
|
||||||
return await this.recorder.getSimpleLineTrace(data.line, data.count || 20);
|
return await this.recorder.getSimpleLineTrace(data.line, data.count || 20);
|
||||||
|
} else if (action === 'requestStopInfo') {
|
||||||
|
return await this.getStopInfo(data.stationStopId);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user