1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Compute the min map zoom from the tiles

This commit is contained in:
Martin Tůma 2020-02-15 21:49:00 +01:00
parent 42e4b0769f
commit c9b3c2eedd
8 changed files with 19 additions and 10 deletions

View File

@ -98,6 +98,8 @@ bool GMAP::loadTile(const QDir &dir, bool baseMap)
_tileTree.Insert(min, max, tile);
_bounds |= tile->bounds();
if (tile->zooms().min() < _zooms.min())
_zooms.setMin(tile->zooms().min());
return true;
}

View File

@ -151,6 +151,8 @@ IMG::IMG(const QString &fileName) : _file(fileName)
_tileTree.Insert(min, max, tile);
_bounds |= tile->bounds();
if (tile->zooms().min() < _zooms.min())
_zooms.setMin(tile->zooms().min());
}
if (!_tileTree.Count())

View File

@ -54,7 +54,8 @@ inline bool pointCb(VectorTile *tile, void *context)
}
MapData::MapData() : _typ(0), _style(0), _baseMap(false), _valid(false)
MapData::MapData() : _typ(0), _style(0), _zooms(24, 28), _baseMap(false),
_valid(false)
{
_polyCache.setMaxCost(CACHED_SUBDIVS_COUNT);
_pointCache.setMaxCost(CACHED_SUBDIVS_COUNT);

View File

@ -7,6 +7,7 @@
#include <QDebug>
#include "common/rectc.h"
#include "common/rtree.h"
#include "common/range.h"
#include "label.h"
class Style;
@ -58,6 +59,7 @@ public:
const QString &name() const {return _name;}
const RectC &bounds() const {return _bounds;}
const Range &zooms() const {return _zooms;}
const Style *style() const {return _style;}
void polys(const RectC &rect, int bits, QList<Poly> *polygons,
QList<Poly> *lines);
@ -79,6 +81,7 @@ protected:
SubFile *_typ;
Style *_style;
TileTree _tileTree;
Range _zooms;
bool _baseMap;
bool _valid;

View File

@ -57,7 +57,7 @@ bool TREFile::init(bool baseMap)
if (!(seek(hdl, _gmpOffset + 0x15) && readInt24(hdl, north)
&& readInt24(hdl, east) && readInt24(hdl, south) && readInt24(hdl, west)))
return false;
_bounds = RectC(Coordinates(toWGS24(west), toWGS24(north)),
_bounds = RectC(Coordinates(toWGS24(west), qMin(toWGS24(north), 85.11)),
Coordinates(RB(east), toWGS24(south)));
Q_ASSERT(_bounds.left() <= _bounds.right());

View File

@ -25,6 +25,8 @@ public:
QList<SubDiv*> subdivs(const RectC &rect, int bits, bool baseMap);
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);}
private:
struct MapLevel {

View File

@ -19,6 +19,7 @@ public:
void clear() {_tre->clear();}
const RectC &bounds() const {return _tre->bounds();}
Range zooms() const {return _tre->zooms();}
SubFile *file(SubFile::Type type);
SubFile *addFile(IMG *img, SubFile::Type type);

View File

@ -79,8 +79,6 @@ private:
};
static const Range zooms(12, 28);
static const QColor shieldColor(Qt::white);
static const QColor shieldBgColor1("#dd3e3e");
static const QColor shieldBgColor2("#379947");
@ -243,7 +241,7 @@ IMGMap::IMGMap(const QString &fileName, QObject *parent)
return;
}
_zoom = zooms.min();
_zoom = _data->zooms().min();
updateTransform();
_valid = true;
@ -271,8 +269,8 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
if (rect.isValid()) {
RectD pr(rect, _projection, 10);
_zoom = zooms.min();
for (int i = zooms.min() + 1; i <= zooms.max(); i++) {
_zoom = _data->zooms().min();
for (int i = _data->zooms().min() + 1; i <= _data->zooms().max(); i++) {
Transform t(transform(i));
QRectF r(t.proj2img(pr.topLeft()), t.proj2img(pr.bottomRight()));
if (size.width() < r.width() || size.height() < r.height())
@ -280,7 +278,7 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
_zoom = i;
}
} else
_zoom = zooms.max();
_zoom = _data->zooms().max();
updateTransform();
@ -289,14 +287,14 @@ int IMGMap::zoomFit(const QSize &size, const RectC &rect)
int IMGMap::zoomIn()
{
_zoom = qMin(_zoom + 1, zooms.max());
_zoom = qMin(_zoom + 1, _data->zooms().max());
updateTransform();
return _zoom;
}
int IMGMap::zoomOut()
{
_zoom = qMax(_zoom - 1, zooms.min());
_zoom = qMax(_zoom - 1, _data->zooms().min());
updateTransform();
return _zoom;
}