furkot-directions
Advanced tools
Comparing version 0.0.10 to 0.0.11
0.0.11 / 2017-01-10 | ||
=================== | ||
* equate no response with empty (i.e. no route available) | ||
* fix checking Maquest status | ||
* fix Google Maps API response status | ||
0.0.10 / 2017-01-10 | ||
@@ -3,0 +10,0 @@ =================== |
@@ -81,3 +81,5 @@ var _defaults = require('lodash.defaults'); | ||
function request(url, req, fn) { | ||
gmService.route(req, function (response) { | ||
gmService.route(req, function (response, status) { | ||
response = response || {}; | ||
response.status = response.status || status; | ||
fn(undefined, response); | ||
@@ -84,0 +86,0 @@ }); |
@@ -86,2 +86,7 @@ var _defaults = require('lodash.defaults'); | ||
st = options.status(response); | ||
if (st === undefined) { | ||
// shouldn't happen (bug or unexpected response format) | ||
// treat it as no route | ||
st = status.empty; | ||
} | ||
if (st === status.failure) { | ||
@@ -88,0 +93,0 @@ // don't ever ask again |
@@ -84,3 +84,3 @@ var _defaults = require('lodash.defaults'); | ||
} | ||
if (status === 0) { | ||
if (st === 0) { | ||
if (response.route) { | ||
@@ -87,0 +87,0 @@ return status.success; |
@@ -48,9 +48,8 @@ var _defaults = require('lodash.defaults'); | ||
// reponse codes: http://project-osrm.org/docs/v5.5.2/api/#responses | ||
// response codes: http://project-osrm.org/docs/v5.5.2/api/#responses | ||
function getStatus(response) { | ||
var code = response && response.code; | ||
var code = response && response.code; | ||
if (!response) { | ||
return; | ||
} | ||
return code2status[code] || status.error; | ||
@@ -103,3 +102,2 @@ } | ||
directions = { | ||
@@ -110,30 +108,31 @@ query: query, | ||
if (response.waypoints) { | ||
directions.places = response.waypoints.map(convertPlace); | ||
} | ||
if (response.routes) { | ||
directions.routes = convertRoute(response.routes[0]); | ||
if (query.turnbyturn || query.path === pathType.smooth || query.path === pathType.coarse) { | ||
directions.segments = []; | ||
// copy segments from route to its own table | ||
directions.routes.forEach(function(route) { | ||
route.segmentIndex = directions.segments.length; | ||
directions.segments = directions.segments.concat(route.segments); | ||
delete route.segments; | ||
}); | ||
} else { | ||
// delete segments | ||
directions.routes.forEach(function(route) { | ||
delete route.segments; | ||
}); | ||
if (response) { | ||
if (response.waypoints) { | ||
directions.places = response.waypoints.map(convertPlace); | ||
} | ||
if (query.path === pathType.full) { | ||
// path is already prepared - no need to do it again from segments | ||
directions.pathReady = true; | ||
if (response.routes) { | ||
directions.routes = convertRoute(response.routes[0]); | ||
if (query.turnbyturn || query.path === pathType.smooth || query.path === pathType.coarse) { | ||
directions.segments = []; | ||
// copy segments from route to its own table | ||
directions.routes.forEach(function(route) { | ||
route.segmentIndex = directions.segments.length; | ||
directions.segments = directions.segments.concat(route.segments); | ||
delete route.segments; | ||
}); | ||
} else { | ||
// delete segments | ||
directions.routes.forEach(function(route) { | ||
delete route.segments; | ||
}); | ||
} | ||
if (query.path === pathType.full) { | ||
// path is already prepared - no need to do it again from segments | ||
directions.pathReady = true; | ||
} | ||
} | ||
} | ||
return directions; | ||
@@ -140,0 +139,0 @@ } |
{ | ||
"name": "furkot-directions", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "Directions service for Furkot", | ||
@@ -5,0 +5,0 @@ "author": { |
83708
1318