GoogleMapProvider.h 4.11 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 14
#pragma once

#include "MapProvider.h"

#include <QNetworkReply>
Cosmin Marc's avatar
Cosmin Marc committed
15
#include <QMutex>
16 17 18

class GoogleMapProvider : public MapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
19 20 21 22

public:
    GoogleMapProvider(const QString& imageFormat, const quint32 averageSize,
                      const QGeoMapType::MapStyle _mapType, QObject* parent = nullptr);
23 24 25 26

    ~GoogleMapProvider();

    // Google Specific private slots
Cosmin Marc's avatar
Cosmin Marc committed
27
private slots:
28 29 30 31
    void _networkReplyError(QNetworkReply::NetworkError error);
    void _googleVersionCompleted();
    void _replyDestroyed();

Cosmin Marc's avatar
Cosmin Marc committed
32
protected:
33
    // Google Specific private methods
Cosmin Marc's avatar
Cosmin Marc committed
34
    void _getSecGoogleWords(const int x, const int y, QString& sec1, QString& sec2) const;
35 36 37 38 39 40 41 42 43 44
    void _tryCorrectGoogleVersions(QNetworkAccessManager* networkManager);

    // Google Specific attributes
    bool           _googleVersionRetrieved;
    QNetworkReply* _googleReply;
    QMutex         _googleVersionMutex;
    QString        _versionGoogleMap;
    QString        _versionGoogleSatellite;
    QString        _versionGoogleLabels;
    QString        _versionGoogleTerrain;
Pierre TILAK's avatar
Pierre TILAK committed
45
    QString        _versionGoogleHybrid;
46 47
    QString        _secGoogleWord;
};
Pierre TILAK's avatar
Pierre TILAK committed
48

49 50 51 52 53 54 55 56 57 58 59 60 61
// NoMap = 0,
// StreetMap,
// SatelliteMapDay,
// SatelliteMapNight,
// TerrainMap,
// HybridMap,
// TransitMap,
// GrayStreetMap,
// PedestrianMap,
// CarNavigationMap,
// CycleMap,
// CustomMap = 100

Cosmin Marc's avatar
Cosmin Marc committed
62 63 64
static const quint32 AVERAGE_GOOGLE_STREET_MAP  = 4913;
static const quint32 AVERAGE_GOOGLE_SAT_MAP     = 56887;
static const quint32 AVERAGE_GOOGLE_TERRAIN_MAP = 19391;
65 66 67 68 69 70

// -----------------------------------------------------------
// Google Street Map

class GoogleStreetMapProvider : public GoogleMapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
71 72 73 74 75 76 77

public:
    GoogleStreetMapProvider(QObject* parent = nullptr)
        : GoogleMapProvider(QStringLiteral("png"), AVERAGE_GOOGLE_STREET_MAP, QGeoMapType::StreetMap, parent) {}

protected:
     QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
78 79 80 81 82
};

// -----------------------------------------------------------
// Google Street Map

Pierre TILAK's avatar
Pierre TILAK committed
83 84
class GoogleSatelliteMapProvider : public GoogleMapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
85 86 87 88

public:
    GoogleSatelliteMapProvider(QObject* parent = nullptr)
        : GoogleMapProvider(QStringLiteral("jpg"), AVERAGE_GOOGLE_SAT_MAP,
89 90
                            QGeoMapType::SatelliteMapDay, parent) {}

Cosmin Marc's avatar
Cosmin Marc committed
91 92
protected:
    QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
Pierre TILAK's avatar
Pierre TILAK committed
93
};
Pierre TILAK's avatar
Pierre TILAK committed
94

95 96 97
// -----------------------------------------------------------
// Google Labels Map

Pierre TILAK's avatar
Pierre TILAK committed
98 99
class GoogleLabelsMapProvider : public GoogleMapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
100 101 102 103 104 105 106

public:
    GoogleLabelsMapProvider(QObject* parent = nullptr)
        : GoogleMapProvider(QStringLiteral("png"), AVERAGE_TILE_SIZE, QGeoMapType::CustomMap, parent) {}

protected:
    QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
Pierre TILAK's avatar
Pierre TILAK committed
107 108
};

109 110 111
// -----------------------------------------------------------
// Google Terrain Map

Pierre TILAK's avatar
Pierre TILAK committed
112 113
class GoogleTerrainMapProvider : public GoogleMapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
114 115 116 117 118 119 120

public:
    GoogleTerrainMapProvider(QObject* parent = nullptr)
        : GoogleMapProvider(QStringLiteral("png"), AVERAGE_GOOGLE_TERRAIN_MAP, QGeoMapType::TerrainMap, parent) {}

protected:
    QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
Pierre TILAK's avatar
Pierre TILAK committed
121
};
Pierre TILAK's avatar
Pierre TILAK committed
122 123 124 125 126 127

// -----------------------------------------------------------
// Google Hybrid Map

class GoogleHybridMapProvider : public GoogleMapProvider {
    Q_OBJECT
Cosmin Marc's avatar
Cosmin Marc committed
128 129 130 131 132 133 134

public:
    GoogleHybridMapProvider(QObject* parent = nullptr)
        : GoogleMapProvider(QStringLiteral("png"), AVERAGE_GOOGLE_SAT_MAP, QGeoMapType::HybridMap, parent) {}

protected:
    QString _getURL(const int x, const int y, const int zoom, QNetworkAccessManager* networkManager) override;
Pierre TILAK's avatar
Pierre TILAK committed
135
};