Add node binding integration
This commit is contained in:
parent
a4460abc83
commit
da252c7597
@ -585,6 +585,39 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
|
||||
params->generate_hints = generate_hints->BooleanValue();
|
||||
}
|
||||
|
||||
if (obj->Has(Nan::New("exclude").ToLocalChecked()))
|
||||
{
|
||||
v8::Local<v8::Value> exclude = obj->Get(Nan::New("exclude").ToLocalChecked());
|
||||
if (exclude.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (!exclude->IsArray())
|
||||
{
|
||||
Nan::ThrowError("Exclude must be an array of strings or empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::Local<v8::Array> exclude_array = v8::Local<v8::Array>::Cast(exclude);
|
||||
|
||||
for (uint32_t i = 0; i < exclude_array->Length(); ++i)
|
||||
{
|
||||
v8::Local<v8::Value> class_name = exclude_array->Get(i);
|
||||
if (class_name.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (class_name->IsString())
|
||||
{
|
||||
std::string class_name_str = *v8::String::Utf8Value(class_name);
|
||||
params->exclude.emplace_back(class_name_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("Exclude must be an array of strings or empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var data_path = require('./constants').data_path;
|
||||
var mld_data_path = require('./constants').mld_data_path;
|
||||
var three_test_coordinates = require('./constants').three_test_coordinates;
|
||||
var two_test_coordinates = require('./constants').two_test_coordinates;
|
||||
|
||||
@ -223,3 +224,17 @@ test('match: throws on invalid tidy param', function(assert) {
|
||||
assert.throws(function() { osrm.match(options, function(err, response) {}) },
|
||||
/tidy must be of type Boolean/);
|
||||
});
|
||||
|
||||
test('match: match in Monaco without motorways', function(assert) {
|
||||
assert.plan(3);
|
||||
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
||||
var options = {
|
||||
coordinates: three_test_coordinates,
|
||||
exclude: ['motorway']
|
||||
};
|
||||
osrm.match(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.tracepoints.length, 3);
|
||||
assert.equal(response.matchings.length, 1);
|
||||
});
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var data_path = require('./constants').data_path;
|
||||
var mld_data_path = require('./constants').mld_data_path;
|
||||
var three_test_coordinates = require('./constants').three_test_coordinates;
|
||||
var two_test_coordinates = require('./constants').two_test_coordinates;
|
||||
|
||||
@ -52,3 +53,16 @@ test('nearest: throws on invalid args', function(assert) {
|
||||
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
||||
/Number must be an integer greater than or equal to 1/);
|
||||
});
|
||||
|
||||
test('nearest: nearest in Monaco without motorways', function(assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
||||
var options = {
|
||||
coordinates: [two_test_coordinates[0]],
|
||||
exclude: ['motorway']
|
||||
};
|
||||
osrm.nearest(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.waypoints.length, 1);
|
||||
});
|
||||
});
|
||||
|
@ -576,3 +576,17 @@ test('route: in Monaco with custom limits on MLD', function(assert) {
|
||||
});
|
||||
});
|
||||
|
||||
test('route: route in Monaco without motorways', function(assert) {
|
||||
assert.plan(3);
|
||||
var osrm = new OSRM({path: monaco_mld_path, algorithm: 'MLD'});
|
||||
var options = {
|
||||
coordinates: two_test_coordinates,
|
||||
exclude: ['motorway']
|
||||
};
|
||||
osrm.route(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.waypoints.length, 2);
|
||||
assert.equal(response.routes.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var data_path = require('./constants').data_path;
|
||||
var mld_data_path = require('./constants').mld_data_path;
|
||||
var three_test_coordinates = require('./constants').three_test_coordinates;
|
||||
var two_test_coordinates = require('./constants').two_test_coordinates;
|
||||
|
||||
@ -166,3 +167,17 @@ test('table: distance table in Monaco without hints', function(assert) {
|
||||
table.destinations.map(assertHasNoHints);
|
||||
});
|
||||
});
|
||||
|
||||
test('table: table in Monaco without motorways', function(assert) {
|
||||
assert.plan(2);
|
||||
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
||||
var options = {
|
||||
coordinates: two_test_coordinates,
|
||||
exclude: ['motorway']
|
||||
};
|
||||
osrm.table(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.durations.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
var OSRM = require('../../');
|
||||
var test = require('tape');
|
||||
var data_path = require('./constants').data_path;
|
||||
var mld_data_path = require('./constants').mld_data_path;
|
||||
var three_test_coordinates = require('./constants').three_test_coordinates;
|
||||
var two_test_coordinates = require('./constants').two_test_coordinates;
|
||||
|
||||
@ -325,3 +326,18 @@ test('trip: fixed start and end combinations', function(assert) {
|
||||
|
||||
assert.end();
|
||||
});
|
||||
|
||||
test('trip: trip in Monaco without motorways', function(assert) {
|
||||
assert.plan(3);
|
||||
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
|
||||
var options = {
|
||||
coordinates: two_test_coordinates,
|
||||
exclude: ['motorway']
|
||||
};
|
||||
osrm.trip(options, function(err, response) {
|
||||
assert.ifError(err);
|
||||
assert.equal(response.waypoints.length, 2);
|
||||
assert.equal(response.trips.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user