Skip to content

Commit 0fc1aa2

Browse files
authored
Adds turn instructions to the turns layer in debug tiles. (#4460)
Add turn types and modifiers to turn points in debug tiles. Also refactor some of the tile code to reduce some repetition.
1 parent 89cf6d9 commit 0fc1aa2

File tree

9 files changed

+270
-150
lines changed

9 files changed

+270
-150
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
updating ETAs returned, without changing route selection (for example, in a distance-based profile with traffic data loaded).
1818
- Infrastructure:
1919
- New file `.osrm.cell_metrics` created by `osrm-customize`.
20+
- Debug tiles:
21+
- Added new properties `type` and `modifier` to `turns` layer, useful for viewing guidance calculated turn types on the map
2022

2123
# 5.11.0
2224
- Changes from 5.10:

docs/http.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ Vector tiles contain two layers:
437437
| `turn_angle` | `integer` | the angle of the turn, relative to the `bearing_in`. -180 to +180, 0 = straight ahead, 90 = 90-degrees to the right |
438438
| `cost` | `float` | the time we think it takes to make that turn, in seconds. May be negative, depending on how the data model is constructed (some turns get a "bonus"). |
439439
| `weight` | `float` | the weight we think it takes to make that turn. May be negative, depending on how the data model is constructed (some turns get a "bonus"). ACTUAL ROUTING USES THIS VALUE |
440+
| `type` | `string` | the type of this turn - values like `turn`, `continue`, etc. See the `StepManeuver` for a partial list, this field also exposes internal turn types that are never returned with an API response |
441+
| `modifier` | `string` | the direction modifier of the turn (`left`, `sharp left`, etc) |
440442

441443

442444
## Result objects

include/engine/api/json_factory.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ namespace detail
3636
std::string instructionTypeToString(extractor::guidance::TurnType::Enum type);
3737
std::string instructionModifierToString(extractor::guidance::DirectionModifier::Enum modifier);
3838

39+
/**
40+
* Returns a string representing all instruction types (including internal types that
41+
* are normally not exposed in route responses)
42+
*
43+
* @param type the TurnType value to convert into a string
44+
* @return a string representing the turn type (e.g. `turn` or `continue`)
45+
*/
46+
std::string internalInstructionTypeToString(extractor::guidance::TurnType::Enum type);
47+
3948
util::json::Array coordinateToLonLat(const util::Coordinate coordinate);
4049

4150
std::string modeToString(const extractor::TravelMode mode);

include/engine/routing_algorithms/tile_turns.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct TurnData final
2424
const int turn_angle;
2525
const EdgeWeight weight;
2626
const EdgeWeight duration;
27+
const extractor::guidance::TurnInstruction turn_instruction;
2728
};
2829

2930
using RTreeLeaf = datafacade::BaseDataFacade::RTreeLeaf;

src/engine/api/json_factory.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,47 @@ const constexpr char *modifier_names[] = {"uturn",
4141
"left",
4242
"sharp left"};
4343

44-
// translations of TurnTypes. Not all types are exposed to the outside world.
45-
// invalid types should never be returned as part of the API
46-
const constexpr char *turn_type_names[] = {
47-
"invalid", "new name", "continue", "turn", "merge",
48-
"on ramp", "off ramp", "fork", "end of road", "notification",
49-
"roundabout", "roundabout", "rotary", "rotary", "roundabout turn",
50-
"roundabout turn", "use lane", "invalid", "invalid", "invalid",
51-
"invalid", "invalid", "invalid", "invalid", "invalid",
52-
"invalid", "invalid"};
44+
/**
45+
* Human readable values for TurnType enum values
46+
*/
47+
struct TurnTypeName
48+
{
49+
// String value we return with our API
50+
const char *external_name;
51+
// Internal only string name for the turn type - useful for debugging
52+
// and used by debug tiles for visualizing hidden turn types
53+
const char *internal_name;
54+
};
55+
56+
// Indexes in this list correspond to the Enum values of osrm::extractor::guidance::TurnType
57+
const constexpr TurnTypeName turn_type_names[] = {
58+
{"invalid", "(not set)"},
59+
{"new name", "new name"},
60+
{"continue", "continue"},
61+
{"turn", "turn"},
62+
{"merge", "merge"},
63+
{"on ramp", "on ramp"},
64+
{"off ramp", "off ramp"},
65+
{"fork", "fork"},
66+
{"end of road", "end of road"},
67+
{"notification", "notification"},
68+
{"roundabout", "enter roundabout"},
69+
{"roundabout", "enter and exit roundabout"},
70+
{"rotary", "enter rotary"},
71+
{"rotary", "enter and exit rotary"},
72+
{"roundabout turn", "enter roundabout turn"},
73+
{"roundabout turn", "enter and exit roundabout turn"},
74+
{"use lane", "use lane"},
75+
{"invalid", "(noturn)"},
76+
{"invalid", "(suppressed)"},
77+
{"invalid", "(enter roundabout at exit)"},
78+
{"invalid", "(exit roundabout)"},
79+
{"invalid", "(enter rotary at exit)"},
80+
{"invalid", "(exit rotary)"},
81+
{"invalid", "(enter roundabout intersection at exit)"},
82+
{"invalid", "(exit roundabout intersection)"},
83+
{"invalid", "(stay on roundabout)"},
84+
{"invalid", "(sliproad)"}};
5385

5486
const constexpr char *waypoint_type_names[] = {"invalid", "arrive", "depart"};
5587

@@ -69,7 +101,14 @@ std::string instructionTypeToString(const TurnType::Enum type)
69101
{
70102
static_assert(sizeof(turn_type_names) / sizeof(turn_type_names[0]) >= TurnType::MaxTurnType,
71103
"Some turn types has not string representation.");
72-
return turn_type_names[static_cast<std::size_t>(type)];
104+
return turn_type_names[static_cast<std::size_t>(type)].external_name;
105+
}
106+
107+
std::string internalInstructionTypeToString(const TurnType::Enum type)
108+
{
109+
static_assert(sizeof(turn_type_names) / sizeof(turn_type_names[0]) >= TurnType::MaxTurnType,
110+
"Some turn types has not string representation.");
111+
return turn_type_names[static_cast<std::size_t>(type)].internal_name;
73112
}
74113

75114
util::json::Array lanesFromIntersection(const guidance::IntermediateIntersection &intersection)

0 commit comments

Comments
 (0)