Really place annotations in RouteLeg and not Route
This commit is contained in:
parent
451a0d9090
commit
d6de2ca71c
@ -7,6 +7,7 @@
|
||||
|
||||
- API:
|
||||
- paramater `annotate` was renamed to `annotations`.
|
||||
- `annotation` as accidentally placed in `Route` instead of `RouteLeg`
|
||||
|
||||
# 5.2.0 RC1
|
||||
Changes from 5.1.0
|
||||
|
@ -1,3 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var Timeout = require('node-timeout');
|
||||
var request = require('request');
|
||||
|
||||
@ -141,14 +143,16 @@ module.exports = function () {
|
||||
return this.extractInstructionList(instructions, s => s.maneuver.bearing_before + '->' + s.maneuver.bearing_after);
|
||||
};
|
||||
|
||||
this.annotationList = (instructions) => {
|
||||
// Pull out all the distinct segment distances, skipping the arrive
|
||||
// instructions, and the leading 0 on all timestamps arrays.
|
||||
var pairs = [];
|
||||
for (var i in instructions.annotation.duration) {
|
||||
pairs.push(instructions.annotation.duration[i]+':'+instructions.annotation.distance[i]);
|
||||
this.annotationList = (matching) => {
|
||||
function zip(list_1, list_2)
|
||||
{
|
||||
let pairs = [];
|
||||
for (let i = 0; i < list_1.length; ++i) {
|
||||
pairs.push([list_1[i], list_2[i]]);
|
||||
}
|
||||
return pairs.join(',');
|
||||
return pairs;
|
||||
}
|
||||
return matching.legs.map(l => {return zip(l.annotation.duration, l.annotation.distance).map(p => { return p.join(':'); }).join(','); }).join(',');
|
||||
};
|
||||
|
||||
this.turnList = (instructions) => {
|
||||
|
@ -85,7 +85,8 @@ makeWaypoint(const util::Coordinate location, std::string name, const Hint &hint
|
||||
util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps);
|
||||
|
||||
util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
|
||||
std::vector<util::json::Value> step_geometries);
|
||||
std::vector<util::json::Value> step_geometries,
|
||||
std::vector<util::json::Object> annotations);
|
||||
}
|
||||
}
|
||||
} // namespace engine
|
||||
|
@ -176,16 +176,14 @@ class RouteAPI : public BaseAPI
|
||||
});
|
||||
}
|
||||
|
||||
auto result = json::makeRoute(route,
|
||||
json::makeRouteLegs(std::move(legs), std::move(step_geometries)),
|
||||
std::move(json_overview));
|
||||
std::vector<util::json::Object> annotations;
|
||||
|
||||
if (parameters.annotations)
|
||||
{
|
||||
util::json::Array durations;
|
||||
util::json::Array distances;
|
||||
for (const auto idx : util::irange<std::size_t>(0UL, leg_geometries.size()))
|
||||
{
|
||||
util::json::Array durations;
|
||||
util::json::Array distances;
|
||||
auto &leg_geometry = leg_geometries[idx];
|
||||
std::for_each(leg_geometry.annotations.begin(),
|
||||
leg_geometry.annotations.end(),
|
||||
@ -193,15 +191,18 @@ class RouteAPI : public BaseAPI
|
||||
durations.values.push_back(step.duration);
|
||||
distances.values.push_back(step.distance);
|
||||
});
|
||||
util::json::Object annotation;
|
||||
annotation.values["distance"] = std::move(distances);
|
||||
annotation.values["duration"] = std::move(durations);
|
||||
annotations.push_back(std::move(annotation));
|
||||
}
|
||||
|
||||
util::json::Object details;
|
||||
details.values["distance"] = std::move(distances);
|
||||
details.values["duration"] = std::move(durations);
|
||||
|
||||
result.values["annotation"] = std::move(details);
|
||||
}
|
||||
|
||||
auto result = json::makeRoute(route,
|
||||
json::makeRouteLegs(std::move(legs), std::move(step_geometries), std::move(annotations)),
|
||||
std::move(json_overview));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -237,8 +237,16 @@ util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps)
|
||||
return route_leg;
|
||||
}
|
||||
|
||||
util::json::Object makeRouteLeg(guidance::RouteLeg leg, util::json::Array steps, util::json::Object annotation)
|
||||
{
|
||||
util::json::Object route_leg = makeRouteLeg(std::move(leg), std::move(steps));
|
||||
route_leg.values["annotation"] = std::move(annotation);
|
||||
return route_leg;
|
||||
}
|
||||
|
||||
util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
|
||||
std::vector<util::json::Value> step_geometries)
|
||||
std::vector<util::json::Value> step_geometries,
|
||||
std::vector<util::json::Object> annotations)
|
||||
{
|
||||
util::json::Array json_legs;
|
||||
auto step_geometry_iter = step_geometries.begin();
|
||||
@ -252,8 +260,15 @@ util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
|
||||
std::back_inserter(json_steps.values), [&step_geometry_iter](guidance::RouteStep step) {
|
||||
return makeRouteStep(std::move(step), std::move(*step_geometry_iter++));
|
||||
});
|
||||
if (annotations.size() > 0)
|
||||
{
|
||||
json_legs.values.push_back(makeRouteLeg(std::move(leg), std::move(json_steps), annotations[idx]));
|
||||
}
|
||||
else
|
||||
{
|
||||
json_legs.values.push_back(makeRouteLeg(std::move(leg), std::move(json_steps)));
|
||||
}
|
||||
}
|
||||
return json_legs;
|
||||
}
|
||||
} // namespace json
|
||||
|
Loading…
Reference in New Issue
Block a user