WIP: race conditions and stalling server
This commit is contained in:
committed by
Patrick Niklaus
parent
8ac403abb9
commit
8947c789a9
@@ -94,13 +94,13 @@ module.exports = function () {
|
||||
q.awaitAll(callback);
|
||||
};
|
||||
|
||||
var ensureDecimal = (i) => {
|
||||
this.ensureDecimal = (i) => {
|
||||
if (parseInt(i) === i) return i.toFixed(1);
|
||||
else return i;
|
||||
};
|
||||
|
||||
this.tableCoordToLonLat = (ci, ri) => {
|
||||
return [this.origin[0] + ci * this.zoom, this.origin[1] - ri * this.zoom].map(ensureDecimal);
|
||||
return [this.origin[0] + ci * this.zoom, this.origin[1] - ri * this.zoom].map(this.ensureDecimal);
|
||||
};
|
||||
|
||||
this.addOSMNode = (name, lon, lat, id) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('util');
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
|
||||
var OSRMError = class extends Error {
|
||||
@@ -23,8 +24,8 @@ var OSRMError = class extends Error {
|
||||
});
|
||||
}
|
||||
|
||||
logTail (path, n, callback) {
|
||||
var expanded = path.resolve(this.TEST_FOLDER, path);
|
||||
logTail (logPath, n, callback) {
|
||||
var expanded = path.resolve(this.TEST_FOLDER, logPath);
|
||||
fs.exists(expanded, (exists) => {
|
||||
if (exists) {
|
||||
fs.readFile(expanded, (err, data) => {
|
||||
|
||||
@@ -34,7 +34,7 @@ module.exports = function () {
|
||||
};
|
||||
|
||||
var encodeWaypoints = (waypoints) => {
|
||||
return waypoints.map(w => [w.lon, w.lat].join(','));
|
||||
return waypoints.map(w => [w.lon, w.lat].map(this.ensureDecimal).join(','));
|
||||
};
|
||||
|
||||
this.requestRoute = (waypoints, bearings, userParams, callback) => {
|
||||
@@ -43,7 +43,7 @@ module.exports = function () {
|
||||
var defaults = {
|
||||
output: 'json',
|
||||
steps: 'true',
|
||||
alternative: 'false'
|
||||
alternatives: 'false'
|
||||
},
|
||||
params = this.overwriteParams(defaults, userParams),
|
||||
encodedWaypoints = encodeWaypoints(waypoints);
|
||||
@@ -108,18 +108,19 @@ module.exports = function () {
|
||||
return this.requestPath('match', params, callback);
|
||||
};
|
||||
|
||||
this.extractInstructionList = (instructions, index, postfix) => {
|
||||
this.extractInstructionList = (instructions, keyFinder, postfix) => {
|
||||
postfix = postfix || null;
|
||||
if (instructions) {
|
||||
return instructions.filter(r => r[0].toString() !== this.DESTINATION_REACHED.toString())
|
||||
.map(r => r[index])
|
||||
.map(r => (isNaN(parseInt(r)) && (!r || r == '')) ? '""' : '' + r + (postfix || ''))
|
||||
return Array.prototype.concat.apply([],
|
||||
instructions.legs.map(l => l.steps))
|
||||
.filter(s => s.maneuver.type !== 'arrive')
|
||||
.map(keyFinder)
|
||||
.join(',');
|
||||
}
|
||||
};
|
||||
|
||||
this.wayList = (instructions) => {
|
||||
return this.extractInstructionList(instructions, 1);
|
||||
return this.extractInstructionList(instructions, s => s.name);
|
||||
};
|
||||
|
||||
this.compassList = (instructions) => {
|
||||
|
||||
@@ -39,13 +39,13 @@ module.exports = function () {
|
||||
var hasRoute = json.status === 200;
|
||||
|
||||
if (hasRoute) {
|
||||
instructions = this.wayList(json.route_instructions);
|
||||
bearings = this.bearingList(json.route_instructions);
|
||||
compasses = this.compassList(json.route_instructions);
|
||||
turns = this.turnList(json.route_instructions);
|
||||
modes = this.modeList(json.route_instructions);
|
||||
times = this.timeList(json.route_instructions);
|
||||
distances = this.distanceList(json.route_instructions);
|
||||
instructions = this.wayList(json.routes[0]);
|
||||
bearings = this.bearingList(json.routes[0]);
|
||||
compasses = this.compassList(json.routes[0]);
|
||||
turns = this.turnList(json.routes[0]);
|
||||
modes = this.modeList(json.routes[0]);
|
||||
times = this.timeList(json.routes[0]);
|
||||
distances = this.distanceList(json.routes[0]);
|
||||
}
|
||||
|
||||
if (headers.has('status')) {
|
||||
@@ -81,8 +81,8 @@ module.exports = function () {
|
||||
this.wayList(json.alternative_instructions[0]) : '';
|
||||
}
|
||||
|
||||
var distance = hasRoute && json.route_summary.total_distance,
|
||||
time = hasRoute && json.route_summary.total_time;
|
||||
var distance = hasRoute && json.routes[0].distance,
|
||||
time = hasRoute && json.routes[0].duration;
|
||||
|
||||
if (headers.has('distance')) {
|
||||
if (row.distance.length) {
|
||||
|
||||
Reference in New Issue
Block a user