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

Fixed/improved IMG basemaps handling

This commit is contained in:
Martin Tůma 2022-04-20 19:40:44 +02:00
parent baee8b3484
commit 5f16f7b367
9 changed files with 41 additions and 33 deletions

View File

@ -15,6 +15,7 @@ public:
int size() const {return (_max - _min);} int size() const {return (_max - _min);}
bool isValid() const {return size() >= 0;} bool isValid() const {return size() >= 0;}
bool isNull() const {return _min == 0 && _max == 0;}
void setMin(int min) {_min = min;} void setMin(int min) {_min = min;}
void setMax(int max) {_max = max;} void setMax(int max) {_max = max;}

View File

@ -94,8 +94,10 @@ bool GMAPData::loadTile(const QDir &dir, bool baseMap)
delete tile; delete tile;
return false; return false;
} }
if (baseMap) if (baseMap) {
tile->markAsBasemap(); tile->markAsBasemap();
_baseMap = tile->zooms();
}
double min[2], max[2]; double min[2], max[2];
min[0] = tile->bounds().left(); min[0] = tile->bounds().left();
@ -124,10 +126,7 @@ GMAPData::GMAPData(const QString &fileName) : MapData(fileName)
} }
QDir dataDir(baseDir.filePath(dataDirPath)); QDir dataDir(baseDir.filePath(dataDirPath));
QFileInfoList ml = dataDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); QFileInfoList ml = dataDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfo baseMap(dataDir.filePath(baseMapPath)); QFileInfo baseMap(dataDir.filePath(baseMapPath));
_baseMap = !baseMapPath.isEmpty() && baseMap.exists();
for (int i = 0; i < ml.size(); i++) { for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i); const QFileInfo &fi = ml.at(i);

View File

@ -137,8 +137,6 @@ bool IMGData::readFAT(QFile &file, TileMap &tileMap)
bool IMGData::createTileTree(const TileMap &tileMap) bool IMGData::createTileTree(const TileMap &tileMap)
{ {
int minMapZoom = 24;
for (TileMap::const_iterator it = tileMap.constBegin(); for (TileMap::const_iterator it = tileMap.constBegin();
it != tileMap.constEnd(); ++it) { it != tileMap.constEnd(); ++it) {
VectorTile *tile = it.value(); VectorTile *tile = it.value();
@ -160,23 +158,33 @@ bool IMGData::createTileTree(const TileMap &tileMap)
_bounds |= tile->bounds(); _bounds |= tile->bounds();
if (tile->zooms().min() < _zooms.min()) if (tile->zooms().min() < _zooms.min())
_zooms.setMin(tile->zooms().min()); _zooms.setMin(tile->zooms().min());
if (tile->zooms().min() < minMapZoom)
minMapZoom = tile->zooms().min();
} }
// Detect and mark basemap // Detect and mark basemap
TileTree::Iterator it; TileTree::Iterator it;
bool baseMap = false;
for (_tileTree.GetFirst(it); !_tileTree.IsNull(it); _tileTree.GetNext(it)) { for (_tileTree.GetFirst(it); !_tileTree.IsNull(it); _tileTree.GetNext(it)) {
VectorTile *tile = _tileTree.GetAt(it); VectorTile *tile = _tileTree.GetAt(it);
if (tile->zooms().min() > minMapZoom) if (tile->zooms().min() > _zooms.min()) {
_baseMap = true; baseMap = true;
if (tile->zooms().min() == minMapZoom) break;
tile->markAsBasemap();
} }
// 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); _zooms.setMin(_zooms.min() - 2);
}
return (_tileTree.Count() > 0); return (_tileTree.Count() > 0);
} }

View File

@ -26,8 +26,7 @@ bool MapData::pointCb(VectorTile *tile, void *context)
MapData::MapData(const QString &fileName) MapData::MapData(const QString &fileName)
: _fileName(fileName), _typ(0), _style(0), _zooms(24, 28), _baseMap(false), : _fileName(fileName), _typ(0), _style(0), _zooms(24, 28), _valid(false)
_valid(false)
{ {
_polyCache.setMaxCost(CACHED_SUBDIVS_COUNT); _polyCache.setMaxCost(CACHED_SUBDIVS_COUNT);
_pointCache.setMaxCost(CACHED_SUBDIVS_COUNT); _pointCache.setMaxCost(CACHED_SUBDIVS_COUNT);

View File

@ -79,7 +79,7 @@ protected:
Style *_style; Style *_style;
TileTree _tileTree; TileTree _tileTree;
Range _zooms; Range _zooms;
bool _baseMap; Range _baseMap;
bool _valid; bool _valid;
QString _errorString; QString _errorString;
@ -96,7 +96,7 @@ private:
struct PolyCTX struct PolyCTX
{ {
PolyCTX(const RectC &rect, int bits, bool baseMap, PolyCTX(const RectC &rect, int bits, const Range &baseMap,
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines, QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
QCache<const SubDiv*, MapData::Polys> *polyCache) QCache<const SubDiv*, MapData::Polys> *polyCache)
: rect(rect), bits(bits), baseMap(baseMap), polygons(polygons), : rect(rect), bits(bits), baseMap(baseMap), polygons(polygons),
@ -104,7 +104,7 @@ private:
const RectC &rect; const RectC &rect;
int bits; int bits;
bool baseMap; const Range &baseMap;
QList<MapData::Poly> *polygons; QList<MapData::Poly> *polygons;
QList<MapData::Poly> *lines; QList<MapData::Poly> *lines;
QCache<const SubDiv*, MapData::Polys> *polyCache; QCache<const SubDiv*, MapData::Polys> *polyCache;
@ -112,7 +112,7 @@ private:
struct PointCTX struct PointCTX
{ {
PointCTX(const RectC &rect, int bits, bool baseMap, PointCTX(const RectC &rect, int bits, const Range &baseMap,
QList<MapData::Point> *points, QList<MapData::Point> *points,
QCache<const SubDiv*, QList<MapData::Point> > *pointCache) QCache<const SubDiv*, QList<MapData::Point> > *pointCache)
: rect(rect), bits(bits), baseMap(baseMap), points(points), : rect(rect), bits(bits), baseMap(baseMap), points(points),
@ -120,7 +120,7 @@ private:
const RectC &rect; const RectC &rect;
int bits; int bits;
bool baseMap; const Range &baseMap;
QList<MapData::Point> *points; QList<MapData::Point> *points;
QCache<const SubDiv*, QList<MapData::Point> > *pointCache; QCache<const SubDiv*, QList<MapData::Point> > *pointCache;
}; };

View File

@ -284,12 +284,12 @@ void TREFile::clear()
_subdivs.clear(); _subdivs.clear();
} }
int TREFile::level(int bits, bool baseMap) int TREFile::level(int bits, const Range &baseMap)
{ {
if (baseMap) { if (!baseMap.isNull()) {
if (!_isBaseMap && _levels.at(_firstLevel).bits > bits) if (!_isBaseMap && bits <= baseMap.max())
return -1; return -1;
if (_isBaseMap && bits > _levels.last().bits) if (_isBaseMap && bits > baseMap.max())
return -1; return -1;
} }
@ -314,7 +314,8 @@ static bool cb(SubDiv *subdiv, void *context)
return true; return true;
} }
QList<SubDiv*> TREFile::subdivs(const RectC &rect, int bits, bool baseMap) QList<SubDiv*> TREFile::subdivs(const RectC &rect, int bits,
const Range &baseMap)
{ {
QList<SubDiv*> list; QList<SubDiv*> list;
SubDivTree *tree = _subdivs.value(level(bits, baseMap)); SubDivTree *tree = _subdivs.value(level(bits, baseMap));

View File

@ -29,7 +29,7 @@ public:
void clear(); void clear();
const RectC &bounds() const {return _bounds;} const RectC &bounds() const {return _bounds;}
QList<SubDiv*> subdivs(const RectC &rect, int bits, bool baseMap); QList<SubDiv*> subdivs(const RectC &rect, int bits, const Range &baseMap);
quint32 shift(quint8 bits) const quint32 shift(quint8 bits) const
{return (bits == _levels.last().bits) ? (_flags >> 0xb) & 7 : 0;} {return (bits == _levels.last().bits) ? (_flags >> 0xb) & 7 : 0;}
Range zooms() const Range zooms() const
@ -46,7 +46,7 @@ private:
friend QDebug operator<<(QDebug dbg, const MapLevel &level); friend QDebug operator<<(QDebug dbg, const MapLevel &level);
bool load(int idx); 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, int readExtEntry(Handle &hdl, quint32 &polygons, quint32 &lines,
quint32 &points); quint32 &points);

View File

@ -100,7 +100,7 @@ void VectorTile::clear()
_loaded = 0; _loaded = 0;
} }
void VectorTile::polys(const RectC &rect, int bits, bool baseMap, void VectorTile::polys(const RectC &rect, int bits, const Range &baseMap,
QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines, QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
QCache<const SubDiv *, MapData::Polys> *polyCache) QCache<const SubDiv *, MapData::Polys> *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; 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<MapData::Point> *points, QCache<const SubDiv *, QList<MapData::Point> *points, QCache<const SubDiv *,
QList<MapData::Point> > *pointCache) QList<MapData::Point> > *pointCache)
{ {

View File

@ -28,10 +28,10 @@ public:
SubFile *file(SubFile::Type type); 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<MapData::Poly> *polygons, QList<MapData::Poly> *lines, QList<MapData::Poly> *polygons, QList<MapData::Poly> *lines,
QCache<const SubDiv *, MapData::Polys> *polyCache); QCache<const SubDiv *, MapData::Polys> *polyCache);
void points(const RectC &rect, int bits, bool baseMap, void points(const RectC &rect, int bits, const Range &baseMap,
QList<MapData::Point> *points, QCache<const SubDiv*, QList<MapData::Point> *points, QCache<const SubDiv*,
QList<MapData::Point> > *pointCache); QList<MapData::Point> > *pointCache);