Unverified Commit cb62d3ae authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8902 from DonLakeFlyer/ZoomTo23

Support map zoom to level 23
parents 5db0b39b b7dfacba
......@@ -4,6 +4,7 @@ Note: This file only contains high level features or important fixes.
## 4.1 - Daily build
* Maps: Support zoom up to level 23 even if map provider doesn't provide tiles that high
* Settings/Mavlink: Add ability to forward mavlink traffic out specified UDP port
* Support mavlink terrain protocol which queries gcs for terrain height information. Allows planning missions with TERRAIN\_FRAME.
* Fly: New instrument values display/editing support
......
......@@ -22,6 +22,7 @@
<file alias="gear-black.svg">resources/gear-black.svg</file>
<file alias="gear-white.svg">resources/gear-white.svg</file>
<file alias="helicoptericon.svg">resources/helicoptericon.svg</file>
<file alias="BingNoTileBytes.dat">resources/BingNoTileBytes.dat</file>
<file alias="JoystickBezel.png">resources/JoystickBezel.png</file>
<file alias="JoystickBezelLight.png">resources/JoystickBezelLight.png</file>
<file alias="land.svg">resources/land.svg</file>
......
......@@ -20,6 +20,9 @@ public:
~BingMapProvider() = default;
bool _isBingProvider() const override { return true; }
protected:
const QString _versionBingMaps = QStringLiteral("563");
};
......
......@@ -89,10 +89,6 @@ int MapProvider::lat2tileY(const double lat, const int z) const {
2.0 * pow(2.0, z)));
}
bool MapProvider::_isElevationProvider() const {
return false;
}
QGCTileSet MapProvider::getTileCount(const int zoom, const double topleftLon,
const double topleftLat, const double bottomRightLon,
const double bottomRightLat) const {
......
......@@ -45,7 +45,8 @@ public:
virtual int lat2tileY(const double lat, const int z) const;
virtual bool _isElevationProvider() 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,
......
......@@ -155,6 +155,17 @@ QString UrlFactory::getTypeFromId(int id) {
return "";
}
MapProvider* UrlFactory::getMapProviderFromId(int id)
{
QString type = getTypeFromId(id);
if (!type.isEmpty()) {
if (_providersTable.find(type) != _providersTable.end()) {
return _providersTable[type];
}
}
return nullptr;
}
// Todo : qHash produce a uint bigger than max(int)
// There is still a low probability for this to
// generate similar hash for different types
......
......@@ -24,7 +24,7 @@
#include "MapboxMapProvider.h"
#include "ElevationMapProvider.h"
#define MAX_MAP_ZOOM (20.0)
#define MAX_MAP_ZOOM (23.0)
class UrlFactory : public QObject {
Q_OBJECT
......@@ -48,6 +48,7 @@ public:
int getIdFromType(QString type);
QString getTypeFromId(int id);
MapProvider* getMapProviderFromId(int id);
QGCTileSet getTileCount(int zoom, double topleftLon, double topleftLat,
double bottomRightLon, double bottomRightLat,
......
......@@ -53,7 +53,8 @@
#include <QFile>
#include "TerrainTile.h"
int QGeoTiledMapReplyQGC::_requestCount = 0;
int QGeoTiledMapReplyQGC::_requestCount = 0;
QByteArray QGeoTiledMapReplyQGC::_bingNoTileImage;
//-----------------------------------------------------------------------------
QGeoTiledMapReplyQGC::QGeoTiledMapReplyQGC(QNetworkAccessManager *networkManager, const QNetworkRequest &request, const QGeoTileSpec &spec, QObject *parent)
......@@ -62,6 +63,12 @@ QGeoTiledMapReplyQGC::QGeoTiledMapReplyQGC(QNetworkAccessManager *networkManager
, _request(request)
, _networkManager(networkManager)
{
if (_bingNoTileImage.count() == 0) {
QFile file(":/res/BingNoTileBytes.dat");
file.open(QFile::ReadOnly);
_bingNoTileImage = file.readAll();
file.close();
}
if(_request.url().isEmpty()) {
if(!_badMapbox.size()) {
QFile b(":/res/notile.png");
......@@ -122,7 +129,8 @@ QGeoTiledMapReplyQGC::networkReplyFinished()
return;
}
QByteArray a = _reply->readAll();
QString format = getQGCMapEngine()->urlFactory()->getImageFormat(tileSpec().mapId(), a);
UrlFactory* urlFactory = getQGCMapEngine()->urlFactory();
QString format = urlFactory->getImageFormat(tileSpec().mapId(), a);
//-- Test for a specialized, elevation data (not map tile)
if( getQGCMapEngine()->urlFactory()->isElevation(tileSpec().mapId())){
a = TerrainTile::serialize(a);
......@@ -135,11 +143,20 @@ QGeoTiledMapReplyQGC::networkReplyFinished()
}
emit terrainDone(a, QNetworkReply::NoError);
} else {
//-- This is a map tile. Process and cache it if valid.
setMapImageData(a);
if(!format.isEmpty()) {
setMapImageFormat(format);
getQGCMapEngine()->cacheTile(getQGCMapEngine()->urlFactory()->getTypeFromId(tileSpec().mapId()), tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format);
MapProvider* mapProvider = urlFactory->getMapProviderFromId(tileSpec().mapId());
if (mapProvider && mapProvider->_isBingProvider() && a.size() && _bingNoTileImage.size() && a == _bingNoTileImage) {
// Bing doesn't return an error if you request a tile above supported zoom level
// It instead returns an image of a missing tile graphic. We need to detect that
// and error out so Qt will deal with zooming correctly even if it doesn't have the tile.
// This allows us to zoom up to level 23 even though the tiles don't actually exist
setError(QGeoTiledMapReply::CommunicationError, "Bing tile above zoom level");
} else {
//-- This is a map tile. Process and cache it if valid.
setMapImageData(a);
if(!format.isEmpty()) {
setMapImageFormat(format);
getQGCMapEngine()->cacheTile(getQGCMapEngine()->urlFactory()->getTypeFromId(tileSpec().mapId()), tileSpec().x(), tileSpec().y(), tileSpec().zoom(), a, format);
}
}
setFinished(true);
}
......
......@@ -81,6 +81,7 @@ private:
QByteArray _badMapbox;
QByteArray _badTile;
QTimer _timer;
static QByteArray _bingNoTileImage;
static int _requestCount;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment