From 285afe827de23cf5e4fee5c5755f09034d5af151 Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Thu, 9 Jul 2020 14:29:27 -0700 Subject: [PATCH] Support map zoom to level 23 --- qgcresources.qrc | 1 + resources/BingNoTileBytes.dat | Bin 0 -> 1033 bytes src/QtLocationPlugin/QGCMapEngine.cpp | 9 +++++++++ src/QtLocationPlugin/QGCMapUrlEngine.h | 2 +- src/QtLocationPlugin/QGeoMapReplyQGC.cpp | 27 +++++++++++++++++++++------ src/QtLocationPlugin/QGeoMapReplyQGC.h | 1 + 6 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 resources/BingNoTileBytes.dat diff --git a/qgcresources.qrc b/qgcresources.qrc index 977a849..49a66a1 100644 --- a/qgcresources.qrc +++ b/qgcresources.qrc @@ -22,6 +22,7 @@ resources/gear-black.svg resources/gear-white.svg resources/helicoptericon.svg + resources/BingNoTileBytes.dat resources/JoystickBezel.png resources/JoystickBezelLight.png resources/land.svg diff --git a/resources/BingNoTileBytes.dat b/resources/BingNoTileBytes.dat new file mode 100644 index 0000000000000000000000000000000000000000..fa081a52c297cf34a8d2863448ed60b866a47cea GIT binary patch literal 1033 zcmV+k1or!hP)FVd>4i#%v4Yf86PI zp#Xp`wB8THPILXtp7h<%!&Y$sY5-Or?5sV zX+I1A`mO<5c_?M!4iKqKE34>JSmRkz{~+9#0<>~p3f$pIWukKF>kl4u2rWyRloUD%*=UiJ=#v&J~BR?5t=$0n| zy6yGw>fSK)1C#>DG{C-;1$q~L%SEcl*Wne~X@LHx2!Qq&V2w^Q0G9qX`0yTJ6*<7- zG(a0}gIDhXuA&Eco(A~g3n1Af02BlCWq1xqtX_bV7UaGFB37#fABJ%03m{<%6^8Ib zfN!Ay#{kNg;XV}L7~nqgMs&IpzU)H*l3!zhI(mTV&B(ol0;D(whT$|AzX9W zJ_JbY{AahZ;ojW@C+5nGZfEVXnIqd*)h3E1byKz0|+}rQvqyWg} zD*6$@J=zf9#W{z*{XRLh&7)t1A}e%x+K&YQ`fg{BJF~)jK?anG9SZ=!zaxYIsg3@A zo`&lz>4)L(>+734uejTq!Ymcu4aXvnx4~0ug=4C)#&{c?O&5PJJX3%ak@vx{6}9II zuu?fItZz0e>hxUx2mJY4sZO1xT&ZVRdHb3sC7C6^lqcdnSAf zl@ScX_W7|RwQ2bPlfyDmmsZF1n~hw8Z$8kN{37d1Qkcee zjk&~sVId+SA|fIpA|fIpA|fIpA|fIpA|fK9|B-(ISkrVlC*^|U00000NkvXXu0mjf DlG*5< literal 0 HcmV?d00001 diff --git a/src/QtLocationPlugin/QGCMapEngine.cpp b/src/QtLocationPlugin/QGCMapEngine.cpp index 15774db..45577d1 100644 --- a/src/QtLocationPlugin/QGCMapEngine.cpp +++ b/src/QtLocationPlugin/QGCMapEngine.cpp @@ -222,6 +222,15 @@ QGCMapEngine::cacheTile(QString type, const QString& hash, const QByteArray& ima QString QGCMapEngine::getTileHash(QString type, int x, int y, int z) { +#if 0 + int maxCachedZoom = 15; + if (z > maxCachedZoom) { + double unZoomFactor = qPow(2, z - maxCachedZoom); + x = (double)x / unZoomFactor; + y = (double)y / unZoomFactor; + z = maxCachedZoom; + } +#endif return QString::asprintf("%010d%08d%08d%03d", getQGCMapEngine()->urlFactory()->getIdFromType(type), x, y, z); } diff --git a/src/QtLocationPlugin/QGCMapUrlEngine.h b/src/QtLocationPlugin/QGCMapUrlEngine.h index 769a3c4..6809926 100644 --- a/src/QtLocationPlugin/QGCMapUrlEngine.h +++ b/src/QtLocationPlugin/QGCMapUrlEngine.h @@ -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 diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp index 7f37010..557d144 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.cpp +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.cpp @@ -53,7 +53,8 @@ #include #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"); @@ -135,11 +142,19 @@ 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); + if (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); } diff --git a/src/QtLocationPlugin/QGeoMapReplyQGC.h b/src/QtLocationPlugin/QGeoMapReplyQGC.h index 58a59a0..af9ab1e 100644 --- a/src/QtLocationPlugin/QGeoMapReplyQGC.h +++ b/src/QtLocationPlugin/QGeoMapReplyQGC.h @@ -81,6 +81,7 @@ private: QByteArray _badMapbox; QByteArray _badTile; QTimer _timer; + static QByteArray _bingNoTileImage; static int _requestCount; };