2017-03-01 12:27:57 -05:00
|
|
|
var OSRM = require('../../');
|
|
|
|
var test = require('tape');
|
2017-03-29 09:28:45 -04:00
|
|
|
var data_path = require('./constants').data_path;
|
2017-08-16 17:35:02 -04:00
|
|
|
var mld_data_path = require('./constants').mld_data_path;
|
2017-03-29 09:28:45 -04:00
|
|
|
var three_test_coordinates = require('./constants').three_test_coordinates;
|
|
|
|
var two_test_coordinates = require('./constants').two_test_coordinates;
|
2022-08-29 16:01:26 -04:00
|
|
|
const flatbuffers = require('../../features/support/flatbuffers').flatbuffers;
|
|
|
|
const FBResult = require('../../features/support/fbresult_generated').osrm.engine.api.fbresult.FBResult;
|
2017-03-29 09:28:45 -04:00
|
|
|
|
2017-03-01 12:27:57 -05:00
|
|
|
|
2022-08-29 16:01:26 -04:00
|
|
|
test('nearest with flatbuffers format', function(assert) {
|
|
|
|
assert.plan(5);
|
|
|
|
var osrm = new OSRM(data_path);
|
|
|
|
osrm.nearest({
|
|
|
|
coordinates: [three_test_coordinates[0]],
|
|
|
|
format: 'flatbuffers'
|
|
|
|
}, function(err, result) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(result instanceof Buffer);
|
|
|
|
const fb = FBResult.getRootAsFBResult(new flatbuffers.ByteBuffer(result));
|
|
|
|
assert.equals(fb.waypointsLength(), 1);
|
|
|
|
assert.ok(fb.waypoints(0).location());
|
|
|
|
assert.ok(fb.waypoints(0).name());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-01 12:27:57 -05:00
|
|
|
test('nearest', function(assert) {
|
|
|
|
assert.plan(4);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
osrm.nearest({
|
2017-03-29 09:28:45 -04:00
|
|
|
coordinates: [three_test_coordinates[0]]
|
2017-03-01 12:27:57 -05:00
|
|
|
}, function(err, result) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(result.waypoints.length, 1);
|
|
|
|
assert.equal(result.waypoints[0].location.length, 2);
|
|
|
|
assert.ok(result.waypoints[0].hasOwnProperty('name'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-02 01:22:37 -04:00
|
|
|
test('nearest', function(assert) {
|
|
|
|
assert.plan(5);
|
|
|
|
var osrm = new OSRM(data_path);
|
|
|
|
osrm.nearest({
|
|
|
|
coordinates: [three_test_coordinates[0]]
|
|
|
|
}, { format: 'json_buffer' }, function(err, result) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(result instanceof Buffer);
|
|
|
|
result = JSON.parse(result);
|
|
|
|
assert.equal(result.waypoints.length, 1);
|
|
|
|
assert.equal(result.waypoints[0].location.length, 2);
|
|
|
|
assert.ok(result.waypoints[0].hasOwnProperty('name'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-03-01 12:27:57 -05:00
|
|
|
test('nearest: can ask for multiple nearest pts', function(assert) {
|
|
|
|
assert.plan(2);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
osrm.nearest({
|
2017-03-29 09:28:45 -04:00
|
|
|
coordinates: [three_test_coordinates[0]],
|
2017-03-01 12:27:57 -05:00
|
|
|
number: 3
|
|
|
|
}, function(err, result) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(result.waypoints.length, 3);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('nearest: throws on invalid args', function(assert) {
|
2018-09-02 01:22:37 -04:00
|
|
|
assert.plan(7);
|
2017-03-29 09:28:45 -04:00
|
|
|
var osrm = new OSRM(data_path);
|
2017-03-01 12:27:57 -05:00
|
|
|
var options = {};
|
|
|
|
assert.throws(function() { osrm.nearest(options); },
|
|
|
|
/Two arguments required/);
|
|
|
|
assert.throws(function() { osrm.nearest(null, function(err, res) {}); },
|
|
|
|
/First arg must be an object/);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [43.73072];
|
2017-03-01 12:27:57 -05:00
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Coordinates must be an array of /);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [three_test_coordinates[0], three_test_coordinates[1]];
|
2017-03-01 12:27:57 -05:00
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Exactly one coordinate pair must be provided/);
|
2017-03-29 09:28:45 -04:00
|
|
|
options.coordinates = [three_test_coordinates[0]];
|
2017-03-01 12:27:57 -05:00
|
|
|
options.number = 3.14159;
|
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Number must be an integer greater than or equal to 1/);
|
|
|
|
options.number = 0;
|
|
|
|
assert.throws(function() { osrm.nearest(options, function(err, res) {}); },
|
|
|
|
/Number must be an integer greater than or equal to 1/);
|
2018-09-02 01:22:37 -04:00
|
|
|
|
|
|
|
options.number = 1;
|
|
|
|
assert.throws(function() { osrm.nearest(options, { format: 'invalid' }, function(err, res) {}); },
|
|
|
|
/format must be a string:/);
|
2017-03-01 12:27:57 -05:00
|
|
|
});
|
2017-08-16 17:35:02 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2023-08-04 13:43:37 -04:00
|
|
|
|
|
|
|
test('nearest: throws on disabled geometry', function(assert) {
|
|
|
|
assert.plan(1);
|
|
|
|
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
|
|
|
var options = {
|
|
|
|
coordinates: [two_test_coordinates[0]],
|
|
|
|
};
|
|
|
|
osrm.nearest(options, function(err, response) {
|
|
|
|
console.log(err)
|
|
|
|
assert.match(err.message, /DisabledDatasetException/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test('nearest: ok on disabled geometry', function(assert) {
|
|
|
|
assert.plan(2);
|
|
|
|
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_GEOMETRY']});
|
|
|
|
var options = {
|
|
|
|
coordinates: [two_test_coordinates[0]],
|
|
|
|
skip_waypoints: true,
|
|
|
|
};
|
|
|
|
osrm.nearest(options, function(err, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.notok(response.waypoints);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('nearest: ok on disabled steps', function(assert) {
|
|
|
|
assert.plan(2);
|
|
|
|
var osrm = new OSRM({path: data_path, 'disable_feature_dataset': ['ROUTE_STEPS']});
|
|
|
|
var options = {
|
|
|
|
coordinates: [two_test_coordinates[0]],
|
|
|
|
};
|
|
|
|
osrm.nearest(options, function(err, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
assert.equal(response.waypoints.length, 1);
|
|
|
|
});
|
|
|
|
});
|