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

10
#pragma once
11

12 13
#include <QByteArray>
#include <QString>
14 15 16 17

#include <cmath>

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

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

Cosmin Marc's avatar
Cosmin Marc committed
24
static const quint32 AVERAGE_TILE_SIZE = 13652;
25 26 27

class QNetworkRequest;
class QNetworkAccessManager;
28 29 30 31

class MapProvider : public QObject {
    Q_OBJECT

32 33
public:
    MapProvider(const QString& referrer, const QString& imageFormat, const quint32 averageSize,
Cosmin Marc's avatar
Cosmin Marc committed
34
        const QGeoMapType::MapStyle mapType = QGeoMapType::CustomMap, QObject* parent = nullptr);
35

Cosmin Marc's avatar
Cosmin Marc committed
36
    virtual QNetworkRequest getTileURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager);
37

38
    QString getImageFormat(const QByteArray& image) const;
39

40
    quint32 getAverageSize() const { return _averageSize; }
41

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

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

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

Cosmin Marc's avatar
Cosmin Marc committed
48
    virtual bool _isElevationProvider() const;
49 50 51 52

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

Cosmin Marc's avatar
Cosmin Marc committed
54 55 56
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;
57 58
    // Define the url to Request
    virtual QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) = 0;
59 60

    // Define Referrer for Request RawHeader
61 62 63 64 65
    QString     _referrer;
    QString     _imageFormat;
    quint32     _averageSize;
    QByteArray  _userAgent;
    QString     _language;
66
    QGeoMapType::MapStyle _mapType;
67 68

};