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