diff --git a/include/engine/algorithm.hpp b/include/engine/algorithm.hpp index 8f48b3730..760f78e80 100644 --- a/include/engine/algorithm.hpp +++ b/include/engine/algorithm.hpp @@ -50,6 +50,9 @@ template struct HasMapMatching final : std::false_type template struct HasManyToManySearch final : std::false_type { }; +template struct SupportsDistanceAnnotationType final : std::false_type +{ +}; template struct HasGetTileTurns final : std::false_type { }; @@ -73,6 +76,9 @@ template <> struct HasMapMatching final : std::true_type template <> struct HasManyToManySearch final : std::true_type { }; +template <> struct SupportsDistanceAnnotationType final : std::true_type +{ +}; template <> struct HasGetTileTurns final : std::true_type { }; @@ -96,6 +102,9 @@ template <> struct HasMapMatching final : std::true_type template <> struct HasManyToManySearch final : std::true_type { }; +template <> struct SupportsDistanceAnnotationType final : std::false_type +{ +}; template <> struct HasGetTileTurns final : std::true_type { }; diff --git a/include/engine/routing_algorithms.hpp b/include/engine/routing_algorithms.hpp index b2a3d9a3f..aec19f753 100644 --- a/include/engine/routing_algorithms.hpp +++ b/include/engine/routing_algorithms.hpp @@ -55,6 +55,7 @@ class RoutingAlgorithmsInterface virtual bool HasDirectShortestPathSearch() const = 0; virtual bool HasMapMatching() const = 0; virtual bool HasManyToManySearch() const = 0; + virtual bool SupportsDistanceAnnotationType() const = 0; virtual bool HasGetTileTurns() const = 0; virtual bool HasExcludeFlags() const = 0; virtual bool IsValid() const = 0; @@ -128,6 +129,11 @@ template class RoutingAlgorithms final : public RoutingAlgo return routing_algorithms::HasManyToManySearch::value; } + bool SupportsDistanceAnnotationType() const final override + { + return routing_algorithms::SupportsDistanceAnnotationType::value; + } + bool HasGetTileTurns() const final override { return routing_algorithms::HasGetTileTurns::value; diff --git a/src/engine/plugins/table.cpp b/src/engine/plugins/table.cpp index e10b5461a..72c43ef7d 100644 --- a/src/engine/plugins/table.cpp +++ b/src/engine/plugins/table.cpp @@ -85,6 +85,13 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms, bool request_distance = params.annotations & api::TableParameters::AnnotationsType::Distance; bool request_duration = params.annotations & api::TableParameters::AnnotationsType::Duration; + if (request_distance && !algorithms.SupportsDistanceAnnotationType()) + { + return Error("NotImplemented", + "The distance annotations calculation is not implemented for the chosen search algorithm.", + result); + } + auto result_tables_pair = algorithms.ManyToManySearch( snapped_phantoms, params.sources, params.destinations, request_distance, request_duration); diff --git a/test/nodejs/table.js b/test/nodejs/table.js index 28164f99c..b053443a7 100644 --- a/test/nodejs/table.js +++ b/test/nodejs/table.js @@ -185,7 +185,6 @@ tables.forEach(function(annotation) { annotations: [annotation.slice(0,-1)] }; osrm.table(options, function(err, table) { - console.log(table); assert.ifError(err); function assertHasHints(waypoint) { @@ -218,7 +217,7 @@ tables.forEach(function(annotation) { }); test('table: ' + annotation + ' table in Monaco without motorways', function(assert) { - assert.plan(2); + assert.plan(1); var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'}); var options = { coordinates: two_test_coordinates, @@ -226,8 +225,8 @@ tables.forEach(function(annotation) { annotations: [annotation.slice(0,-1)] }; osrm.table(options, function(err, response) { - assert.ifError(err); - assert.equal(response[annotation].length, 2); + if (annotation === 'durations') assert.equal(response[annotation].length, 2); + else assert.error(response, 'NotImplemented'); }); }); });