diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2014-10-21 14:18:13 -0400 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-01-09 09:00:35 +0100 |
commit | 3a48d5bf848ccd2b59eb4abbb3ee240bd688321c (patch) | |
tree | 78aa021e415daadd8247cfd6820639ddb0cc8a21 /src/plugins/geoservices/mapbox | |
parent | 9735cab006350ef9cb9a3f9b32b4829350bd1c6e (diff) | |
download | qtlocation-3a48d5bf848ccd2b59eb4abbb3ee240bd688321c.tar.gz |
Add Mapbox plugin.
Allow Mapbox (https://www.mapbox.com) maps to be used. This requires the user to
set the mapbox.map_id and mapbox.access_token parameters for the Map object.
Change-Id: I3095df260dd0c9d49d84d45385c5a530fcffee0b
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/plugins/geoservices/mapbox')
10 files changed, 665 insertions, 0 deletions
diff --git a/src/plugins/geoservices/mapbox/mapbox.pro b/src/plugins/geoservices/mapbox/mapbox.pro new file mode 100644 index 00000000..7fdfa508 --- /dev/null +++ b/src/plugins/geoservices/mapbox/mapbox.pro @@ -0,0 +1,22 @@ +TARGET = qtgeoservices_mapbox +QT += location-private positioning-private network + +PLUGIN_TYPE = geoservices +PLUGIN_CLASS_NAME = QGeoServiceProviderFactoryMapbox +load(qt_plugin) + +HEADERS += \ + qgeoserviceproviderpluginmapbox.h \ + qgeotiledmappingmanagerenginemapbox.h \ + qgeotilefetchermapbox.h \ + qgeomapreplymapbox.h + +SOURCES += \ + qgeoserviceproviderpluginmapbox.cpp \ + qgeotiledmappingmanagerenginemapbox.cpp \ + qgeotilefetchermapbox.cpp \ + qgeomapreplymapbox.cpp + +OTHER_FILES += \ + mapbox_plugin.json + diff --git a/src/plugins/geoservices/mapbox/mapbox_plugin.json b/src/plugins/geoservices/mapbox/mapbox_plugin.json new file mode 100644 index 00000000..0b8d08af --- /dev/null +++ b/src/plugins/geoservices/mapbox/mapbox_plugin.json @@ -0,0 +1,9 @@ +{ + "Keys": ["mapbox"], + "Provider": "mapbox", + "Version": 100, + "Experimental": false, + "Features": [ + "OnlineMappingFeature" + ] +} diff --git a/src/plugins/geoservices/mapbox/qgeomapreplymapbox.cpp b/src/plugins/geoservices/mapbox/qgeomapreplymapbox.cpp new file mode 100644 index 00000000..7f080724 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeomapreplymapbox.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeomapreplymapbox.h" + +#include <QtLocation/private/qgeotilespec_p.h> + +QGeoMapReplyMapbox::QGeoMapReplyMapbox(QNetworkReply *reply, const QGeoTileSpec &spec, const QString &format, QObject *parent) +: QGeoTiledMapReply(spec, parent), m_reply(reply), m_format (format) +{ + connect(m_reply, SIGNAL(finished()), this, SLOT(networkReplyFinished())); + connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), + this, SLOT(networkReplyError(QNetworkReply::NetworkError))); + connect(m_reply, SIGNAL(destroyed()), this, SLOT(replyDestroyed())); +} + +QGeoMapReplyMapbox::~QGeoMapReplyMapbox() +{ + if (m_reply) { + m_reply->deleteLater(); + m_reply = 0; + } +} + +void QGeoMapReplyMapbox::abort() +{ + if (!m_reply) + return; + + m_reply->abort(); +} + +QNetworkReply *QGeoMapReplyMapbox::networkReply() const +{ + return m_reply; +} + +void QGeoMapReplyMapbox::replyDestroyed() +{ + m_reply = 0; +} + +void QGeoMapReplyMapbox::networkReplyFinished() +{ + if (!m_reply) + return; + + if (m_reply->error() != QNetworkReply::NoError) + return; + + setMapImageData(m_reply->readAll()); + setMapImageFormat(m_format); + setFinished(true); + + m_reply->deleteLater(); + m_reply = 0; +} + +void QGeoMapReplyMapbox::networkReplyError(QNetworkReply::NetworkError error) +{ + if (!m_reply) + return; + + if (error != QNetworkReply::OperationCanceledError) + setError(QGeoTiledMapReply::CommunicationError, m_reply->errorString()); + + setFinished(true); + m_reply->deleteLater(); + m_reply = 0; +} diff --git a/src/plugins/geoservices/mapbox/qgeomapreplymapbox.h b/src/plugins/geoservices/mapbox/qgeomapreplymapbox.h new file mode 100644 index 00000000..ca4ec687 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeomapreplymapbox.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOMAPREPLYMAPBOX_H +#define QGEOMAPREPLYMAPBOX_H + +#include <QtNetwork/QNetworkReply> +#include <QtLocation/private/qgeotiledmapreply_p.h> + +QT_BEGIN_NAMESPACE + +class QGeoMapReplyMapbox : public QGeoTiledMapReply +{ + Q_OBJECT + +public: + explicit QGeoMapReplyMapbox(QNetworkReply *reply, const QGeoTileSpec &spec, const QString &format, QObject *parent = 0); + ~QGeoMapReplyMapbox(); + + void abort(); + + QNetworkReply *networkReply() const; + +private Q_SLOTS: + void replyDestroyed(); + void networkReplyFinished(); + void networkReplyError(QNetworkReply::NetworkError error); + +private: + QNetworkReply *m_reply; + QString m_format; +}; + +QT_END_NAMESPACE + +#endif // QGEOMAPREPLYMAPBOX_H diff --git a/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp new file mode 100644 index 00000000..08adb46d --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeoserviceproviderpluginmapbox.h" +#include "qgeotiledmappingmanagerenginemapbox.h" + +#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h> + +QT_BEGIN_NAMESPACE + +QGeoCodingManagerEngine *QGeoServiceProviderFactoryMapbox::createGeocodingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + +QGeoMappingManagerEngine *QGeoServiceProviderFactoryMapbox::createMappingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + const QString mapId = parameters.value(QStringLiteral("mapbox.map_id")).toString(); + const QString accessToken = parameters.value(QStringLiteral("mapbox.access_token")).toString(); + + if (!mapId.isEmpty() && !accessToken.isEmpty()) { + return new QGeoTiledMappingManagerEngineMapbox(parameters, error, errorString); + } else { + *error = QGeoServiceProvider::MissingRequiredParameterError; + *errorString = tr("Mapbox plugin requires 'mapbox.map_id' and 'mapbox.access_token' parameters.\n" + "Please visit https://www.mapbox.com"); + return 0; + } +} + +QGeoRoutingManagerEngine *QGeoServiceProviderFactoryMapbox::createRoutingManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + +QPlaceManagerEngine *QGeoServiceProviderFactoryMapbox::createPlaceManagerEngine( + const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + +QT_END_NAMESPACE diff --git a/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.h b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.h new file mode 100644 index 00000000..ca32d1c9 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeoserviceproviderpluginmapbox.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSERVICEPROVIDER_MAPBOX_H +#define QGEOSERVICEPROVIDER_MAPBOX_H + +#include <QtCore/QObject> +#include <QtLocation/QGeoServiceProviderFactory> + +QT_BEGIN_NAMESPACE + +class QGeoServiceProviderFactoryMapbox: public QObject, public QGeoServiceProviderFactory +{ + Q_OBJECT + Q_INTERFACES(QGeoServiceProviderFactory) + Q_PLUGIN_METADATA(IID "org.qt-project.qt.geoservice.serviceproviderfactory/5.0" + FILE "mapbox_plugin.json") + +public: + QGeoCodingManagerEngine *createGeocodingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoMappingManagerEngine *createMappingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QGeoRoutingManagerEngine *createRoutingManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; + QPlaceManagerEngine *createPlaceManagerEngine(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp new file mode 100644 index 00000000..b944f644 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeotiledmappingmanagerenginemapbox.h" +#include "qgeotilefetchermapbox.h" + +#include <QtLocation/private/qgeocameracapabilities_p.h> +#include <QtLocation/private/qgeomaptype_p.h> +#include <QtLocation/private/qgeotiledmapdata_p.h> + +QT_BEGIN_NAMESPACE + +QGeoTiledMappingManagerEngineMapbox::QGeoTiledMappingManagerEngineMapbox(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString) +: QGeoTiledMappingManagerEngine() +{ + QGeoCameraCapabilities cameraCaps; + cameraCaps.setMinimumZoomLevel(0.0); + cameraCaps.setMaximumZoomLevel(19.0); + setCameraCapabilities(cameraCaps); + + setTileSize(QSize(256, 256)); + + QList<QGeoMapType> mapTypes; + mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("Custom"), tr("Mapbox custom map"), false, false, 0); + setSupportedMapTypes(mapTypes); + + QGeoTileFetcherMapbox *tileFetcher = new QGeoTileFetcherMapbox(this); + if (parameters.contains(QStringLiteral("useragent"))) { + const QByteArray ua = parameters.value(QStringLiteral("useragent")).toString().toLatin1(); + tileFetcher->setUserAgent(ua); + } + if (parameters.contains(QStringLiteral("mapbox.map_id"))) { + const QString id = parameters.value(QStringLiteral("mapbox.map_id")).toString(); + tileFetcher->setMapId(id); + } + if (parameters.contains(QStringLiteral("mapbox.format"))) { + const QString format = parameters.value(QStringLiteral("mapbox.format")).toString(); + tileFetcher->setFormat(format); + } + if (parameters.contains(QStringLiteral("mapbox.access_token"))) { + const QString token = parameters.value(QStringLiteral("mapbox.access_token")).toString(); + tileFetcher->setAccessToken(token); + } + + setTileFetcher(tileFetcher); + + *error = QGeoServiceProvider::NoError; + errorString->clear(); +} + +QGeoTiledMappingManagerEngineMapbox::~QGeoTiledMappingManagerEngineMapbox() +{ +} + +QGeoMapData *QGeoTiledMappingManagerEngineMapbox::createMapData() +{ + return new QGeoTiledMapData(this, 0); +} + +QT_END_NAMESPACE diff --git a/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.h b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.h new file mode 100644 index 00000000..0d0f7ff7 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeotiledmappingmanagerenginemapbox.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOTILEDMAPPINGMANAGERENGINEMAPBOX_H +#define QGEOTILEDMAPPINGMANAGERENGINEMAPBOX_H + +#include <QtLocation/QGeoServiceProvider> + +#include <QtLocation/private/qgeotiledmappingmanagerengine_p.h> + +QT_BEGIN_NAMESPACE + +class QGeoTiledMappingManagerEngineMapbox : public QGeoTiledMappingManagerEngine +{ + Q_OBJECT + +public: + QGeoTiledMappingManagerEngineMapbox(const QVariantMap ¶meters, + QGeoServiceProvider::Error *error, QString *errorString); + ~QGeoTiledMappingManagerEngineMapbox(); + + QGeoMapData *createMapData(); +}; + +QT_END_NAMESPACE + +#endif // QGEOTILEDMAPPINGMANAGERENGINEMAPBOX_H diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp new file mode 100644 index 00000000..109b6f41 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeotilefetchermapbox.h" +#include "qgeomapreplymapbox.h" + +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkRequest> +#include <QtLocation/private/qgeotilespec_p.h> +#include <QDebug> + +QT_BEGIN_NAMESPACE + +QGeoTileFetcherMapbox::QGeoTileFetcherMapbox(QObject *parent) +: QGeoTileFetcher(parent), m_networkManager(new QNetworkAccessManager(this)), + m_userAgent("Qt Location based application"), + m_mapId(""), + m_format("png"), + m_replyFormat("png"), + m_accessToken("") +{ +} + +void QGeoTileFetcherMapbox::setUserAgent(const QByteArray &userAgent) +{ + m_userAgent = userAgent; +} + +void QGeoTileFetcherMapbox::setMapId(const QString &mapId) +{ + m_mapId = mapId; +} + +void QGeoTileFetcherMapbox::setFormat(const QString &format) +{ + m_format = format; + + if (m_format == "png" || m_format == "png32" || m_format == "png64" || m_format == "png128" || m_format == "png256") + m_replyFormat = "png"; + else if (m_format == "jpg70" || m_format == "jpg80" || m_format == "jpg90") + m_replyFormat = "jpg"; + else + qWarning() << "Unknown map format " << m_format; +} + +void QGeoTileFetcherMapbox::setAccessToken(const QString &accessToken) +{ + m_accessToken = accessToken; +} + +QGeoTiledMapReply *QGeoTileFetcherMapbox::getTileImage(const QGeoTileSpec &spec) +{ + QNetworkRequest request; + request.setRawHeader("User-Agent", m_userAgent); + + request.setUrl(QUrl(QStringLiteral("http://api.tiles.mapbox.com/v4/") + + m_mapId + QLatin1Char('/') + + QString::number(spec.zoom()) + QLatin1Char('/') + + QString::number(spec.x()) + QLatin1Char('/') + + QString::number(spec.y()) + QLatin1Char('.') + + m_format + QLatin1Char('?') + + QStringLiteral("access_token=") + m_accessToken)); + + QNetworkReply *reply = m_networkManager->get(request); + + return new QGeoMapReplyMapbox(reply, spec, m_replyFormat); +} + +QT_END_NAMESPACE diff --git a/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h new file mode 100644 index 00000000..9980b308 --- /dev/null +++ b/src/plugins/geoservices/mapbox/qgeotilefetchermapbox.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Canonical Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtLocation module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOTILEFETCHERMAPBOX_H +#define QGEOTILEFETCHERMAPBOX_H + +#include <QtLocation/private/qgeotilefetcher_p.h> + +QT_BEGIN_NAMESPACE + +class QGeoTiledMappingManagerEngine; +class QNetworkAccessManager; + +class QGeoTileFetcherMapbox : public QGeoTileFetcher +{ + Q_OBJECT + +public: + QGeoTileFetcherMapbox(QObject *parent = 0); + + void setUserAgent(const QByteArray &userAgent); + void setMapId(const QString &mapId); + void setFormat(const QString &format); + void setAccessToken(const QString &accessToken); + +private: + QGeoTiledMapReply *getTileImage(const QGeoTileSpec &spec); + + QNetworkAccessManager *m_networkManager; + QByteArray m_userAgent; + QString m_mapId; + QString m_format; + QString m_replyFormat; + QString m_accessToken; +}; + +QT_END_NAMESPACE + +#endif // QGEOTILEFETCHERMAPBOX_H |