1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Properly handle IMG basemaps (gmapbmap.img)

This commit is contained in:
Martin Tůma 2020-02-17 09:19:15 +01:00
parent f333a76ef7
commit 27edc4d6b5
6 changed files with 27 additions and 9 deletions

View File

@ -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();

View File

@ -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())

View File

@ -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);
}

View File

@ -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 {

View File

@ -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;

View File

@ -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();}