Allow specifing a weight for routing that is independent of duration

This commit is contained in:
Patrick Niklaus
2016-05-12 18:50:10 +02:00
committed by Patrick Niklaus
parent e463733138
commit 279f8aabfb
85 changed files with 2100 additions and 853 deletions
+18 -4
View File
@@ -164,15 +164,21 @@ module.exports = function () {
};
this.annotationList = (instructions) => {
function zip(list_1, list_2, list_3)
if (!('annotation' in instructions.legs[0]))
return '';
function zip(list_1, list_2, list_3, list_4)
{
let tuples = [];
for (let i = 0; i < list_1.length; ++i) {
tuples.push([list_1[i], list_2[i], list_3[i]]);
for (let i = 0; i < list_1.length; ++i) {
tuples.push([list_1[i], list_2[i], list_3[i], list_4[i]]);
}
return tuples;
}
return instructions.legs.map(l => {return zip(l.annotation.duration, l.annotation.distance, l.annotation.datasources).map(p => { return p.join(':'); }).join(','); }).join(',');
return instructions.legs.map(l => {
const values = zip( l.annotation.weight, l.annotation.duration, l.annotation.distance, l.annotation.datasources);
return values.map(p => { return p.join(':'); }).join(',');
}).join(',');
};
this.OSMIDList = (instructions) => {
@@ -250,4 +256,12 @@ module.exports = function () {
this.distanceList = (instructions) => {
return this.extractInstructionList(instructions, s => s.distance + 'm');
};
this.weightName = (instructions) => {
return instructions ? instructions.weight_name : '';
};
this.weightList = (instructions) => {
return this.extractInstructionList(instructions, s => s.weight);
};
};
+10 -1
View File
@@ -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, locations;
distances, summary, intersections, lanes, locations, annotation, weight_name, weights;
let json = JSON.parse(body);
@@ -55,6 +55,9 @@ module.exports = function () {
lanes = this.lanesList(json.routes[0]);
summary = this.summary(json.routes[0]);
locations = this.locations(json.routes[0]);
annotation = this.annotationList(json.routes[0]);
weight_name = this.weightName(json.routes[0]);
weights = this.weightList(json.routes[0]);
}
if (headers.has('status')) {
@@ -130,6 +133,10 @@ module.exports = function () {
got.locations = (locations || '').trim();
}
if (headers.has('annotation')){
got.annotation = (annotation || '').trim();
}
var putValue = (key, value) => {
if (headers.has(key)) got[key] = instructions ? value : '';
};
@@ -142,6 +149,8 @@ module.exports = function () {
putValue('distances', distances);
putValue('pronunciations', pronunciations);
putValue('destinations', destinations);
putValue('weight_name', weight_name);
putValue('weights', weights);
}
for (var key in row) {