Remove valhalla-specific logic - valhalla now knows how to emit OSRM responses.
This commit is contained in:
parent
5d0dcbbc21
commit
171a20d322
@ -31,7 +31,10 @@ module.exports = function () {
|
|||||||
if (type === 'GET') {
|
if (type === 'GET') {
|
||||||
|
|
||||||
var params = this.paramsToString(parameters);
|
var params = this.paramsToString(parameters);
|
||||||
this.query = baseUri + (params.length ? '/' + params : '');
|
console.log(params);
|
||||||
|
this.query = baseUri + (params.length ? ((params[0] != '?') ? '/' : '' + params) : '');
|
||||||
|
|
||||||
|
console.log(this.query);
|
||||||
|
|
||||||
if (logfile && typeof logfile !== 'function') fs.writeFileSync(logfile, `GET ${this.query}`);
|
if (logfile && typeof logfile !== 'function') fs.writeFileSync(logfile, `GET ${this.query}`);
|
||||||
request(this.query, (err, res, body) => {
|
request(this.query, (err, res, body) => {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ module.exports = function () {
|
|||||||
uri = [this.HOST, service, 'v1', this.profile].join('/');
|
uri = [this.HOST, service, 'v1', this.profile].join('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sendRequest(uri, params, this.osrmLoader.method === 'valhalla' ? 'POST' : 'GET', logfile, callback);
|
return this.sendRequest(uri, params, 'GET', logfile, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.requestUrl = (path, callback) => {
|
this.requestUrl = (path, callback) => {
|
||||||
@ -60,6 +60,8 @@ module.exports = function () {
|
|||||||
|
|
||||||
params.coordinates = encodedWaypoints;
|
params.coordinates = encodedWaypoints;
|
||||||
|
|
||||||
|
console.log(params);
|
||||||
|
|
||||||
if (bearings.length) {
|
if (bearings.length) {
|
||||||
params.bearings = bearings.map(b => {
|
params.bearings = bearings.map(b => {
|
||||||
var bs = b.split(',');
|
var bs = b.split(',');
|
||||||
@ -74,11 +76,14 @@ module.exports = function () {
|
|||||||
|
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
if (this.osrmLoader.method === 'valhalla') {
|
||||||
params = {
|
params = {
|
||||||
locations: waypoints.map(w => {return{ lat: w.lat, lon: w.lon };}),
|
json: JSON.stringify({
|
||||||
costing: 'auto',
|
locations: waypoints.map(w => {return{ lat: w.lat, lon: w.lon };}),
|
||||||
directions_options:{
|
costing: 'auto',
|
||||||
units:'miles'}
|
directions_options:{
|
||||||
};
|
units:'miles'}
|
||||||
|
}),
|
||||||
|
format: 'osrm'
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -137,18 +142,10 @@ module.exports = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.extractInstructionList = (instructions, keyFinder) => {
|
this.extractInstructionList = (instructions, keyFinder) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
if (instructions) {
|
||||||
if (instructions) {
|
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.maneuvers), [])
|
.map(keyFinder)
|
||||||
.map(keyFinder)
|
.join(',');
|
||||||
.join(',');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (instructions) {
|
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
|
||||||
.map(keyFinder)
|
|
||||||
.join(',');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,13 +156,7 @@ module.exports = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.wayList = (instructions) => {
|
this.wayList = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
return this.extractInstructionList(instructions, s => s.name);
|
||||||
var result = this.extractInstructionList(instructions, s => s.street_names && s.street_names.join(',') || '');
|
|
||||||
var laststep = result.split(',').slice(-2)[0];
|
|
||||||
return result + laststep;
|
|
||||||
} else {
|
|
||||||
return this.extractInstructionList(instructions, s => s.name);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.refList = (instructions) => {
|
this.refList = (instructions) => {
|
||||||
@ -192,19 +183,12 @@ module.exports = function () {
|
|||||||
|
|
||||||
this.bearingList = (instructions) => {
|
this.bearingList = (instructions) => {
|
||||||
|
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
return this.extractInstructionList(instructions, s => ('in' in s.intersections[0] ? this.reverseBearing(s.intersections[0].bearings[s.intersections[0].in]) : 0)
|
||||||
return 'NOT IMPLEMENTED';
|
+ '->' +
|
||||||
} else {
|
('out' in s.intersections[0] ? s.intersections[0].bearings[s.intersections[0].out] : 0));
|
||||||
return this.extractInstructionList(instructions, s => ('in' in s.intersections[0] ? this.reverseBearing(s.intersections[0].bearings[s.intersections[0].in]) : 0)
|
|
||||||
+ '->' +
|
|
||||||
('out' in s.intersections[0] ? s.intersections[0].bearings[s.intersections[0].out] : 0));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.lanesList = (instructions) => {
|
this.lanesList = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
|
||||||
return 'NOT IMPLEMENTED';
|
|
||||||
} else {
|
|
||||||
return this.extractInstructionList(instructions, s => {
|
return this.extractInstructionList(instructions, s => {
|
||||||
return s.intersections.map( i => {
|
return s.intersections.map( i => {
|
||||||
if(i.lanes)
|
if(i.lanes)
|
||||||
@ -220,7 +204,6 @@ module.exports = function () {
|
|||||||
}
|
}
|
||||||
}).join(';');
|
}).join(';');
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.approachList = (instructions) => {
|
this.approachList = (instructions) => {
|
||||||
@ -250,94 +233,6 @@ module.exports = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.turnList = (instructions) => {
|
this.turnList = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
|
||||||
/*
|
|
||||||
from https://github.com/valhalla/valhalla-docs/blob/master/turn-by-turn/api-reference.md
|
|
||||||
|
|
||||||
kNone = 0;
|
|
||||||
kStart = 1; kStartRight = 2; kStartLeft = 3; kDestination = 4; kDestinationRight = 5; kDestinationLeft = 6;
|
|
||||||
kBecomes = 7; kContinue = 8;
|
|
||||||
kSlightRight = 9; kRight = 10; kSharpRight = 11; kUturnRight = 12;
|
|
||||||
|
|
||||||
kUturnLeft = 13; kSharpLeft = 14; kLeft = 15; kSlightLeft = 16;
|
|
||||||
|
|
||||||
kRampStraight = 17; kRampRight = 18; kRampLeft = 19;
|
|
||||||
|
|
||||||
kExitRight = 20; kExitLeft = 21;
|
|
||||||
|
|
||||||
kStayStraight = 22; kStayRight = 23; kStayLeft = 24;
|
|
||||||
|
|
||||||
kMerge = 25;
|
|
||||||
|
|
||||||
kRoundaboutEnter = 26;
|
|
||||||
kRoundaboutExit = 27;
|
|
||||||
kFerryEnter = 28;
|
|
||||||
kFerryExit = 29;
|
|
||||||
kTransit = 30;
|
|
||||||
kTransitTransfer = 31;
|
|
||||||
kTransitRemainOn = 32;
|
|
||||||
kTransitConnectionStart = 33;
|
|
||||||
kTransitConnectionTransfer = 34;
|
|
||||||
kTransitConnectionDestination = 35;
|
|
||||||
kPostTransitConnectionDestination = 36;
|
|
||||||
*/
|
|
||||||
var typemap = {
|
|
||||||
1: {type: 'depart', modifier: null },
|
|
||||||
2: {type: 'depart', modifier: 'right' },
|
|
||||||
3: {type: 'depart', modifier: 'left' },
|
|
||||||
|
|
||||||
4: {type: 'arrive', modifier: null },
|
|
||||||
5: {type: 'arrive', modifier: 'right' },
|
|
||||||
6: {type: 'arrive', modifier: 'left' },
|
|
||||||
|
|
||||||
7: {type: 'becomes', modifier: null },
|
|
||||||
8: {type: 'continue', modifier: 'straight' },
|
|
||||||
|
|
||||||
9: {type: 'turn', modifier: 'slight right' },
|
|
||||||
10: {type: 'turn', modifier: 'right' },
|
|
||||||
11: {type: 'turn', modifier: 'sharp right' },
|
|
||||||
12: {type: 'uturn', modifier: 'right' },
|
|
||||||
|
|
||||||
13: {type: 'uturn', modifier: 'left' },
|
|
||||||
14: {type: 'turn', modifier: 'sharp left' },
|
|
||||||
15: {type: 'turn', modifier: 'left' },
|
|
||||||
16: {type: 'turn', modifier: 'slight left' },
|
|
||||||
|
|
||||||
17: {type: 'on ramp', modifier: 'straight' },
|
|
||||||
18: {type: 'on ramp', modifier: 'right' },
|
|
||||||
19: {type: 'on ramp', modifier: 'left' },
|
|
||||||
|
|
||||||
20: {type: 'off ramp', modifier: 'right' },
|
|
||||||
21: {type: 'off ramp', modifier: 'left' },
|
|
||||||
|
|
||||||
22: {type: 'continue', modifier: 'straight' },
|
|
||||||
23: {type: 'continue', modifier: 'right' },
|
|
||||||
24: {type: 'continue', modifier: 'left' },
|
|
||||||
|
|
||||||
25: {type: 'merge', modifier: null },
|
|
||||||
|
|
||||||
26: {type: 'roundabout-exit', modifier: null },
|
|
||||||
27: {type: 'exit roundabout', modifier: null },
|
|
||||||
|
|
||||||
28: {type: 'enter ferry', modifier: null },
|
|
||||||
29: {type: 'exit ferry', modifier: null }
|
|
||||||
|
|
||||||
}
|
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.maneuvers), [])
|
|
||||||
.map(v => {
|
|
||||||
if (v.type in typemap) {
|
|
||||||
if (v.type === 26) { // special construction for roundabout instructions
|
|
||||||
return `${typemap[v.type].type}-${v.roundabout_exit_count}`;
|
|
||||||
} else if (typemap[v.type].modifier) {
|
|
||||||
return `${typemap[v.type].type} ${typemap[v.type].modifier}`;
|
|
||||||
} else {
|
|
||||||
return `${typemap[v.type].type}`;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "UNRECOGNIZED";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||||
.map(v => {
|
.map(v => {
|
||||||
switch (v.maneuver.type) {
|
switch (v.maneuver.type) {
|
||||||
@ -362,25 +257,17 @@ var typemap = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.join(',');
|
.join(',');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.locations = (instructions) => {
|
this.locations = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
|
||||||
return 'NOT IMPLEMENTED';
|
|
||||||
} else {
|
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||||
.map(v => {
|
.map(v => {
|
||||||
return this.findNodeByLocation(v.maneuver.location);
|
return this.findNodeByLocation(v.maneuver.location);
|
||||||
})
|
})
|
||||||
.join(',');
|
.join(',');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.intersectionList = (instructions) => {
|
this.intersectionList = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
|
||||||
return 'NOT IMPLEMENTED';
|
|
||||||
} else {
|
|
||||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||||
.map( v => {
|
.map( v => {
|
||||||
return v.intersections
|
return v.intersections
|
||||||
@ -391,7 +278,6 @@ var typemap = {
|
|||||||
return string;
|
return string;
|
||||||
}).join(',');
|
}).join(',');
|
||||||
}).join(';');
|
}).join(';');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.modeList = (instructions) => {
|
this.modeList = (instructions) => {
|
||||||
@ -403,11 +289,7 @@ var typemap = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.classesList = (instructions) => {
|
this.classesList = (instructions) => {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
|
||||||
return 'NOT IMPLEMENTED';
|
|
||||||
} else {
|
|
||||||
return this.extractInstructionList(instructions, s => '[' + s.intersections.map(i => '(' + (i.classes ? i.classes.join(',') : '') + ')').join(',') + ']');
|
return this.extractInstructionList(instructions, s => '[' + s.intersections.map(i => '(' + (i.classes ? i.classes.join(',') : '') + ')').join(',') + ']');
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.timeList = (instructions) => {
|
this.timeList = (instructions) => {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ module.exports = function () {
|
|||||||
var got;
|
var got;
|
||||||
|
|
||||||
var afterRequest = (err, res, body) => {
|
var afterRequest = (err, res, body) => {
|
||||||
console.log(waypoints);
|
console.log(body);
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (body && body.length) {
|
if (body && body.length) {
|
||||||
let destinations, exits, pronunciations, instructions, refs, bearings, turns, modes, times, classes,
|
let destinations, exits, pronunciations, instructions, refs, bearings, turns, modes, times, classes,
|
||||||
@ -44,21 +44,12 @@ module.exports = function () {
|
|||||||
let json = JSON.parse(body);
|
let json = JSON.parse(body);
|
||||||
|
|
||||||
var hasRoute = false;
|
var hasRoute = false;
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
got.code = json.code;
|
||||||
got.code = json.trip.status;
|
hasRoute = json.code === 'Ok' || json.code;
|
||||||
hasRoute = json.trip.status == 0;
|
|
||||||
} else {
|
|
||||||
got.code = json.code;
|
|
||||||
hasRoute = json.code === 'Ok';
|
|
||||||
}
|
|
||||||
var route;
|
var route;
|
||||||
|
|
||||||
if (hasRoute) {
|
if (hasRoute) {
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
route = json.routes[0];
|
||||||
route = json.trip;
|
|
||||||
} else {
|
|
||||||
route = json.routes[0];
|
|
||||||
}
|
|
||||||
instructions = this.wayList(route);
|
instructions = this.wayList(route);
|
||||||
pronunciations = this.pronunciationList(route);
|
pronunciations = this.pronunciationList(route);
|
||||||
refs = this.refList(route);
|
refs = this.refList(route);
|
||||||
@ -114,17 +105,16 @@ module.exports = function () {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
// Extract Valhalla route geometry
|
// OSRM route geometry
|
||||||
if (this.osrmLoader.method === 'valhalla') {
|
// TODO: Assume polyline5 for now
|
||||||
geojson.features[2].geometry.coordinates = polyline.decode(route.legs[0].shape,6).map(c => c.reverse());
|
if (typeof route.geometry === 'string') {
|
||||||
} else {
|
if (this.osrmLoader.method === 'valhalla') {
|
||||||
// OSRM route geometry
|
geojson.features[2].geometry.coordinates = polyline.decode(route.geometry,6).map(c => c.reverse());
|
||||||
// TODO: Assume polyline5 for now
|
|
||||||
if (typeof route.geometry === 'string') {
|
|
||||||
geojson.features[2].geometry.coordinates = polyline.decode(route.geometry).map(c => c.reverse());
|
|
||||||
} else {
|
} else {
|
||||||
geojson.features[2].geometry = route.geometry;
|
geojson.features[2].geometry.coordinates = polyline.decode(route.geometry).map(c => c.reverse());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
geojson.features[2].geometry = route.geometry;
|
||||||
}
|
}
|
||||||
fs.writeFileSync(`${this.scenarioCacheFile}_${rowIndex}_shape.geojson`,JSON.stringify(geojson));
|
fs.writeFileSync(`${this.scenarioCacheFile}_${rowIndex}_shape.geojson`,JSON.stringify(geojson));
|
||||||
}
|
}
|
||||||
@ -161,9 +151,9 @@ module.exports = function () {
|
|||||||
got.alternative = this.wayList(json.routes[1]);
|
got.alternative = this.wayList(json.routes[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var distance = hasRoute && (this.osrmLoader.method === 'valhalla') ? route.summary.length : route.distance,
|
var distance = hasRoute && route.distance,
|
||||||
time = hasRoute && (this.osrmLoader.method === 'valhalla') ? route.summary.time : route.duration,
|
time = hasRoute && route.duration,
|
||||||
weight = hasRoute && (this.osrmLoader.method === 'valhalla') ? route.summary.time : route.weight;
|
weight = hasRoute && route.weight;
|
||||||
|
|
||||||
if (headers.has('distance')) {
|
if (headers.has('distance')) {
|
||||||
if (row.distance.length) {
|
if (row.distance.length) {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "osrm",
|
"name": "osrm",
|
||||||
"version": "5.16.0-latest.1",
|
"version": "5.17.0-latest.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -10,8 +10,8 @@
|
|||||||
"nan": "^2.6.2",
|
"nan": "^2.6.2",
|
||||||
"node-cmake": "^2.3.2",
|
"node-cmake": "^2.3.2",
|
||||||
"node-pre-gyp": "^0.6.36",
|
"node-pre-gyp": "^0.6.36",
|
||||||
"osmtogeojson": "^3.0.0-beta.3"
|
"osmtogeojson": "^3.0.0-beta.3",
|
||||||
"rimraf": "^2.5.4"
|
"rimraf": "^2.5.4",
|
||||||
"xmldoc": "^1.1.0"
|
"xmldoc": "^1.1.0"
|
||||||
},
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user