Skip to content

Commit 70401fd

Browse files
SiarheiFedartsoumattwigway
authored andcommitted
Fix annotations=true handling in NodeJS bindings & libosrm (Project-OSRM#6415)
1 parent 828f6f4 commit 70401fd

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22
- Changes from 5.27.1
33
- Misc:
4+
- FIXED: Fix annotations=true handling in NodeJS bindings & libosrm. [#6415](https://github.com/Project-OSRM/osrm-backend/pull/6415/)
45
- FIXED: Fix bindings compilation issue on the latest Node. Update NAN to 2.17.0. [#6416](https://github.com/Project-OSRM/osrm-backend/pull/6416)
56
# 5.27.1
67
- Changes from 5.27.0

Diff for: include/engine/api/route_api.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class RouteAPI : public BaseAPI
439439
{
440440
// AnnotationsType uses bit flags, & operator checks if a property is set
441441
flatbuffers::Offset<flatbuffers::Vector<float>> speed;
442-
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
442+
if (requested_annotations & RouteParameters::AnnotationsType::Speed)
443443
{
444444
double prev_speed = 0;
445445
speed =
@@ -778,7 +778,7 @@ class RouteAPI : public BaseAPI
778778
util::json::Object annotation;
779779

780780
// AnnotationsType uses bit flags, & operator checks if a property is set
781-
if (parameters.annotations_type & RouteParameters::AnnotationsType::Speed)
781+
if (requested_annotations & RouteParameters::AnnotationsType::Speed)
782782
{
783783
double prev_speed = 0;
784784
annotation.values["speed"] = GetAnnotations(

Diff for: include/nodejs/node_osrm_support.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,9 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
799799
if (annotations->IsBoolean())
800800
{
801801
params->annotations = Nan::To<bool>(annotations).FromJust();
802+
params->annotations_type = params->annotations
803+
? osrm::RouteParameters::AnnotationsType::All
804+
: osrm::RouteParameters::AnnotationsType::None;
802805
}
803806
else if (annotations->IsArray())
804807
{
@@ -845,6 +848,9 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
845848
Nan::ThrowError("this 'annotations' param is not supported");
846849
return false;
847850
}
851+
852+
params->annotations =
853+
params->annotations_type != osrm::RouteParameters::AnnotationsType::None;
848854
}
849855
}
850856
else

Diff for: test/nodejs/route.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ test('route: routes Monaco with several (duration, distance, nodes) annotations
286286
assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance');
287287
assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations');
288288
assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes');
289-
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight')
290-
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources')
291-
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'has no annotations for speed')
289+
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'has no annotations for weight');
290+
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'has no annotations for datasources');
291+
assert.notOk(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'has no annotations for speed');
292292

293293
options.overview = 'full';
294294
osrm.route(options, function(err, full) {
@@ -303,7 +303,7 @@ test('route: routes Monaco with several (duration, distance, nodes) annotations
303303
});
304304

305305
test('route: routes Monaco with options', function(assert) {
306-
assert.plan(11);
306+
assert.plan(17);
307307
var osrm = new OSRM(monaco_path);
308308
var options = {
309309
coordinates: two_test_coordinates,
@@ -322,6 +322,12 @@ test('route: routes Monaco with options', function(assert) {
322322
assert.ok(first.routes[0].legs[0]);
323323
assert.ok(first.routes[0].legs.every(l => { return l.steps.length > 0; }), 'every leg has steps');
324324
assert.ok(first.routes[0].legs.every(l => { return l.annotation;}), 'every leg has annotations');
325+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.distance;}), 'every leg has annotations for distance');
326+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.duration;}), 'every leg has annotations for durations');
327+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.nodes;}), 'every leg has annotations for nodes');
328+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.weight; }), 'every leg has annotations for weight');
329+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.datasources; }), 'every leg has annotations for datasources');
330+
assert.ok(first.routes[0].legs.every(l => { return l.annotation.speed; }), 'every leg has annotations for speed');
325331

326332
options.overview = 'full';
327333
osrm.route(options, function(err, full) {

Diff for: unit_tests/library/route.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ void test_manual_setting_of_annotations_property(bool use_json_only_api)
584584
.values["annotation"]
585585
.get<json::Object>()
586586
.values;
587-
BOOST_CHECK_EQUAL(annotations.size(), 6);
587+
BOOST_CHECK_EQUAL(annotations.size(), 7);
588588
}
589589
BOOST_AUTO_TEST_CASE(test_manual_setting_of_annotations_property_old_api)
590590
{

0 commit comments

Comments
 (0)