Added road incidents, just need to update backbone object to deal with them

This commit is contained in:
martin 2018-05-22 16:16:23 +01:00
parent 1be9414e21
commit 32dd4a0b24
2 changed files with 22 additions and 3 deletions

View File

@ -218,6 +218,16 @@ app.get('/incidents', cache('5 minutes'), (req, res) => {
});
app.get('/comb', asyncMiddleware(async (req, res, next) => {
logger.debug(req.query);
let m = await directions.doGetEstDirectionsWithIncidents(req.query.olat, req.query.olon, req.query.dlat, req.query.dlon).then((b) => {
logger.debug('b', b);
});
logger.debug('m', m);
res.send(m);
}));
app.listen(port, (err) => {
if (err)
return logger.error('Server error:', err);

View File

@ -9,7 +9,8 @@ const { reduceEstDirections, reduceIncidents } = require('./reducers/directions'
module.exports = {
'getTraffic': doGetEstDirections,
'getIncidents' : doGetTraffic
'getIncidents' : doGetTraffic,
doGetEstDirectionsWithIncidents
};
const headers = {};
@ -18,7 +19,15 @@ const lastGood = {};
//
// https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&key=AIzaSyBl7O9LHIthCagcqIaDkQ4um_hghYG5reE
function doGetEstDirections(olat, olon, dlat, dlon) {
async function doGetEstDirectionsWithIncidents(olat, olon, dlat, dlon) {
let traff = await doGetEstDirections(olat, olon, dlat, dlon);
let incid = await doGetTraffic();
logger.debug('after...');
return {traff, incid};
}
async function doGetEstDirections(olat, olon, dlat, dlon) {
logger.debug('doGetEstDirections');
const url = `https://sgws2.maps.yahoo.com/Directions?time=now&cache=n&flags=J&olat=${olat}&olon=${olon}&dlat=${dlat}&dlon=${dlon}`;
@ -50,7 +59,7 @@ function doGetEstDirections(olat, olon, dlat, dlon) {
});
}
function doGetTraffic() {
async function doGetTraffic() {
logger.debug('doGetTraffic');
return new Promise((resolve, reject) => {