MapProvider.h 1.89 KB
Newer Older
1 2
#pragma once

Pierre TILAK's avatar
Pierre TILAK committed
3
#include <cmath>
4 5
#include "QGCTileSet.h" 

6 7 8 9
#include <QByteArray>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QString>
10
#include <QtLocation/private/qgeomaptype_p.h>
11

12 13 14 15 16
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};

17
const quint32 AVERAGE_TILE_SIZE          = 13652;
18 19 20 21

class MapProvider : public QObject {
    Q_OBJECT
  public:
22 23 24
    MapProvider(
        QString referrer, QString imageFormat, quint32 averageSize,
        QGeoMapType::MapStyle _mapType = QGeoMapType::CustomMap, QObject* parent = nullptr);
25 26 27 28 29 30

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

    QString getImageFormat(const QByteArray& image);

31
    quint32 getAverageSize(){return _averageSize;}
32

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

35
    virtual int long2tileX(double lon, int z);
36

37
    virtual int lat2tileY(double lat, int z);
38

39 40
	virtual bool _isElevationProvider();

41 42 43 44
    virtual QGCTileSet getTileCount(int zoom, double topleftLon,
                                     double topleftLat, double bottomRightLon,
                                     double bottomRightLat);

45
  protected:
46 47
    QString _tileXYToQuadKey(int tileX, int tileY, int levelOfDetail);
    int     _getServerNum(int x, int y, int max);
48 49

    // Define Referrer for Request RawHeader
50 51 52 53 54
    QString     _referrer;
    QString     _imageFormat;
    quint32     _averageSize;
    QByteArray  _userAgent;
    QString     _language;
55
    QGeoMapType::MapStyle _mapType;
56 57 58 59 60

    // Define the url to Request
    virtual QString _getURL(int x, int y, int zoom,
                            QNetworkAccessManager* networkManager) = 0;
};