diff options
author | Wolfgang Bremer <wolfgang@w-bremer.de> | 2015-05-05 01:34:24 +0200 |
---|---|---|
committer | Wolfgang Bremer <wolfgang.bremer@pelagicore.com> | 2015-05-08 16:21:48 +0000 |
commit | 8275c4c933d0de20f1e784d5d5aeb78a8d20d80c (patch) | |
tree | 1ff52d121eba5279f903efeb4f52662e6cc2978d | |
parent | 3f697f6d73f0a7f10be90f48662f139a33d1781e (diff) |
Allow custom URLs for OSRM routing
This enables the usage of another routing server than the default
osrm project. The api still needs to be the same, but it is possible
to drive your own server using the OSRM project sources.
Change-Id: Ib335fdf97eb1e208caafb17783c22d9b423a40e2
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/location/doc/src/plugins/osm.qdoc | 7 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.cpp | 7 | ||||
-rw-r--r-- | src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.h | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc index 2d3a7a68..f10059d2 100644 --- a/src/location/doc/src/plugins/osm.qdoc +++ b/src/location/doc/src/plugins/osm.qdoc @@ -65,12 +65,18 @@ The following table lists optional parameters that can be passed to the Open Str \li mapping.copyright \li Custom copryright string is used when setting the \l{Map::activeMapType} to \l{MapType}.CustomMap via urlprefix parameter. This copyright will only be used when using the CustomMap from above. If empty no copyright will be displayed for the custom map. +\row + \li routing.host + \li Url string set when making network requests to the routing server. This parameter should be set to a + valid server url with the correct osrm api. If not specified the default \l {http://router.project-osrm.org/viaroute}{url} will be used. + \note The api documentation and sources are available at \l {http://project-osrm.org/}{Project OSRM}. \endtable \section1 Parameter Usage Example The following example shows how to create an OSM plugin instance with parameters supplied for an useragent, and if necessary, a custom server url plus the corresponding copyright information for the tile provider. +Additionally, it is possible to choose another routing server than the public osrm one. \section2 QML @@ -80,6 +86,7 @@ Plugin { PluginParameter { name: "useragent"; value: "My great Qt OSM application" } PluginParameter { name: "mapping.host"; value: "http://osm.tile.server.address/" } PluginParameter { name: "mapping.copyright"; value: "All mine" } + PluginParameter { name: "routing.host"; value: "http://osrm.server.address/viaroute" } } \endcode */ diff --git a/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.cpp b/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.cpp index 36913146..ab582434 100644 --- a/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.cpp +++ b/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.cpp @@ -48,6 +48,11 @@ QGeoRoutingManagerEngineOsm::QGeoRoutingManagerEngineOsm(const QVariantMap ¶ else m_userAgent = "Qt Location based application"; + if (parameters.contains(QStringLiteral("routing.host"))) + m_urlPrefix = parameters.value(QStringLiteral("routing.host")).toString().toLatin1(); + else + m_urlPrefix = QStringLiteral("http://router.project-osrm.org/viaroute"); + *error = QGeoServiceProvider::NoError; errorString->clear(); } @@ -61,7 +66,7 @@ QGeoRouteReply* QGeoRoutingManagerEngineOsm::calculateRoute(const QGeoRouteReque QNetworkRequest networkRequest; networkRequest.setRawHeader("User-Agent", m_userAgent); - QUrl url(QStringLiteral("http://router.project-osrm.org/viaroute")); + QUrl url(m_urlPrefix); QUrlQuery query; query.addQueryItem(QStringLiteral("instructions"), QStringLiteral("true")); diff --git a/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.h b/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.h index 793c8ace..618ef900 100644 --- a/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.h +++ b/src/plugins/geoservices/osm/qgeoroutingmanagerengineosm.h @@ -60,6 +60,7 @@ private Q_SLOTS: private: QNetworkAccessManager *m_networkManager; QByteArray m_userAgent; + QString m_urlPrefix; }; QT_END_NAMESPACE |