add locations feature to allow testing turn locations, fix minor bug breaking the arrival location
This commit is contained in:
@@ -126,6 +126,20 @@ module.exports = function () {
|
||||
return fromNode;
|
||||
};
|
||||
|
||||
// find a node based on an array containing lon/lat
|
||||
this.findNodeByLocation = (node_location) => {
|
||||
var searched_coordinate = new classes.Location(node_location[0],node_location[1]);
|
||||
for (var node in this.nameNodeHash)
|
||||
{
|
||||
var node_coordinate = new classes.Location(this.nameNodeHash[node].lon,this.nameNodeHash[node].lat);
|
||||
if (this.FuzzyMatch.matchCoordinate(searched_coordinate, node_coordinate, this.zoom))
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
return '_';
|
||||
};
|
||||
|
||||
this.findWayByName = (s) => {
|
||||
return this.nameWayHash[s.toString()] || this.nameWayHash[s.toString().split('').reverse().join('')];
|
||||
};
|
||||
|
||||
@@ -111,5 +111,12 @@ module.exports = {
|
||||
return this.match(got[0], util.format('%d ~0.0025%', want.lon)) &&
|
||||
this.match(got[1], util.format('%d ~0.0025%', want.lat));
|
||||
}
|
||||
|
||||
matchCoordinate (got, want, zoom) {
|
||||
if (got == null || want == null) return false;
|
||||
return this.match(got.lon, util.format('%d +- %d', want.lon, 0.25*zoom)) &&
|
||||
this.match(got.lat, util.format('%d +- %d', want.lat, 0.25*zoom));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -211,6 +211,14 @@ module.exports = function () {
|
||||
.join(',');
|
||||
};
|
||||
|
||||
this.locations = (instructions) => {
|
||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||
.map(v => {
|
||||
return this.findNodeByLocation(v.maneuver.location);
|
||||
})
|
||||
.join(',');
|
||||
};
|
||||
|
||||
this.intersectionList = (instructions) => {
|
||||
return instructions.legs.reduce((m, v) => m.concat(v.steps), [])
|
||||
.map( v => {
|
||||
|
||||
@@ -35,7 +35,7 @@ module.exports = function () {
|
||||
if (err) return cb(err);
|
||||
if (body && body.length) {
|
||||
let destinations, pronunciations, instructions, refs, bearings, turns, modes, times,
|
||||
distances, summary, intersections, lanes;
|
||||
distances, summary, intersections, lanes, locations;
|
||||
|
||||
let json = JSON.parse(body);
|
||||
|
||||
@@ -54,6 +54,7 @@ module.exports = function () {
|
||||
distances = this.distanceList(json.routes[0]);
|
||||
lanes = this.lanesList(json.routes[0]);
|
||||
summary = this.summary(json.routes[0]);
|
||||
locations = this.locations(json.routes[0]);
|
||||
}
|
||||
|
||||
if (headers.has('status')) {
|
||||
@@ -125,6 +126,10 @@ module.exports = function () {
|
||||
got.intersections = (intersections || '').trim();
|
||||
}
|
||||
|
||||
if (headers.has('locations')){
|
||||
got.locations = (locations || '').trim();
|
||||
}
|
||||
|
||||
var putValue = (key, value) => {
|
||||
if (headers.has(key)) got[key] = instructions ? value : '';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user