MapProvider.h 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/****************************************************************************
 *
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include <QByteArray>
#include <QString>

#include <cmath>

#include "QGCTileSet.h" 
#include <QtLocation/private/qgeomaptype_p.h>

static const unsigned char pngSignature[]  = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00};
static const unsigned char jpegSignature[] = {0xFF, 0xD8, 0xFF, 0x00};
static const unsigned char gifSignature[]  = {0x47, 0x49, 0x46, 0x38, 0x00};

static const quint32 AVERAGE_TILE_SIZE = 13652;

class QNetworkRequest;
class QNetworkAccessManager;

class MapProvider : public QObject {
    Q_OBJECT

public:
    MapProvider(const QString& referrer, const QString& imageFormat, const quint32 averageSize,
        const QGeoMapType::MapStyle mapType = QGeoMapType::CustomMap, QObject* parent = nullptr);

    virtual QNetworkRequest getTileURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager);

    QString getImageFormat(const QByteArray& image) const;

    quint32 getAverageSize() const { return _averageSize; }

    QGeoMapType::MapStyle getMapStyle() { return _mapType; }

    virtual int long2tileX(const double lon, const int z) const;

    virtual int lat2tileY(const double lat, const int z) const;

    virtual bool _isElevationProvider() const { return false; }
    virtual bool _isBingProvider() const { return false; }

    virtual QGCTileSet getTileCount(const int zoom, const double topleftLon,
                                     const double topleftLat, const double bottomRightLon,
                                     const double bottomRightLat) const;

protected:
    QString _tileXYToQuadKey(const int tileX, const int tileY, const int levelOfDetail) const;
    int _getServerNum(const int x, const int y, const int max) const;
    // Define the url to Request
    virtual QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) = 0;

    // Define Referrer for Request RawHeader
    QString     _referrer;
    QString     _imageFormat;
    quint32     _averageSize;
    QByteArray  _userAgent;
    QString     _language;
    QGeoMapType::MapStyle _mapType;

};