report depart/arrive in addition to waypoint
This commit is contained in:
parent
29cf9e05db
commit
c439594403
@ -36,8 +36,7 @@ class RouteAPI : public BaseAPI
|
||||
{
|
||||
}
|
||||
|
||||
void MakeResponse(const InternalRouteResult &raw_route,
|
||||
util::json::Object &response) const
|
||||
void MakeResponse(const InternalRouteResult &raw_route, util::json::Object &response) const
|
||||
{
|
||||
auto number_of_routes = raw_route.has_alternative() ? 2UL : 1UL;
|
||||
util::json::Array routes;
|
||||
@ -102,7 +101,6 @@ class RouteAPI : public BaseAPI
|
||||
leg.steps = guidance::assembleSteps(
|
||||
BaseAPI::facade, path_data, leg_geometry, phantoms.source_phantom,
|
||||
phantoms.target_phantom, reversed_source, reversed_target);
|
||||
;
|
||||
}
|
||||
|
||||
leg_geometries.push_back(std::move(leg_geometry));
|
||||
|
@ -25,6 +25,7 @@ namespace guidance
|
||||
namespace detail
|
||||
{
|
||||
StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instruction,
|
||||
const WaypointType waypoint_type,
|
||||
const LegGeometry &leg_geometry,
|
||||
const std::size_t segment_index,
|
||||
const unsigned exit);
|
||||
@ -71,8 +72,9 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
|
||||
{
|
||||
|
||||
StepManeuver maneuver = detail::stepManeuverFromGeometry(
|
||||
extractor::guidance::TurnInstruction{extractor::guidance::TurnType::Location,
|
||||
extractor::guidance::TurnInstruction{extractor::guidance::TurnType::NoTurn,
|
||||
initial_modifier},
|
||||
WaypointType::Depart,
|
||||
leg_geometry, segment_index, INVALID_EXIT_NR);
|
||||
|
||||
// PathData saves the information we need of the segment _before_ the turn,
|
||||
@ -90,7 +92,7 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
|
||||
path_point.travel_mode, maneuver, leg_geometry.FrontIndex(segment_index),
|
||||
leg_geometry.BackIndex(segment_index) + 1});
|
||||
maneuver = detail::stepManeuverFromGeometry(
|
||||
path_point.turn_instruction, leg_geometry, segment_index, path_point.exit);
|
||||
path_point.turn_instruction, WaypointType::None, leg_geometry, segment_index, path_point.exit);
|
||||
segment_index++;
|
||||
}
|
||||
}
|
||||
@ -109,7 +111,8 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
|
||||
// |-------| duration
|
||||
StepManeuver maneuver = {source_node.location, 0., 0.,
|
||||
extractor::guidance::TurnInstruction{
|
||||
extractor::guidance::TurnType::Location, initial_modifier},
|
||||
extractor::guidance::TurnType::NoTurn, initial_modifier},
|
||||
WaypointType::Depart,
|
||||
INVALID_EXIT_NR};
|
||||
|
||||
steps.push_back(RouteStep{source_node.name_id, facade.get_name_for_id(source_node.name_id),
|
||||
@ -131,8 +134,9 @@ std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
|
||||
steps.push_back(RouteStep{
|
||||
target_node.name_id, facade.get_name_for_id(target_node.name_id), 0., 0., target_mode,
|
||||
StepManeuver{target_node.location, 0., 0.,
|
||||
extractor::guidance::TurnInstruction{extractor::guidance::TurnType::Location,
|
||||
extractor::guidance::TurnInstruction{extractor::guidance::TurnType::NoTurn,
|
||||
final_modifier},
|
||||
WaypointType::Arrive,
|
||||
INVALID_EXIT_NR},
|
||||
leg_geometry.locations.size(), leg_geometry.locations.size()});
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "util/coordinate.hpp"
|
||||
#include "extractor/guidance/turn_instruction.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
@ -11,12 +13,20 @@ namespace engine
|
||||
namespace guidance
|
||||
{
|
||||
|
||||
enum class WaypointType : std::uint8_t
|
||||
{
|
||||
None,
|
||||
Arrive,
|
||||
Depart,
|
||||
};
|
||||
|
||||
struct StepManeuver
|
||||
{
|
||||
util::Coordinate location;
|
||||
double bearing_before;
|
||||
double bearing_after;
|
||||
extractor::guidance::TurnInstruction instruction;
|
||||
WaypointType waypoint_type;
|
||||
unsigned exit;
|
||||
};
|
||||
} // namespace guidance
|
||||
|
@ -37,8 +37,7 @@ enum DirectionModifier
|
||||
enum TurnType // at the moment we can support 32 turn types, without increasing memory consumption
|
||||
{
|
||||
Invalid, // no valid turn instruction
|
||||
NoTurn, // end of segment without turn
|
||||
Location, // start,end,via
|
||||
NoTurn, // end of segment without turn/middle of a segment
|
||||
Suppressed, // location that suppresses a turn
|
||||
NewName, // no turn, but name changes
|
||||
Continue, // remain on a street
|
||||
|
@ -28,36 +28,49 @@ namespace json
|
||||
namespace detail
|
||||
{
|
||||
|
||||
const constexpr char *modifier_names[] = {"uturn", "sharp right", "right", "slight right",
|
||||
"straight", "slight left", "left", "sharp left"};
|
||||
const constexpr char *modifier_names[] = {"uturn",
|
||||
"sharp right",
|
||||
"right",
|
||||
"slight right",
|
||||
"straight",
|
||||
"slight left",
|
||||
"left",
|
||||
"sharp left"};
|
||||
|
||||
// translations of TurnTypes. Not all types are exposed to the outside world.
|
||||
// invalid types should never be returned as part of the API
|
||||
const constexpr char *turn_type_names[] = {
|
||||
"invalid", "no turn", "waypoint", "invalid", "new name", "continue",
|
||||
"turn", "merge", "ramp", "fork", "end of road", "roundabout",
|
||||
"invalid", "roundabout", "invalid", "traffic circle", "invalid", "traffic circle",
|
||||
"invalid", "invalid", "restriction", "notification"};
|
||||
"invalid", "no turn", "invalid", "new name", "continue", "turn",
|
||||
"merge", "ramp", "fork", "end of road", "roundabout", "invalid",
|
||||
"roundabout", "invalid", "traffic circle", "invalid", "traffic circle", "invalid",
|
||||
"invalid", "restriction", "notification"};
|
||||
|
||||
const constexpr char *waypoint_type_names[] = {"invalid", "arrive", "depart"};
|
||||
|
||||
// Check whether to include a modifier in the result of the API
|
||||
inline bool isValidModifier(const TurnType type, const DirectionModifier modifier)
|
||||
inline bool isValidModifier(const guidance::StepManeuver maneuver)
|
||||
{
|
||||
if (type == TurnType::Location && modifier != DirectionModifier::Left &&
|
||||
modifier != DirectionModifier::Straight && modifier != DirectionModifier::Right)
|
||||
if (maneuver.waypoint_type != guidance::WaypointType::None &&
|
||||
maneuver.instruction.direction_modifier == DirectionModifier::UTurn)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string instructionTypeToString(TurnType type)
|
||||
std::string instructionTypeToString(const TurnType type)
|
||||
{
|
||||
return turn_type_names[static_cast<std::size_t>(type)];
|
||||
}
|
||||
|
||||
std::string instructionModifierToString(DirectionModifier modifier)
|
||||
std::string instructionModifierToString(const DirectionModifier modifier)
|
||||
{
|
||||
return modifier_names[static_cast<std::size_t>(modifier)];
|
||||
}
|
||||
|
||||
std::string waypointTypeToString(const guidance::WaypointType waypoint_type)
|
||||
{
|
||||
return waypoint_type_names[static_cast<std::size_t>(waypoint_type)];
|
||||
}
|
||||
|
||||
util::json::Array coordinateToLonLat(const util::Coordinate coordinate)
|
||||
{
|
||||
util::json::Array array;
|
||||
@ -123,8 +136,12 @@ std::string modeToString(const extractor::TravelMode mode)
|
||||
util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver)
|
||||
{
|
||||
util::json::Object step_maneuver;
|
||||
step_maneuver.values["type"] = detail::instructionTypeToString(maneuver.instruction.type);
|
||||
if (detail::isValidModifier(maneuver.instruction.type, maneuver.instruction.direction_modifier))
|
||||
if (maneuver.waypoint_type == guidance::WaypointType::None)
|
||||
step_maneuver.values["type"] = detail::instructionTypeToString(maneuver.instruction.type);
|
||||
else
|
||||
step_maneuver.values["type"] = detail::waypointTypeToString(maneuver.waypoint_type);
|
||||
|
||||
if (detail::isValidModifier(maneuver))
|
||||
step_maneuver.values["modifier"] =
|
||||
detail::instructionModifierToString(maneuver.instruction.direction_modifier);
|
||||
step_maneuver.values["location"] = detail::coordinateToLonLat(maneuver.location);
|
||||
@ -199,7 +216,6 @@ util::json::Array makeRouteLegs(std::vector<guidance::RouteLeg> legs,
|
||||
});
|
||||
json_legs.values.push_back(makeRouteLeg(std::move(leg), std::move(json_steps)));
|
||||
}
|
||||
|
||||
return json_legs;
|
||||
}
|
||||
} // namespace json
|
||||
|
@ -13,6 +13,7 @@ namespace guidance
|
||||
namespace detail
|
||||
{
|
||||
StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instruction,
|
||||
const WaypointType waypoint_type,
|
||||
const LegGeometry &leg_geometry,
|
||||
const std::size_t segment_index,
|
||||
const unsigned exit)
|
||||
@ -31,7 +32,7 @@ StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instr
|
||||
const double post_turn_bearing =
|
||||
util::coordinate_calculation::bearing(turn_coordinate, post_turn_coordinate);
|
||||
|
||||
return StepManeuver{turn_coordinate, pre_turn_bearing, post_turn_bearing, instruction, exit};
|
||||
return StepManeuver{turn_coordinate, pre_turn_bearing, post_turn_bearing, instruction, waypoint_type, exit};
|
||||
}
|
||||
} // ns detail
|
||||
} // ns engine
|
||||
|
Loading…
Reference in New Issue
Block a user