diff --git a/src/common/range.h b/src/common/range.h index 7730eb05..226f889f 100644 --- a/src/common/range.h +++ b/src/common/range.h @@ -15,6 +15,7 @@ public: int size() const {return (_max - _min);} bool isValid() const {return size() >= 0;} + bool isNull() const {return _min == 0 && _max == 0;} void setMin(int min) {_min = min;} void setMax(int max) {_max = max;} diff --git a/src/map/IMG/gmapdata.cpp b/src/map/IMG/gmapdata.cpp index d73c9fd7..c0c0c601 100644 --- a/src/map/IMG/gmapdata.cpp +++ b/src/map/IMG/gmapdata.cpp @@ -94,8 +94,10 @@ bool GMAPData::loadTile(const QDir &dir, bool baseMap) delete tile; return false; } - if (baseMap) + if (baseMap) { tile->markAsBasemap(); + _baseMap = tile->zooms(); + } double min[2], max[2]; min[0] = tile->bounds().left(); @@ -124,10 +126,7 @@ GMAPData::GMAPData(const QString &fileName) : MapData(fileName) } QDir dataDir(baseDir.filePath(dataDirPath)); QFileInfoList ml = dataDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); - - QFileInfo baseMap(dataDir.filePath(baseMapPath)); - _baseMap = !baseMapPath.isEmpty() && baseMap.exists(); for (int i = 0; i < ml.size(); i++) { const QFileInfo &fi = ml.at(i); diff --git a/src/map/IMG/imgdata.cpp b/src/map/IMG/imgdata.cpp index 2b27db30..b6b22787 100644 --- a/src/map/IMG/imgdata.cpp +++ b/src/map/IMG/imgdata.cpp @@ -137,8 +137,6 @@ bool IMGData::readFAT(QFile &file, TileMap &tileMap) bool IMGData::createTileTree(const TileMap &tileMap) { - int minMapZoom = 24; - for (TileMap::const_iterator it = tileMap.constBegin(); it != tileMap.constEnd(); ++it) { VectorTile *tile = it.value(); @@ -160,23 +158,33 @@ bool IMGData::createTileTree(const TileMap &tileMap) _bounds |= tile->bounds(); if (tile->zooms().min() < _zooms.min()) _zooms.setMin(tile->zooms().min()); - if (tile->zooms().min() < minMapZoom) - minMapZoom = tile->zooms().min(); } // Detect and mark basemap TileTree::Iterator it; + bool baseMap = false; + for (_tileTree.GetFirst(it); !_tileTree.IsNull(it); _tileTree.GetNext(it)) { VectorTile *tile = _tileTree.GetAt(it); - if (tile->zooms().min() > minMapZoom) - _baseMap = true; - if (tile->zooms().min() == minMapZoom) - tile->markAsBasemap(); + if (tile->zooms().min() > _zooms.min()) { + baseMap = true; + break; + } } - // Allow some extra zoom out on maps without basemaps, but not too much as - // this would kill the rendering performance - if (!_baseMap) + if (baseMap) { + for (_tileTree.GetFirst(it); !_tileTree.IsNull(it); + _tileTree.GetNext(it)) { + VectorTile *tile = _tileTree.GetAt(it); + if (tile->zooms().min() == _zooms.min()) { + tile->markAsBasemap(); + _baseMap = tile->zooms(); + } + } + } else { + /* Allow some extra zoom out on maps without basemaps, but not too much + as this would kill the rendering performance. */ _zooms.setMin(_zooms.min() - 2); + } return (_tileTree.Count() > 0); } diff --git a/src/map/IMG/mapdata.cpp b/src/map/IMG/mapdata.cpp index 9e3ab6a4..58397520 100644 --- a/src/map/IMG/mapdata.cpp +++ b/src/map/IMG/mapdata.cpp @@ -26,8 +26,7 @@ bool MapData::pointCb(VectorTile *tile, void *context) MapData::MapData(const QString &fileName) - : _fileName(fileName), _typ(0), _style(0), _zooms(24, 28), _baseMap(false), - _valid(false) + : _fileName(fileName), _typ(0), _style(0), _zooms(24, 28), _valid(false) { _polyCache.setMaxCost(CACHED_SUBDIVS_COUNT); _pointCache.setMaxCost(CACHED_SUBDIVS_COUNT); diff --git a/src/map/IMG/mapdata.h b/src/map/IMG/mapdata.h index 7220c15e..128666a0 100644 --- a/src/map/IMG/mapdata.h +++ b/src/map/IMG/mapdata.h @@ -79,7 +79,7 @@ protected: Style *_style; TileTree _tileTree; Range _zooms; - bool _baseMap; + Range _baseMap; bool _valid; QString _errorString; @@ -96,7 +96,7 @@ private: struct PolyCTX { - PolyCTX(const RectC &rect, int bits, bool baseMap, + PolyCTX(const RectC &rect, int bits, const Range &baseMap, QList *polygons, QList *lines, QCache *polyCache) : rect(rect), bits(bits), baseMap(baseMap), polygons(polygons), @@ -104,7 +104,7 @@ private: const RectC ▭ int bits; - bool baseMap; + const Range &baseMap; QList *polygons; QList *lines; QCache *polyCache; @@ -112,7 +112,7 @@ private: struct PointCTX { - PointCTX(const RectC &rect, int bits, bool baseMap, + PointCTX(const RectC &rect, int bits, const Range &baseMap, QList *points, QCache > *pointCache) : rect(rect), bits(bits), baseMap(baseMap), points(points), @@ -120,7 +120,7 @@ private: const RectC ▭ int bits; - bool baseMap; + const Range &baseMap; QList *points; QCache > *pointCache; }; diff --git a/src/map/IMG/trefile.cpp b/src/map/IMG/trefile.cpp index e48b1cb9..df89d711 100644 --- a/src/map/IMG/trefile.cpp +++ b/src/map/IMG/trefile.cpp @@ -284,12 +284,12 @@ void TREFile::clear() _subdivs.clear(); } -int TREFile::level(int bits, bool baseMap) +int TREFile::level(int bits, const Range &baseMap) { - if (baseMap) { - if (!_isBaseMap && _levels.at(_firstLevel).bits > bits) + if (!baseMap.isNull()) { + if (!_isBaseMap && bits <= baseMap.max()) return -1; - if (_isBaseMap && bits > _levels.last().bits) + if (_isBaseMap && bits > baseMap.max()) return -1; } @@ -314,7 +314,8 @@ static bool cb(SubDiv *subdiv, void *context) return true; } -QList TREFile::subdivs(const RectC &rect, int bits, bool baseMap) +QList TREFile::subdivs(const RectC &rect, int bits, + const Range &baseMap) { QList list; SubDivTree *tree = _subdivs.value(level(bits, baseMap)); diff --git a/src/map/IMG/trefile.h b/src/map/IMG/trefile.h index b41831d1..e8347238 100644 --- a/src/map/IMG/trefile.h +++ b/src/map/IMG/trefile.h @@ -29,7 +29,7 @@ public: void clear(); const RectC &bounds() const {return _bounds;} - QList subdivs(const RectC &rect, int bits, bool baseMap); + QList subdivs(const RectC &rect, int bits, const Range &baseMap); quint32 shift(quint8 bits) const {return (bits == _levels.last().bits) ? (_flags >> 0xb) & 7 : 0;} Range zooms() const @@ -46,7 +46,7 @@ private: friend QDebug operator<<(QDebug dbg, const MapLevel &level); bool load(int idx); - int level(int bits, bool baseMap); + int level(int bits, const Range &baseMap); int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines, quint32 &points); diff --git a/src/map/IMG/vectortile.cpp b/src/map/IMG/vectortile.cpp index b4d17a80..9106c11c 100644 --- a/src/map/IMG/vectortile.cpp +++ b/src/map/IMG/vectortile.cpp @@ -100,7 +100,7 @@ void VectorTile::clear() _loaded = 0; } -void VectorTile::polys(const RectC &rect, int bits, bool baseMap, +void VectorTile::polys(const RectC &rect, int bits, const Range &baseMap, QList *polygons, QList *lines, QCache *polyCache) { @@ -169,7 +169,7 @@ void VectorTile::polys(const RectC &rect, int bits, bool baseMap, delete rgnHdl; delete lblHdl; delete netHdl; delete nodHdl; delete nodHdl2; } -void VectorTile::points(const RectC &rect, int bits, bool baseMap, +void VectorTile::points(const RectC &rect, int bits, const Range &baseMap, QList *points, QCache > *pointCache) { diff --git a/src/map/IMG/vectortile.h b/src/map/IMG/vectortile.h index 26de0e30..f8edebca 100644 --- a/src/map/IMG/vectortile.h +++ b/src/map/IMG/vectortile.h @@ -28,10 +28,10 @@ public: SubFile *file(SubFile::Type type); - void polys(const RectC &rect, int bits, bool baseMap, + void polys(const RectC &rect, int bits, const Range &baseMap, QList *polygons, QList *lines, QCache *polyCache); - void points(const RectC &rect, int bits, bool baseMap, + void points(const RectC &rect, int bits, const Range &baseMap, QList *points, QCache > *pointCache);