GetAnnotations function
This commit is contained in:
parent
734df348cb
commit
84261fd214
@ -79,6 +79,19 @@ class RouteAPI : public BaseAPI
|
||||
return json::makeGeoJSONGeometry(begin, end);
|
||||
}
|
||||
|
||||
template <typename GetFn>
|
||||
util::json::Array GetAnnotations(const guidance::LegGeometry &leg, GetFn Get) const
|
||||
{
|
||||
util::json::Array annotations_store;
|
||||
annotations_store.values.reserve(leg.annotations.size());
|
||||
std::for_each(leg.annotations.begin(),
|
||||
leg.annotations.end(),
|
||||
[Get, &annotations_store](const guidance::LegGeometry::Annotation &step) {
|
||||
annotations_store.values.push_back(Get(step));
|
||||
});
|
||||
return annotations_store;
|
||||
}
|
||||
|
||||
util::json::Object MakeRoute(const std::vector<PhantomNodes> &segment_end_coordinates,
|
||||
const std::vector<std::vector<PathData>> &unpacked_path_segments,
|
||||
const std::vector<bool> &source_traversed_in_reverse,
|
||||
@ -221,52 +234,35 @@ class RouteAPI : public BaseAPI
|
||||
{
|
||||
auto &leg_geometry = leg_geometries[idx];
|
||||
util::json::Object annotation;
|
||||
|
||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Duration)
|
||||
{
|
||||
util::json::Array durations;
|
||||
durations.values.reserve(leg_geometry.annotations.size());
|
||||
std::for_each(
|
||||
leg_geometry.annotations.begin(),
|
||||
leg_geometry.annotations.end(),
|
||||
[this, &durations](const guidance::LegGeometry::Annotation &step) {
|
||||
durations.values.push_back(step.duration);
|
||||
});
|
||||
annotation.values["duration"] = std::move(durations);
|
||||
annotation.values["duration"] =
|
||||
GetAnnotations(leg_geometry,
|
||||
std::bind(&guidance::LegGeometry::Annotation::duration,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Distance)
|
||||
{
|
||||
util::json::Array distances;
|
||||
distances.values.reserve(leg_geometry.annotations.size());
|
||||
std::for_each(
|
||||
leg_geometry.annotations.begin(),
|
||||
leg_geometry.annotations.end(),
|
||||
[this, &distances](const guidance::LegGeometry::Annotation &step) {
|
||||
distances.values.push_back(step.distance);
|
||||
});
|
||||
annotation.values["distance"] = std::move(distances);
|
||||
annotation.values["distance"] =
|
||||
GetAnnotations(leg_geometry,
|
||||
std::bind(&guidance::LegGeometry::Annotation::distance,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Weight)
|
||||
{
|
||||
util::json::Array weights;
|
||||
weights.values.reserve(leg_geometry.annotations.size());
|
||||
std::for_each(leg_geometry.annotations.begin(),
|
||||
leg_geometry.annotations.end(),
|
||||
[this, &weights](const guidance::LegGeometry::Annotation &step) {
|
||||
weights.values.push_back(step.weight);
|
||||
});
|
||||
annotation.values["weight"] = std::move(weights);
|
||||
annotation.values["weight"] =
|
||||
GetAnnotations(leg_geometry,
|
||||
std::bind(&guidance::LegGeometry::Annotation::weight,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Datasources)
|
||||
{
|
||||
util::json::Array datasources;
|
||||
datasources.values.reserve(leg_geometry.annotations.size());
|
||||
std::for_each(
|
||||
leg_geometry.annotations.begin(),
|
||||
leg_geometry.annotations.end(),
|
||||
[this, &datasources](const guidance::LegGeometry::Annotation &step) {
|
||||
datasources.values.push_back(step.datasource);
|
||||
});
|
||||
annotation.values["datasources"] = std::move(datasources);
|
||||
annotation.values["datasources"] =
|
||||
GetAnnotations(leg_geometry,
|
||||
std::bind(&guidance::LegGeometry::Annotation::datasource,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Nodes)
|
||||
{
|
||||
|
@ -72,9 +72,9 @@ struct RouteParameters : public BaseParameters
|
||||
None = 0,
|
||||
Duration = 0x01,
|
||||
Nodes = 0x02,
|
||||
Distance = 0x03,
|
||||
Weight = 0x04,
|
||||
Datasources = 0x05,
|
||||
Distance = 0x04,
|
||||
Weight = 0x08,
|
||||
Datasources = 0x10,
|
||||
All = Duration | Nodes | Distance | Weight | Datasources
|
||||
};
|
||||
|
||||
|
@ -67,7 +67,8 @@ BOOST_AUTO_TEST_CASE(invalid_route_urls)
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>(std::string{"1,2;3,"} + '\0'), 6);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations=distances"), 28UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations="), 20UL);
|
||||
BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>("1,2;3,4?annotations=&overview=simplified"), 20UL);
|
||||
BOOST_CHECK_EQUAL(
|
||||
testInvalidOptions<RouteParameters>("1,2;3,4?annotations=&overview=simplified"), 20UL);
|
||||
|
||||
// BOOST_CHECK_EQUAL(testInvalidOptions<RouteParameters>(), );
|
||||
}
|
||||
@ -346,9 +347,7 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
|
||||
"overview=simplified&annotations=duration");
|
||||
BOOST_CHECK(result_15);
|
||||
BOOST_CHECK_EQUAL(reference_15.geometries, result_15->geometries);
|
||||
BOOST_CHECK_EQUAL(
|
||||
static_cast<bool>(result_2->annotations_type & RouteParameters::AnnotationsType::Duration),
|
||||
true);
|
||||
BOOST_CHECK_EQUAL(result_15->annotations_type == RouteParameters::AnnotationsType::Duration, true);
|
||||
BOOST_CHECK_EQUAL(result_15->annotations, true);
|
||||
|
||||
// parse multiple annotations correctly
|
||||
@ -373,8 +372,8 @@ BOOST_AUTO_TEST_CASE(valid_route_urls)
|
||||
RouteParameters reference_17{};
|
||||
reference_17.annotations_type = RouteParameters::AnnotationsType::All;
|
||||
reference_17.coordinates = coords_1;
|
||||
auto result_17 =
|
||||
parseParameters<RouteParameters>("1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance");
|
||||
auto result_17 = parseParameters<RouteParameters>(
|
||||
"1,2;3,4?overview=simplified&annotations=duration,weight,nodes,datasources,distance");
|
||||
BOOST_CHECK(result_17);
|
||||
BOOST_CHECK_EQUAL(reference_17.geometries, result_17->geometries);
|
||||
BOOST_CHECK_EQUAL(
|
||||
|
Loading…
Reference in New Issue
Block a user