Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Commit

Permalink
Exposes generate_hints parameter, resolves #300
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Feb 28, 2017
1 parent 42abaea commit 11386e7
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 15 deletions.
13 changes: 7 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ var osrm = new OSRM('network.osrm');

Each OSRM method (except for `OSRM.tile()`) has set of general options as well as unique options, outlined below.

| Option | Values | Description | Format |
| ----------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| coordinates | `array` of `coordinate` elements: `[{coordinate}, ...]` | The coordinates this request will use. | `array` with `[{lon},{lat}]` values, in decimal degrees |
| bearings | `array` of `bearing` elements: `[{bearing}, ...]` | Limits the search to segments with given bearing in degrees towards true north in clockwise direction. | `null` or `array` with `[{value},{range}]` `integer 0 .. 360,integer 0 .. 180` |
| radiuses | `array` of `radius` elements: `[{radius}, ...]` | Limits the search to given radius in meters. | `null` or `double >= 0` or `unlimited` (default) |
| hints | `array` of `hint` elements: `[{hint}, ...]` | Hint to derive position in street network. | Base64 `string` |
| Option | Values | Description | Format |
| --------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ |
| coordinates | `array` of `coordinate` elements: `[{coordinate}, ...]` | The coordinates this request will use. | `array` with `[{lon},{lat}]` values, in decimal degrees |
| bearings | `array` of `bearing` elements: `[{bearing}, ...]` | Limits the search to segments with given bearing in degrees towards true north in clockwise direction. | `null` or `array` with `[{value},{range}]` `integer 0 .. 360,integer 0 .. 180` |
| radiuses | `array` of `radius` elements: `[{radius}, ...]` | Limits the search to given radius in meters. | `null` or `double >= 0` or `unlimited` (default) |
| hints | `array` of `hint` elements: `[{hint}, ...]` | Hint to derive position in street network. | Base64 `string` |
| generate\_hints | `true` (default) or `false` | Adds a Hint to the response which can be used in subsequent requests, see `hints` parameter. | `Boolean` |

## route

Expand Down
37 changes: 29 additions & 8 deletions src/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
}
}

if (obj->Has(Nan::New("generate_hints").ToLocalChecked()))
{
v8::Local<v8::Value> generate_hints = obj->Get(Nan::New("generate_hints").ToLocalChecked());

if (!generate_hints->IsBoolean())
{
Nan::ThrowError("generate_hints must be of type Boolean");
return false;
}

params->generate_hints = generate_hints->BooleanValue();
}

return true;
}

Expand Down Expand Up @@ -430,31 +443,38 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
for (std::size_t i = 0; i < annotations_array->Length(); i++)
{
const Nan::Utf8String annotations_utf8str(annotations_array->Get(i));
std::string annotations_str{*annotations_utf8str, *annotations_utf8str + annotations_utf8str.length()};
std::string annotations_str{*annotations_utf8str,
*annotations_utf8str + annotations_utf8str.length()};

if (annotations_str == "duration")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Duration;
params->annotations_type =
params->annotations_type | osrm::RouteParameters::AnnotationsType::Duration;
}
else if (annotations_str == "nodes")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Nodes;
params->annotations_type =
params->annotations_type | osrm::RouteParameters::AnnotationsType::Nodes;
}
else if (annotations_str == "distance")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Distance;
params->annotations_type =
params->annotations_type | osrm::RouteParameters::AnnotationsType::Distance;
}
else if (annotations_str == "weight")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Weight;
params->annotations_type =
params->annotations_type | osrm::RouteParameters::AnnotationsType::Weight;
}
else if (annotations_str == "datasources")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Datasources;
params->annotations_type = params->annotations_type |
osrm::RouteParameters::AnnotationsType::Datasources;
}
else if (annotations_str == "speed")
{
params->annotations_type = params->annotations_type | osrm::RouteParameters::AnnotationsType::Speed;
params->annotations_type =
params->annotations_type | osrm::RouteParameters::AnnotationsType::Speed;
}
else
{
Expand All @@ -480,7 +500,8 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
return false;
}
const Nan::Utf8String geometries_utf8str(geometries);
std::string geometries_str{*geometries_utf8str, *geometries_utf8str + geometries_utf8str.length()};
std::string geometries_str{*geometries_utf8str,
*geometries_utf8str + geometries_utf8str.length()};

if (geometries_str == "polyline")
{
Expand Down
44 changes: 43 additions & 1 deletion test/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ test('table: distance table in Berlin with sources/destinations', function(asser
});

test('table: throws on invalid arguments', function(assert) {
assert.plan(13);
assert.plan(14);
var osrm = new OSRM(berlin_path);
var options = {};
assert.throws(function() { osrm.table(options); },
Expand Down Expand Up @@ -109,6 +109,9 @@ test('table: throws on invalid arguments', function(assert) {
options.destinations = [0, 1];
assert.doesNotThrow(function() { osrm.table(options, function(err, response) {}) },
/You can either specify sources and destinations, or coordinates/);

assert.throws(function() { osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]], generate_hints: null}, function(err, route) {}) },
/generate_hints must be of type Boolean/);
});

test('table: throws on invalid arguments', function(assert) {
Expand All @@ -117,3 +120,42 @@ test('table: throws on invalid arguments', function(assert) {
assert.throws(function() { osrm.table(null, function() {}); },
/First arg must be an object/);
});

test('table: distance table in Berlin with hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
generate_hints: true // true is default but be explicit here
};
osrm.table(options, function(err, table) {
console.log(table);
assert.ifError(err);

function assertHasHints(waypoint) {
assert.notStrictEqual(waypoint.hint, undefined);
}

table.sources.map(assertHasHints);
table.destinations.map(assertHasHints);
});
});

test('table: distance table in Berlin without hints', function(assert) {
assert.plan(5);
var osrm = new OSRM(berlin_path);
var options = {
coordinates: [[13.43864,52.51993],[13.415852,52.513191]],
generate_hints: false // true is default
};
osrm.table(options, function(err, table) {
assert.ifError(err);

function assertHasNoHints(waypoint) {
assert.strictEqual(waypoint.hint, undefined);
}

table.sources.map(assertHasNoHints);
table.destinations.map(assertHasNoHints);
});
});

0 comments on commit 11386e7

Please sign in to comment.