EsriMapProvider.cpp 2.41 KB
Newer Older
Cosmin Marc's avatar
Cosmin Marc committed
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
Cosmin Marc's avatar
Cosmin Marc committed
4 5 6 7 8 9
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

10 11 12 13
#include "EsriMapProvider.h"
#include "QGCApplication.h"
#include "SettingsManager.h"

Cosmin Marc's avatar
Cosmin Marc committed
14 15 16 17
EsriMapProvider::EsriMapProvider(const quint32 averageSize, const QGeoMapType::MapStyle mapType, QObject *parent)
    : MapProvider(QString(), QString(), averageSize, mapType, parent) {}

QNetworkRequest EsriMapProvider::getTileURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) {
18 19
    //-- Build URL
    QNetworkRequest request;
Cosmin Marc's avatar
Cosmin Marc committed
20
    const QString url = _getURL(x, y, zoom, networkManager);
21 22 23 24
    if (url.isEmpty()) {
        return request;
    }
    request.setUrl(QUrl(url));
Cosmin Marc's avatar
Cosmin Marc committed
25 26 27 28
    request.setRawHeader(QByteArrayLiteral("Accept"), QByteArrayLiteral("*/*"));
    const QByteArray token = qgcApp()->toolbox()->settingsManager()->appSettings()->esriToken()->rawValue().toString().toLatin1();
    request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("Qt Location based application"));
    request.setRawHeader(QByteArrayLiteral("User-Token"), token);
29 30 31
    return request;
}

Cosmin Marc's avatar
Cosmin Marc committed
32 33 34 35 36
static const QString WorldStreetMapUrl = QStringLiteral("http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/%1/%2/%3");

QString EsriWorldStreetMapProvider::_getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) {
    Q_UNUSED(networkManager)
    return WorldStreetMapUrl.arg(zoom).arg(y).arg(x);
37 38
}

Cosmin Marc's avatar
Cosmin Marc committed
39 40 41 42 43
static const QString WorldSatelliteMapUrl = QStringLiteral("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/%1/%2/%3");

QString EsriWorldSatelliteMapProvider::_getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) {
    Q_UNUSED(networkManager)
    return WorldSatelliteMapUrl.arg(zoom).arg(y).arg(x);
44 45
}

Cosmin Marc's avatar
Cosmin Marc committed
46 47 48 49 50
static const QString TerrainMapUrl = QStringLiteral("http://server.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/%1/%2/%3");

QString EsriTerrainMapProvider::_getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) {
    Q_UNUSED(networkManager)
    return TerrainMapUrl.arg(zoom).arg(y).arg(x);
51
}