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