Integrate MLD into node-bindings
This commit is contained in:
parent
ac0c5c27e7
commit
90ed027711
@ -117,6 +117,7 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
|||||||
{
|
{
|
||||||
engine_config->storage_config =
|
engine_config->storage_config =
|
||||||
osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked()));
|
osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked()));
|
||||||
|
engine_config->use_shared_memory = false;
|
||||||
}
|
}
|
||||||
if (!shared_memory->IsUndefined())
|
if (!shared_memory->IsUndefined())
|
||||||
{
|
{
|
||||||
@ -141,18 +142,18 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
|
|||||||
auto algorithm = params->Get(Nan::New("algorithm").ToLocalChecked());
|
auto algorithm = params->Get(Nan::New("algorithm").ToLocalChecked());
|
||||||
if (algorithm->IsString())
|
if (algorithm->IsString())
|
||||||
{
|
{
|
||||||
auto algorithm_str = *v8::String::Utf8Value(Nan::To<v8::String>(algorithm).ToLocalChecked());
|
auto algorithm_str = Nan::To<v8::String>(algorithm).ToLocalChecked();
|
||||||
if (name == "CH")
|
if (*v8::String::Utf8Value(algorithm_str) == std::string("CH"))
|
||||||
{
|
{
|
||||||
engine_config->algorithm = EngineConfig::Algorithm::CH;
|
engine_config->algorithm = osrm::EngineConfig::Algorithm::CH;
|
||||||
}
|
}
|
||||||
else if (name == "CoreCH")
|
else if (*v8::String::Utf8Value(algorithm_str) == std::string("CoreCH"))
|
||||||
{
|
{
|
||||||
engine_config->algorithm = EngineConfig::Algorithm::CoreCH;
|
engine_config->algorithm = osrm::EngineConfig::Algorithm::CoreCH;
|
||||||
}
|
}
|
||||||
else if (name == "MLD")
|
else if (*v8::String::Utf8Value(algorithm_str) == std::string("MLD"))
|
||||||
{
|
{
|
||||||
engine_config->algorithm = EngineConfig::Algorithm::MLD;
|
engine_config->algorithm = osrm::EngineConfig::Algorithm::MLD;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
var OSRM = require('../../');
|
var OSRM = require('../../');
|
||||||
var test = require('tape');
|
var test = require('tape');
|
||||||
var berlin_path = require('./osrm-data-path').data_path;
|
var berlin_path = require('./osrm-data-path').data_path;
|
||||||
|
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
|
||||||
|
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
|
||||||
|
|
||||||
test('constructor: throws if new keyword is not used', function(assert) {
|
test('constructor: throws if new keyword is not used', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
@ -23,7 +25,7 @@ test('constructor: does not accept more than one parameter', function(assert) {
|
|||||||
test('constructor: throws if necessary files do not exist', function(assert) {
|
test('constructor: throws if necessary files do not exist', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { new OSRM("missing.osrm"); },
|
assert.throws(function() { new OSRM("missing.osrm"); },
|
||||||
/Invalid file paths/);
|
/Error opening missing.osrm.names/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('constructor: takes a shared memory argument', function(assert) {
|
test('constructor: takes a shared memory argument', function(assert) {
|
||||||
@ -34,32 +36,50 @@ test('constructor: takes a shared memory argument', function(assert) {
|
|||||||
|
|
||||||
test('constructor: throws if shared_memory==false with no path defined', function(assert) {
|
test('constructor: throws if shared_memory==false with no path defined', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { var osrm = new OSRM({shared_memory: false}); },
|
assert.throws(function() { new OSRM({shared_memory: false}); },
|
||||||
/Shared_memory must be enabled if no path is specified/);
|
/Shared_memory must be enabled if no path is specified/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('constructor: throws if given a non-bool shared_memory option', function(assert) {
|
test('constructor: throws if given a non-bool shared_memory option', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { var osrm = new OSRM({path: berlin_path, shared_memory: "a"}); },
|
assert.throws(function() { new OSRM({path: berlin_path, shared_memory: 'a'}); },
|
||||||
/Shared_memory option must be a boolean/);
|
/Shared_memory option must be a boolean/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('constructor: throws if given a non-string/obj argument', function(assert) {
|
test('constructor: throws if given a non-string/obj argument', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { var osrm = new OSRM(true); },
|
assert.throws(function() { new OSRM(true); },
|
||||||
/Parameter must be a path or options object/);
|
/Parameter must be a path or options object/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('constructor: throws if given an unkown algorithm', function(assert) {
|
test('constructor: throws if given an unkown algorithm', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { var osrm = new OSRM({algorithm: "Foo", shared_memory: true}); },
|
assert.throws(function() { new OSRM({algorithm: 'Foo', shared_memory: true}); },
|
||||||
/algorithm option needs to be one of 'CH', 'CoreCH', or 'MLD'/);
|
/algorithm option must be one of 'CH', 'CoreCH', or 'MLD'/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('constructor: throws if given an invalid algorithm', function(assert) {
|
test('constructor: throws if given an invalid algorithm', function(assert) {
|
||||||
assert.plan(1);
|
assert.plan(1);
|
||||||
assert.throws(function() { var osrm = new OSRM({algorithm: 3, shared_memory: true}); },
|
assert.throws(function() { new OSRM({algorithm: 3, shared_memory: true}); },
|
||||||
/algorithm option needs to be a string and one of 'CH', 'CoreCH', or 'MLD'/);
|
/algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('constructor: loads MLD if given as algorithm', function(assert) {
|
||||||
|
assert.plan(1);
|
||||||
|
var osrm = new OSRM({algorithm: 'MLD', path: berlin_mld_path});
|
||||||
|
assert.ok(osrm);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('constructor: loads CH if given as algorithm', function(assert) {
|
||||||
|
assert.plan(1);
|
||||||
|
var osrm = new OSRM({algorithm: 'CH', path: berlin_path});
|
||||||
|
assert.ok(osrm);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('constructor: loads CoreCH if given as algorithm', function(assert) {
|
||||||
|
assert.plan(1);
|
||||||
|
var osrm = new OSRM({algorithm: 'CoreCH', path: berlin_corech_path});
|
||||||
|
assert.ok(osrm);
|
||||||
});
|
});
|
||||||
|
|
||||||
require('./route.js');
|
require('./route.js');
|
||||||
|
@ -2,7 +2,11 @@ var path = require('path');
|
|||||||
|
|
||||||
if (process.env.OSRM_DATA_PATH !== undefined) {
|
if (process.env.OSRM_DATA_PATH !== undefined) {
|
||||||
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/berlin.osrm");
|
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/berlin.osrm");
|
||||||
|
exports.mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/berlin.osrm");
|
||||||
|
exports.corech_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "corech/berlin.osrm");
|
||||||
console.log('Setting custom data path to ' + exports.data_path);
|
console.log('Setting custom data path to ' + exports.data_path);
|
||||||
} else {
|
} else {
|
||||||
exports.data_path = path.resolve(path.join(__dirname, "../data/ch/berlin.osrm"));
|
exports.data_path = path.resolve(path.join(__dirname, "../data/ch/berlin.osrm"));
|
||||||
|
exports.mld_data_path = path.resolve(path.join(__dirname, "../data/mld/berlin.osrm"));
|
||||||
|
exports.corech_data_path = path.resolve(path.join(__dirname, "../data/corech/berlin.osrm"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user