summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-03-29 13:49:59 +0300
committerBruno de Oliveira Abinader <brunoabinader@gmail.com>2018-04-09 09:18:17 +0000
commit730932ab648e4d455b4bc84fb05f9a78ce1576be (patch)
treed7aa3b65941371755cd656661a5915230cdc9c4a
parent98878f5a25578c66b001c27817bffac6e0f82d20 (diff)
downloadqtlocation-730932ab648e4d455b4bc84fb05f9a78ce1576be.tar.gz
Add OSRM's {leg,step}_index extra attribute to QGeoManeuver
Change-Id: I3f6fd2e29a9689baa9db3efbbcc17242925484db Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
-rw-r--r--src/location/maps/qgeorouteparserosrmv5.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/location/maps/qgeorouteparserosrmv5.cpp b/src/location/maps/qgeorouteparserosrmv5.cpp
index 2167a4e8..7cd29f92 100644
--- a/src/location/maps/qgeorouteparserosrmv5.cpp
+++ b/src/location/maps/qgeorouteparserosrmv5.cpp
@@ -793,7 +793,7 @@ static QGeoManeuver::InstructionDirection instructionDirection(const QJsonObject
return QGeoManeuver::NoDirection;
}
-static QGeoRouteSegment parseStep(const QJsonObject &step, bool useServerText) {
+static QGeoRouteSegment parseStep(const QJsonObject &step, bool useServerText, int legIndex, int stepIndex) {
// OSRM Instructions documentation: https://github.com/Project-OSRM/osrm-text-instructions
// This goes on top of OSRM: https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md
// Mapbox however, includes this in the reply, under "instruction".
@@ -846,6 +846,10 @@ static QGeoRouteSegment parseStep(const QJsonObject &step, bool useServerText) {
if (maneuver.find(e) != maneuver.end())
extraAttributes.insert(e, maneuver.value(e).toVariant());
}
+ // These should be removed as soon as route leg support is introduced.
+ // Ref: http://project-osrm.org/docs/v5.15.2/api/#routeleg-object
+ extraAttributes.insert(QLatin1String("leg_index"), legIndex);
+ extraAttributes.insert(QLatin1String("step_index"), stepIndex);
geoManeuver.setExtendedAttributes(extraAttributes);
segment.setDistance(distance);
@@ -912,7 +916,8 @@ QGeoRouteReply::Error QGeoRouteParserOsrmV5Private::parseReply(QList<QGeoRoute>
QList<QGeoRouteSegment> segments;
QJsonArray legs = route.value(QLatin1String("legs")).toArray();
- foreach (const QJsonValue &l, legs) {
+ for (int legIndex = 0; legIndex < legs.size(); ++legIndex) {
+ const QJsonValue &l = legs.at(legIndex);
if (!l.isObject()) { // invalid leg record
error = true;
break;
@@ -923,12 +928,13 @@ QGeoRouteReply::Error QGeoRouteParserOsrmV5Private::parseReply(QList<QGeoRoute>
break;
}
QJsonArray steps = leg.value(QLatin1String("steps")).toArray();
- foreach (const QJsonValue &s, steps) {
+ for (int stepIndex = 0; stepIndex < steps.size(); ++stepIndex) {
+ const QJsonValue &s = steps.at(stepIndex);
if (!s.isObject()) {
error = true;
break;
}
- QGeoRouteSegment segment = parseStep(s.toObject(), m_useServerText);
+ QGeoRouteSegment segment = parseStep(s.toObject(), m_useServerText, legIndex, stepIndex);
if (segment.isValid()) {
segments.append(segment);
} else {