diff --git a/src/map/IMG/gmap.cpp b/src/map/IMG/gmap.cpp index 4e16bb60..64a1e512 100644 --- a/src/map/IMG/gmap.cpp +++ b/src/map/IMG/gmap.cpp @@ -84,11 +84,13 @@ bool GMAP::loadTile(const QDir &dir, bool baseMap) tile->addFile(fi.absoluteFilePath(), tileType(fi.suffix())); } - if (!tile->init(baseMap)) { + if (!tile->init()) { qWarning("%s: Invalid map tile", qPrintable(dir.path())); delete tile; return false; } + if (baseMap) + tile->markAsBasemap(); double min[2], max[2]; min[0] = tile->bounds().left(); diff --git a/src/map/IMG/img.cpp b/src/map/IMG/img.cpp index 7b577e3c..13c66d2f 100644 --- a/src/map/IMG/img.cpp +++ b/src/map/IMG/img.cpp @@ -132,11 +132,13 @@ IMG::IMG(const QString &fileName) : _file(fileName) } // Create tile tree + + int minMapZoom = 24; for (TileMap::const_iterator it = tileMap.constBegin(); it != tileMap.constEnd(); ++it) { VectorTile *tile = it.value(); - if (!tile->init(false)) { + if (!tile->init()) { qWarning("%s: %s: Invalid map tile", qPrintable(_file.fileName()), qPrintable(it.key())); delete tile; @@ -153,6 +155,17 @@ IMG::IMG(const QString &fileName) : _file(fileName) _bounds |= tile->bounds(); if (tile->zooms().min() < _zooms.min()) _zooms.setMin(tile->zooms().min()); + if (tile->zooms().min() < minMapZoom) + minMapZoom = tile->zooms().min(); + } + + for (TileMap::const_iterator it = tileMap.constBegin(); + it != tileMap.constEnd(); ++it) { + VectorTile *tile = it.value(); + if (tile->zooms().min() > minMapZoom) + _baseMap = true; + if (tile->zooms().min() == minMapZoom) + tile->markAsBasemap(); } if (!_tileTree.Count()) diff --git a/src/map/IMG/trefile.cpp b/src/map/IMG/trefile.cpp index 6854cbf0..f258f5f4 100644 --- a/src/map/IMG/trefile.cpp +++ b/src/map/IMG/trefile.cpp @@ -42,12 +42,13 @@ TREFile::~TREFile() clear(); } -bool TREFile::init(bool baseMap) +bool TREFile::init() { Handle hdl(this); quint8 locked; quint16 hdrLen; + if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen) && seek(hdl, _gmpOffset + 0x0D) && readUInt8(hdl, locked))) return false; @@ -114,7 +115,7 @@ bool TREFile::init(bool baseMap) } } - _isBaseMap = baseMap; + _isBaseMap = false; return (_firstLevel >= 0); } diff --git a/src/map/IMG/trefile.h b/src/map/IMG/trefile.h index 2e252f73..b7fa4fd7 100644 --- a/src/map/IMG/trefile.h +++ b/src/map/IMG/trefile.h @@ -18,7 +18,8 @@ public: TREFile(SubFile *gmp, quint32 offset) : SubFile(gmp, offset) {} ~TREFile(); - bool init(bool baseMap); + bool init(); + void markAsBasemap() {_isBaseMap = true;} void clear(); const RectC &bounds() const {return _bounds;} @@ -26,7 +27,7 @@ public: quint32 shift(quint8 bits) const {return (bits == _levels.last().bits) ? (_flags >> 0xb) & 7 : 0;} Range zooms() const - {return Range(_levels.first().bits, _levels.last().bits);} + {return Range(_levels.at(_firstLevel).bits, _levels.last().bits);} private: struct MapLevel { diff --git a/src/map/IMG/vectortile.cpp b/src/map/IMG/vectortile.cpp index 2888789d..a8f948a7 100644 --- a/src/map/IMG/vectortile.cpp +++ b/src/map/IMG/vectortile.cpp @@ -82,12 +82,12 @@ SubFile *VectorTile::addFile(const QString &path, SubFile::Type type) } } -bool VectorTile::init(bool baseMap) +bool VectorTile::init() { if (_gmp && !initGMP()) return false; - if (!(_tre && _tre->init(baseMap) && _rgn)) + if (!(_tre && _tre->init() && _rgn)) return false; return true; diff --git a/src/map/IMG/vectortile.h b/src/map/IMG/vectortile.h index 26f27ac5..b63cf174 100644 --- a/src/map/IMG/vectortile.h +++ b/src/map/IMG/vectortile.h @@ -15,7 +15,8 @@ public: delete _tre; delete _rgn; delete _lbl; delete _net; delete _gmp; } - bool init(bool baseMap); + bool init(); + void markAsBasemap() {_tre->markAsBasemap();} void clear() {_tre->clear();} const RectC &bounds() const {return _tre->bounds();}