diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-28 16:53:54 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-29 23:02:27 +0000 |
commit | fe821df2179d496a3ffc853076e9c62f96abde2a (patch) | |
tree | 649ce88bd270af2a74b47ae6e529fc0ecd6122e0 /src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp | |
parent | 057fe199941b8783312abeedde315118b59ccb8e (diff) | |
download | qtlocation-fe821df2179d496a3ffc853076e9c62f96abde2a.tar.gz |
Unify OSRM backends for OSM and Mapbox plugins
This patch unifies the OSRM backend in both the OSM and Mapbox plugins,
adding some extra functionalities to QGeoRouteParserOsrmV5 to handle
the extra osrm-text-instructions information coming from the Mapbox
servers.
It also adds a plugin parameter to let the user choose whether to
use the server's text instructions or the plugin-generated ones.
Change-Id: Id7ce73f4285e2e7db6872f40d72c0610847fce91
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp')
-rw-r--r-- | src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp index 1b7cc1b3..2697114d 100644 --- a/src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp +++ b/src/plugins/geoservices/mapbox/qgeoroutingmanagerenginemapbox.cpp @@ -41,6 +41,7 @@ #include "qgeoroutingmanagerenginemapbox.h" #include "qgeoroutereplymapbox.h" #include "qmapboxcommon.h" +#include "QtLocation/private/qgeorouteparserosrmv5_p.h" #include <QtCore/QUrlQuery> #include <QtCore/QDebug> @@ -62,6 +63,15 @@ QGeoRoutingManagerEngineMapbox::QGeoRoutingManagerEngineMapbox(const QVariantMap m_accessToken = parameters.value(QStringLiteral("mapbox.access_token")).toString(); } + bool use_mapbox_text_instructions = true; + if (parameters.contains(QStringLiteral("mapbox.routing.use_mapbox_text_instructions"))) { + use_mapbox_text_instructions = parameters.value(QStringLiteral("mapbox.use_mapbox_text_instructions")).toBool(); + } + + QGeoRouteParserOsrmV5 *parser = new QGeoRouteParserOsrmV5(this, use_mapbox_text_instructions); + parser->setAccessToken(m_accessToken); + m_routeParser = parser; + *error = QGeoServiceProvider::NoError; errorString->clear(); } @@ -73,7 +83,7 @@ QGeoRoutingManagerEngineMapbox::~QGeoRoutingManagerEngineMapbox() QGeoRouteReply* QGeoRoutingManagerEngineMapbox::calculateRoute(const QGeoRouteRequest &request) { QNetworkRequest networkRequest; - networkRequest.setRawHeader("User-Agent", m_userAgent); + networkRequest.setHeader(QNetworkRequest::UserAgentHeader, m_userAgent); QString url = mapboxDirectionsApiPath; @@ -94,24 +104,10 @@ QGeoRouteReply* QGeoRoutingManagerEngineMapbox::calculateRoute(const QGeoRouteRe } } - foreach (const QGeoCoordinate &c, request.waypoints()) { - url += QString("%1,%2;").arg(c.longitude()).arg(c.latitude()); - } - if (url.right(1) == QLatin1Char(';')) - url.chop(1); - - QUrlQuery query; - query.addQueryItem(QStringLiteral("steps"), QStringLiteral("true")); - query.addQueryItem(QStringLiteral("alternatives"), QStringLiteral("true")); - query.addQueryItem(QStringLiteral("overview"), QStringLiteral("full")); - query.addQueryItem(QStringLiteral("geometries"), QStringLiteral("geojson")); - query.addQueryItem(QStringLiteral("access_token"), m_accessToken); - - QUrl u(url); - u.setQuery(query); - networkRequest.setUrl(u); + networkRequest.setUrl(m_routeParser->requestUrl(request, url)); QNetworkReply *reply = m_networkManager->get(networkRequest); + QGeoRouteReplyMapbox *routeReply = new QGeoRouteReplyMapbox(reply, request, this); connect(routeReply, SIGNAL(finished()), this, SLOT(replyFinished())); @@ -121,6 +117,11 @@ QGeoRouteReply* QGeoRoutingManagerEngineMapbox::calculateRoute(const QGeoRouteRe return routeReply; } +const QGeoRouteParser *QGeoRoutingManagerEngineMapbox::routeParser() const +{ + return m_routeParser; +} + void QGeoRoutingManagerEngineMapbox::replyFinished() { QGeoRouteReply *reply = qobject_cast<QGeoRouteReply *>(sender()); |