From 598b8a54ae79604387754c7d61a66958b7e470d1 Mon Sep 17 00:00:00 2001 From: Maciej Bukczynski Date: Mon, 21 Jun 2021 21:16:34 -0600 Subject: [PATCH 1/2] Add support node_osrm support for skip_waypoints parameter --- CHANGELOG.md | 3 +++ include/nodejs/node_osrm_support.hpp | 16 ++++++++++++++++ test/nodejs/table.js | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfa3c5dd568..a77e0018c15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Unreleased + - Changes from 5.25.0 + - Misc: + - FIXED: Support `skip_waypoints` in Node bindings [#6060](https://github.com/Project-OSRM/osrm-backend/pull/6060) # 5.25.0 - Changes from 5.24.0 diff --git a/include/nodejs/node_osrm_support.hpp b/include/nodejs/node_osrm_support.hpp index 400d420a52b..25f96661dfa 100644 --- a/include/nodejs/node_osrm_support.hpp +++ b/include/nodejs/node_osrm_support.hpp @@ -675,6 +675,22 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo &arg params->generate_hints = Nan::To(generate_hints).FromJust(); } + if (Nan::Has(obj, Nan::New("skip_waypoints").ToLocalChecked()).FromJust()) + { + v8::Local skip_waypoints = + Nan::Get(obj, Nan::New("skip_waypoints").ToLocalChecked()).ToLocalChecked(); + if (skip_waypoints.IsEmpty()) + return false; + + if (!skip_waypoints->IsBoolean()) + { + Nan::ThrowError("skip_waypoints must be of type Boolean"); + return false; + } + + params->skip_waypoints = Nan::To(skip_waypoints).FromJust(); + } + if (Nan::Has(obj, Nan::New("exclude").ToLocalChecked()).FromJust()) { v8::Local exclude = diff --git a/test/nodejs/table.js b/test/nodejs/table.js index f4f0e63123d..0df0c37c35d 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -190,6 +190,8 @@ tables.forEach(function(annotation) { assert.throws(function() { osrm.route({coordinates: two_test_coordinates, generate_hints: null}, function(err, route) {}) }, /generate_hints must be of type Boolean/); + assert.throws(function() { osrm.route({coordinates: two_test_coordinates, skip_waypoints: null}, function(err, route) {}) }, + /skip_waypoints must be of type Boolean/); }); test('table: throws on invalid arguments', function(assert) { @@ -239,6 +241,20 @@ tables.forEach(function(annotation) { }); }); + test('table: ' + annotation + ' table in Monaco without waypoints', function(assert) { + assert.plan(2); + var osrm = new OSRM(data_path); + var options = { + coordinates: two_test_coordinates, + skip_waypoints: true, // false is default + annotations: [annotation.slice(0,-1)] + }; + osrm.table(options, function(err, table) { + assert.strictEqual(table.sources, undefined); + assert.strictEqual(table.destinations, undefined); + }); + }); + test('table: ' + annotation + ' table in Monaco without motorways', function(assert) { assert.plan(2); var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); From 748a249dfb06fc8a42f916e9c21420420abd432a Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Mon, 22 Aug 2022 21:04:52 +0200 Subject: [PATCH 2/2] Update table.js --- test/nodejs/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nodejs/table.js b/test/nodejs/table.js index 0df0c37c35d..d2c50d83f2a 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -130,7 +130,7 @@ tables.forEach(function(annotation) { }); test('table: ' + annotation + ' throws on invalid arguments', function(assert) { - assert.plan(17); + assert.plan(18); var osrm = new OSRM(data_path); var options = {annotations: [annotation.slice(0,-1)]}; assert.throws(function() { osrm.table(options); },