diff --git a/include/engine/api/match_api.hpp b/include/engine/api/match_api.hpp index bc3c29cda..7329ab42a 100644 --- a/include/engine/api/match_api.hpp +++ b/include/engine/api/match_api.hpp @@ -87,9 +87,9 @@ class MatchAPI final : public RouteAPI 0u, static_cast(sub_matchings[sub_matching_index].indices.size()))) { // tidied_to_original: index of the input coordinate that a tidied coordinate - // corresponds to + // corresponds to. // sub_matching indices: index of the coordinate passed to map matching plugin that - // a matched node corresponds to + // a matched node corresponds to. trace_idx_to_matching_idx[tidy_result .tidied_to_original[sub_matchings[sub_matching_index] .indices[point_index]]] = @@ -115,17 +115,22 @@ class MatchAPI final : public RouteAPI sub_matchings[matching_index.sub_matching_index].nodes[matching_index.point_index]; auto waypoint = BaseAPI::MakeWaypoint(phantom); waypoint.values["matchings_index"] = matching_index.sub_matching_index; + waypoint.values["waypoint_index"] = matching_index.point_index; waypoint.values["alternatives_count"] = sub_matchings[matching_index.sub_matching_index] .alternatives_count[matching_index.point_index]; - if (tidy_result.was_waypoint[trace_index]) + // waypoint indices need to be adjusted if route legs were collapsed + if (!parameters.waypoints.empty()) { - waypoint.values["waypoint_index"] = was_waypoint_idx; - was_waypoint_idx++; - } - else - { - waypoint.values["waypoint_index"] = util::json::Null(); + if (tidy_result.was_waypoint[trace_index]) + { + waypoint.values["waypoint_index"] = was_waypoint_idx; + was_waypoint_idx++; + } + else + { + waypoint.values["waypoint_index"] = util::json::Null(); + } } waypoints.values.push_back(std::move(waypoint)); }