1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00

Improved scale computation on offline & WMTS maps

This commit is contained in:
Martin Tůma 2018-02-28 22:19:46 +01:00
parent 46cefada94
commit b9ed0c3933
12 changed files with 131 additions and 199 deletions

View File

@ -95,7 +95,8 @@ void MapView::centerOn(const QPointF &pos)
verticalScrollBar()->setValue(verticalScrollBar()->value() verticalScrollBar()->setValue(verticalScrollBar()->value()
+ offset.y()); + offset.y());
_res = _map->resolution(pos); QRectF vr(mapToScene(viewport()->rect()).boundingRect());
_res = _map->resolution(vr);
_mapScale->setResolution(_res); _mapScale->setResolution(_res);
} }
@ -267,9 +268,8 @@ void MapView::setPalette(const Palette &palette)
void MapView::setMap(Map *map) void MapView::setMap(Map *map)
{ {
QPointF pos = mapToScene(viewport()->rect().center()); QRectF vr(mapToScene(viewport()->rect()).boundingRect());
Coordinates center = _map->xy2ll(pos); RectC cr(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
qreal resolution = _map->resolution(pos);
_map->unload(); _map->unload();
disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap())); disconnect(_map, SIGNAL(loaded()), this, SLOT(reloadMap()));
@ -281,7 +281,7 @@ void MapView::setMap(Map *map)
digitalZoom(0); digitalZoom(0);
_map->zoomFit(resolution, center); _map->zoomFit(viewport()->rect().size(), cr);
_scene->setSceneRect(_map->bounds()); _scene->setSceneRect(_map->bounds());
for (int i = 0; i < _tracks.size(); i++) for (int i = 0; i < _tracks.size(); i++)
@ -296,7 +296,7 @@ void MapView::setMap(Map *map)
it.value()->setMap(_map); it.value()->setMap(_map);
updatePOIVisibility(); updatePOIVisibility();
centerOn(_map->ll2xy(center)); centerOn(_map->ll2xy(cr.center()));
resetCachedContent(); resetCachedContent();
QPixmapCache::clear(); QPixmapCache::clear();
@ -499,9 +499,9 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
bool hires) bool hires)
{ {
QRect orig, adj; QRect orig, adj;
qreal ratio, diff, origRes, q; qreal ratio, diff, q;
QPointF origScene, origPos; QPointF origScene, origPos;
Coordinates origLL; RectC origC;
// Enter plot mode // Enter plot mode
@ -526,9 +526,9 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
// Adjust the view for printing // Adjust the view for printing
if (hires) { if (hires) {
origScene = mapToScene(orig.center()); QRectF vr(mapToScene(orig).boundingRect());
origLL = _map->xy2ll(origScene); origC = RectC(_map->xy2ll(vr.topLeft()), _map->xy2ll(vr.bottomRight()));
origRes = _map->resolution(origScene); origScene = vr.center();
QPointF s(painter->device()->logicalDpiX() QPointF s(painter->device()->logicalDpiX()
/ (qreal)metric(QPaintDevice::PdmDpiX), / (qreal)metric(QPaintDevice::PdmDpiX),
@ -558,7 +558,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
// Revert view changes to display mode // Revert view changes to display mode
if (hires) { if (hires) {
_map->zoomFit(origRes, origLL); _map->zoomFit(orig.size(), origC);
rescale(); rescale();
centerOn(origScene); centerOn(origScene);
} }
@ -797,8 +797,8 @@ void MapView::scrollContentsBy(int dx, int dy)
{ {
QGraphicsView::scrollContentsBy(dx, dy); QGraphicsView::scrollContentsBy(dx, dy);
QPointF center = mapToScene(viewport()->rect().center()); QRectF sr(mapToScene(viewport()->rect()).boundingRect());
qreal res = _map->resolution(center); qreal res = _map->resolution(sr);
if (qMax(res, _res) / qMin(res, _res) > 1.1) { if (qMax(res, _res) / qMin(res, _res) > 1.1) {
_mapScale->setResolution(res); _mapScale->setResolution(res);

View File

@ -15,8 +15,8 @@ static bool resCmp(const OfflineMap *m1, const OfflineMap *m2)
{ {
qreal r1, r2; qreal r1, r2;
r1 = m1->resolution(m1->bounds().center()); r1 = m1->resolution(m1->bounds());
r2 = m2->resolution(m2->bounds().center()); r2 = m2->resolution(m2->bounds());
return r1 > r2; return r1 > r2;
} }
@ -37,8 +37,8 @@ void Atlas::computeZooms()
_zooms.append(QPair<int, int>(0, _maps.count() - 1)); _zooms.append(QPair<int, int>(0, _maps.count() - 1));
for (int i = 1; i < _maps.count(); i++) { for (int i = 1; i < _maps.count(); i++) {
qreal last = _maps.at(i-1)->resolution(_maps.at(i)->bounds().center()); qreal last = _maps.at(i-1)->resolution(_maps.at(i)->bounds());
qreal cur = _maps.at(i)->resolution(_maps.at(i)->bounds().center()); qreal cur = _maps.at(i)->resolution(_maps.at(i)->bounds());
if (cur < last * ZOOM_THRESHOLD) { if (cur < last * ZOOM_THRESHOLD) {
_zooms.last().second = i-1; _zooms.last().second = i-1;
_zooms.append(QPair<int, int>(i, _maps.count() - 1)); _zooms.append(QPair<int, int>(i, _maps.count() - 1));
@ -169,26 +169,21 @@ QRectF Atlas::bounds() const
return QRectF(QPointF(0, 0), s); return QRectF(QPointF(0, 0), s);
} }
qreal Atlas::resolution(const QPointF &p) const qreal Atlas::resolution(const QRectF &rect) const
{ {
int idx = _zooms.at(_zoom).first; int idx = _zooms.at(_zoom).first;
for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) { for (int i = _zooms.at(_zoom).first; i <= _zooms.at(_zoom).second; i++) {
if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(p))) { if (_bounds.at(i).second.contains(_maps.at(i)->xy2pp(rect.center()))) {
idx = i; idx = i;
break; break;
} }
} }
return _maps.at(idx)->resolution(p); return _maps.at(idx)->resolution(rect);
} }
qreal Atlas::zoom() const int Atlas::zoomFit(const QSize &size, const RectC &br)
{
return _zoom;
}
qreal Atlas::zoomFit(const QSize &size, const RectC &br)
{ {
_zoom = 0; _zoom = 0;
@ -217,33 +212,13 @@ qreal Atlas::zoomFit(const QSize &size, const RectC &br)
return _zoom; return _zoom;
} }
qreal Atlas::zoomFit(qreal resolution, const Coordinates &c) int Atlas::zoomIn()
{
_zoom = 0;
for (int z = 0; z < _zooms.count(); z++) {
for (int i = _zooms.at(z).first; i <= _zooms.at(z).second; i++) {
if (!_bounds.at(i).first.contains(_maps.at(i)->ll2pp(c)))
continue;
if (_maps.at(i)->resolution(_maps.at(i)->ll2xy(c)) < resolution)
return _zoom;
_zoom = z;
break;
}
}
return _zoom;
}
qreal Atlas::zoomIn()
{ {
_zoom = qMin(_zoom + 1, _zooms.size() - 1); _zoom = qMin(_zoom + 1, _zooms.size() - 1);
return _zoom; return _zoom;
} }
qreal Atlas::zoomOut() int Atlas::zoomOut()
{ {
_zoom = qMax(_zoom - 1, 0); _zoom = qMax(_zoom - 1, 0);
return _zoom; return _zoom;

View File

@ -17,13 +17,12 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QPointF &p) const; qreal resolution(const QRectF &rect) const;
qreal zoom() const; int zoom() const {return _zoom;}
qreal zoomFit(const QSize &size, const RectC &br); int zoomFit(const QSize &size, const RectC &br);
qreal zoomFit(qreal resolution, const Coordinates &c); int zoomIn();
qreal zoomIn(); int zoomOut();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c); QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p); Coordinates xy2ll(const QPointF &p);

View File

@ -6,8 +6,9 @@
#include "emptymap.h" #include "emptymap.h"
#define SCALE_MIN 0.5 #define ZOOM_MIN 0
#define SCALE_MAX 1.0E-6 #define ZOOM_MAX 19
#define TILE_SIZE 256
static QPointF ll2m(const Coordinates &c) static QPointF ll2m(const Coordinates &c)
{ {
@ -19,10 +20,30 @@ static Coordinates m2ll(const QPointF &p)
return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2)); return Coordinates(p.x(), rad2deg(2 * atan(exp(deg2rad(p.y()))) - M_PI/2));
} }
static qreal zoom2scale(int zoom)
{
return (360.0/(qreal)((1<<zoom) * TILE_SIZE));
}
static int scale2zoom(qreal scale)
{
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
}
static int limitZoom(int zoom)
{
if (zoom < ZOOM_MIN)
return ZOOM_MIN;
if (zoom > ZOOM_MAX)
return ZOOM_MAX;
return zoom;
}
EmptyMap::EmptyMap(QObject *parent) : Map(parent) EmptyMap::EmptyMap(QObject *parent) : Map(parent)
{ {
_scale = SCALE_MAX; _zoom = ZOOM_MAX;
} }
QRectF EmptyMap::bounds() const QRectF EmptyMap::bounds() const
@ -30,49 +51,38 @@ QRectF EmptyMap::bounds() const
return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85))); return QRectF(ll2xy(Coordinates(-180, 85)), ll2xy(Coordinates(180, -85)));
} }
qreal EmptyMap::zoomFit(const QSize &size, const RectC &br) int EmptyMap::zoomFit(const QSize &size, const RectC &br)
{ {
if (!br.isValid()) if (!br.isValid())
_scale = SCALE_MAX; _zoom = ZOOM_MAX;
else { else {
QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight())); QRectF tbr(ll2m(br.topLeft()), ll2m(br.bottomRight()));
QPointF sc(tbr.width() / size.width(), tbr.height() / size.height()); QPointF sc(tbr.width() / size.width(), tbr.height() / size.height());
_scale = qMax(sc.x(), sc.y());
_zoom = limitZoom(scale2zoom(qMax(sc.x(), sc.y())));
} }
_scale = qMax(_scale, SCALE_MAX); return _zoom;
_scale = qMin(_scale, SCALE_MIN);
return _scale;
} }
qreal EmptyMap::zoomFit(qreal resolution, const Coordinates &c) qreal EmptyMap::resolution(const QRectF &rect) const
{ {
_scale = (360.0 * resolution) / (WGS84_RADIUS * 2 * M_PI qreal scale = zoom2scale(_zoom);
* cos(deg2rad(c.lat())));
_scale = qMax(_scale, SCALE_MAX); return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
_scale = qMin(_scale, SCALE_MIN); * cos(2.0 * atan(exp(deg2rad(-rect.center().y() * scale))) - M_PI/2));
return _scale;
} }
qreal EmptyMap::resolution(const QPointF &p) const int EmptyMap::zoomIn()
{ {
return (WGS84_RADIUS * 2 * M_PI * _scale / 360.0 _zoom = qMin(_zoom + 1, ZOOM_MAX);
* cos(2.0 * atan(exp(deg2rad(-p.y() * _scale))) - M_PI/2)); return _zoom;
} }
qreal EmptyMap::zoomIn() int EmptyMap::zoomOut()
{ {
_scale = qMax(_scale / 2.0, SCALE_MAX); _zoom = qMax(_zoom - 1, ZOOM_MIN);
return _scale; return _zoom;
}
qreal EmptyMap::zoomOut()
{
_scale = qMin(_scale * 2.0, SCALE_MIN);
return _scale;
} }
void EmptyMap::draw(QPainter *painter, const QRectF &rect) void EmptyMap::draw(QPainter *painter, const QRectF &rect)
@ -82,12 +92,13 @@ void EmptyMap::draw(QPainter *painter, const QRectF &rect)
QPointF EmptyMap::ll2xy(const Coordinates &c) const QPointF EmptyMap::ll2xy(const Coordinates &c) const
{ {
qreal scale = zoom2scale(_zoom);
QPointF m = ll2m(c); QPointF m = ll2m(c);
return QPointF(m.x() / _scale, m.y() / -_scale); return QPointF(m.x() / scale, m.y() / -scale);
} }
Coordinates EmptyMap::xy2ll(const QPointF &p) const Coordinates EmptyMap::xy2ll(const QPointF &p) const
{ {
QPointF m(p.x() * _scale, -p.y() * _scale); qreal scale = zoom2scale(_zoom);
return m2ll(QPointF(p.x() * _scale, -p.y() * _scale)); return m2ll(QPointF(p.x() * scale, -p.y() * scale));
} }

View File

@ -14,13 +14,12 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QPointF &p) const; qreal resolution(const QRectF &rect) const;
qreal zoom() const {return _scale;} int zoom() const {return _zoom;}
qreal zoomFit(const QSize &size, const RectC &br); int zoomFit(const QSize &size, const RectC &br);
qreal zoomFit(qreal resolution, const Coordinates &c); int zoomIn();
qreal zoomIn(); int zoomOut();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c)
{return static_cast<const EmptyMap &>(*this).ll2xy(c);} {return static_cast<const EmptyMap &>(*this).ll2xy(c);}
@ -34,7 +33,7 @@ private:
Coordinates xy2ll(const QPointF &p) const; Coordinates xy2ll(const QPointF &p) const;
QString _name; QString _name;
qreal _scale; int _zoom;
}; };
#endif // EMPTYMAP_H #endif // EMPTYMAP_H

View File

@ -20,13 +20,12 @@ public:
virtual const QString &name() const = 0; virtual const QString &name() const = 0;
virtual QRectF bounds() const = 0; virtual QRectF bounds() const = 0;
virtual qreal resolution(const QPointF &p) const = 0; virtual qreal resolution(const QRectF &rect) const = 0;
virtual qreal zoom() const = 0; virtual int zoom() const = 0;
virtual qreal zoomFit(const QSize &size, const RectC &br) = 0; virtual int zoomFit(const QSize &size, const RectC &br) = 0;
virtual qreal zoomFit(qreal resolution, const Coordinates &c) = 0; virtual int zoomIn() = 0;
virtual qreal zoomIn() = 0; virtual int zoomOut() = 0;
virtual qreal zoomOut() = 0;
virtual QPointF ll2xy(const Coordinates &c) = 0; virtual QPointF ll2xy(const Coordinates &c) = 0;
virtual Coordinates xy2ll(const QPointF &p) = 0; virtual Coordinates xy2ll(const QPointF &p) = 0;

View File

@ -14,17 +14,6 @@
#include "offlinemap.h" #include "offlinemap.h"
void OfflineMap::computeResolution()
{
Coordinates tl = xy2ll((bounds().topLeft()));
Coordinates br = xy2ll(bounds().bottomRight());
qreal ds = tl.distanceTo(br);
qreal ps = QLineF(bounds().topLeft(), bounds().bottomRight()).length();
_resolution = ds/ps;
}
bool OfflineMap::getImageInfo(const QString &path) bool OfflineMap::getImageInfo(const QString &path)
{ {
QFileInfo ii(_imgPath); QFileInfo ii(_imgPath);
@ -112,7 +101,6 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
_valid = false; _valid = false;
_img = 0; _img = 0;
_resolution = 0.0;
_zoom = 0; _zoom = 0;
_scale = QPointF(1.0, 1.0); _scale = QPointF(1.0, 1.0);
@ -190,7 +178,6 @@ OfflineMap::OfflineMap(const QString &fileName, QObject *parent)
} }
_inverted = _transform.inverted(); _inverted = _transform.inverted();
computeResolution();
_valid = true; _valid = true;
} }
@ -203,7 +190,6 @@ OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
_valid = false; _valid = false;
_img = 0; _img = 0;
_resolution = 0.0;
_zoom = 0; _zoom = 0;
_scale = QPointF(1.0, 1.0); _scale = QPointF(1.0, 1.0);
@ -227,9 +213,7 @@ OfflineMap::OfflineMap(const QString &fileName, Tar &tar, QObject *parent)
_size = mf.size(); _size = mf.size();
_projection = mf.projection(); _projection = mf.projection();
_transform = mf.transform(); _transform = mf.transform();
_inverted = _transform.inverted(); _inverted = _transform.inverted();
computeResolution();
_tarPath = fi.absolutePath() + "/" + fi.completeBaseName() + ".tar"; _tarPath = fi.absolutePath() + "/" + fi.completeBaseName() + ".tar";
_valid = true; _valid = true;
@ -353,7 +337,7 @@ void OfflineMap::draw(QPainter *painter, const QRectF &rect)
painter->fillRect(rect, _backgroundColor); painter->fillRect(rect, _backgroundColor);
} }
QPointF OfflineMap::ll2xy(const Coordinates &c) QPointF OfflineMap::ll2xy(const Coordinates &c) const
{ {
if (_ozf.isOpen()) { if (_ozf.isOpen()) {
QPointF p(_transform.map(_projection.ll2xy(c))); QPointF p(_transform.map(_projection.ll2xy(c)));
@ -362,7 +346,7 @@ QPointF OfflineMap::ll2xy(const Coordinates &c)
return _transform.map(_projection.ll2xy(c)); return _transform.map(_projection.ll2xy(c));
} }
Coordinates OfflineMap::xy2ll(const QPointF &p) Coordinates OfflineMap::xy2ll(const QPointF &p) const
{ {
if (_ozf.isOpen()) { if (_ozf.isOpen()) {
return _projection.xy2ll(_inverted.map(QPointF(p.x() / _scale.x(), return _projection.xy2ll(_inverted.map(QPointF(p.x() / _scale.x(),
@ -379,17 +363,18 @@ QRectF OfflineMap::bounds() const
return QRectF(QPointF(0, 0), _size); return QRectF(QPointF(0, 0), _size);
} }
qreal OfflineMap::resolution(const QPointF &p) const qreal OfflineMap::resolution(const QRectF &rect) const
{ {
Q_UNUSED(p); Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
if (_ozf.isOpen()) qreal ds = tl.distanceTo(br);
return _resolution / ((_scale.x() + _scale.y()) / 2.0); qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
else
return _resolution; return ds/ps;
} }
qreal OfflineMap::zoomFit(const QSize &size, const RectC &br) int OfflineMap::zoomFit(const QSize &size, const RectC &br)
{ {
if (_ozf.isOpen()) { if (_ozf.isOpen()) {
if (!br.isValid()) if (!br.isValid())
@ -411,23 +396,7 @@ qreal OfflineMap::zoomFit(const QSize &size, const RectC &br)
return _zoom; return _zoom;
} }
qreal OfflineMap::zoomFit(qreal resolution, const Coordinates &c) int OfflineMap::zoomIn()
{
Q_UNUSED(c);
if (_ozf.isOpen()) {
for (int i = 0; i < _ozf.zooms(); i++) {
rescale(i);
qreal sr = _resolution / ((_scale.x() + _scale.y()) / 2.0);
if (sr >= resolution)
break;
}
}
return _zoom;
}
qreal OfflineMap::zoomIn()
{ {
if (_ozf.isOpen()) if (_ozf.isOpen())
rescale(qMax(_zoom - 1, 0)); rescale(qMax(_zoom - 1, 0));
@ -435,7 +404,7 @@ qreal OfflineMap::zoomIn()
return _zoom; return _zoom;
} }
qreal OfflineMap::zoomOut() int OfflineMap::zoomOut()
{ {
if (_ozf.isOpen()) if (_ozf.isOpen())
rescale(qMin(_zoom + 1, _ozf.zooms() - 1)); rescale(qMin(_zoom + 1, _ozf.zooms() - 1));

View File

@ -24,16 +24,17 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QPointF &p) const; qreal resolution(const QRectF &rect) const;
qreal zoom() const {return _zoom;} int zoom() const {return _zoom;}
qreal zoomFit(const QSize &size, const RectC &br); int zoomFit(const QSize &size, const RectC &br);
qreal zoomFit(qreal resolution, const Coordinates &c); int zoomIn();
qreal zoomIn(); int zoomOut();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c); QPointF ll2xy(const Coordinates &c)
Coordinates xy2ll(const QPointF &p); {return static_cast<const OfflineMap &>(*this).ll2xy(c);}
Coordinates xy2ll(const QPointF &p)
{return static_cast<const OfflineMap &>(*this).xy2ll(p);}
void draw(QPainter *painter, const QRectF &rect); void draw(QPainter *painter, const QRectF &rect);
@ -51,6 +52,9 @@ public:
{return _transform.map(p);} {return _transform.map(p);}
private: private:
QPointF ll2xy(const Coordinates &c) const;
Coordinates xy2ll(const QPointF &p) const;
bool getTileInfo(const QStringList &tiles, const QString &path = QString()); bool getTileInfo(const QStringList &tiles, const QString &path = QString());
bool getImageInfo(const QString &path); bool getImageInfo(const QString &path);
bool totalSizeSet(); bool totalSizeSet();
@ -59,7 +63,6 @@ private:
void drawOZF(QPainter *painter, const QRectF &rect); void drawOZF(QPainter *painter, const QRectF &rect);
void drawImage(QPainter *painter, const QRectF &rect); void drawImage(QPainter *painter, const QRectF &rect);
void computeResolution();
void rescale(int zoom); void rescale(int zoom);
QString _name; QString _name;
@ -77,7 +80,6 @@ private:
QSize _size; QSize _size;
int _zoom; int _zoom;
qreal _resolution;
QPointF _scale; QPointF _scale;
bool _valid; bool _valid;

View File

@ -90,7 +90,7 @@ int OnlineMap::limitZoom(int zoom) const
return zoom; return zoom;
} }
qreal OnlineMap::zoomFit(const QSize &size, const RectC &br) int OnlineMap::zoomFit(const QSize &size, const RectC &br)
{ {
if (!br.isValid()) if (!br.isValid())
_zoom = _zooms.max(); _zoom = _zooms.max();
@ -104,29 +104,21 @@ qreal OnlineMap::zoomFit(const QSize &size, const RectC &br)
return _zoom; return _zoom;
} }
qreal OnlineMap::zoomFit(qreal resolution, const Coordinates &c) qreal OnlineMap::resolution(const QRectF &rect) const
{
_zoom = limitZoom((int)log2((WGS84_RADIUS * 2.0 * M_PI
* cos(deg2rad(c.lat()))) / (resolution * TILE_SIZE)));
return _zoom;
}
qreal OnlineMap::resolution(const QPointF &p) const
{ {
qreal scale = zoom2scale(_zoom); qreal scale = zoom2scale(_zoom);
return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0 return (WGS84_RADIUS * 2.0 * M_PI * scale / 360.0
* cos(2.0 * atan(exp(deg2rad(-p.y() * scale))) - M_PI/2)); * cos(2.0 * atan(exp(deg2rad(-rect.center().y() * scale))) - M_PI/2));
} }
qreal OnlineMap::zoomIn() int OnlineMap::zoomIn()
{ {
_zoom = qMin(_zoom + 1, _zooms.max()); _zoom = qMin(_zoom + 1, _zooms.max());
return _zoom; return _zoom;
} }
qreal OnlineMap::zoomOut() int OnlineMap::zoomOut()
{ {
_zoom = qMax(_zoom - 1, _zooms.min()); _zoom = qMax(_zoom - 1, _zooms.min());
return _zoom; return _zoom;

View File

@ -18,13 +18,12 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QPointF &p) const; qreal resolution(const QRectF &rect) const;
qreal zoom() const {return _zoom;} int zoom() const {return _zoom;}
qreal zoomFit(const QSize &size, const RectC &br); int zoomFit(const QSize &size, const RectC &br);
qreal zoomFit(qreal resolution, const Coordinates &c); int zoomIn();
qreal zoomIn(); int zoomOut();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c)
{return static_cast<const OnlineMap &>(*this).ll2xy(c);} {return static_cast<const OnlineMap &>(*this).ll2xy(c);}

View File

@ -119,7 +119,7 @@ QRectF WMTSMap::bounds() const
return _bounds.isValid() ? tileBounds.intersected(bounds) : tileBounds; return _bounds.isValid() ? tileBounds.intersected(bounds) : tileBounds;
} }
qreal WMTSMap::zoomFit(const QSize &size, const RectC &br) int WMTSMap::zoomFit(const QSize &size, const RectC &br)
{ {
if (br.isValid()) { if (br.isValid()) {
QRectF tbr(_projection.ll2xy(br.topLeft()), QRectF tbr(_projection.ll2xy(br.topLeft()),
@ -142,37 +142,25 @@ qreal WMTSMap::zoomFit(const QSize &size, const RectC &br)
return _zoom; return _zoom;
} }
qreal WMTSMap::zoomFit(qreal resolution, const Coordinates &c) qreal WMTSMap::resolution(const QRectF &rect) const
{ {
Q_UNUSED(c); Coordinates tl = xy2ll((rect.topLeft()));
Coordinates br = xy2ll(rect.bottomRight());
_zoom = 0; qreal ds = tl.distanceTo(br);
qreal ps = QLineF(rect.topLeft(), rect.bottomRight()).length();
for (int i = 0; i < _zooms.size(); i++) { return ds/ps;
if (sd2res(_zooms.at(i).scaleDenominator) < resolution)
break;
_zoom = i;
}
updateTransform();
return _zoom;
} }
qreal WMTSMap::resolution(const QPointF &p) const int WMTSMap::zoomIn()
{
Q_UNUSED(p);
return sd2res(_zooms.at(_zoom).scaleDenominator);
}
qreal WMTSMap::zoomIn()
{ {
_zoom = qMin(_zoom + 1, _zooms.size() - 1); _zoom = qMin(_zoom + 1, _zooms.size() - 1);
updateTransform(); updateTransform();
return _zoom; return _zoom;
} }
qreal WMTSMap::zoomOut() int WMTSMap::zoomOut()
{ {
_zoom = qMax(_zoom - 1, 0); _zoom = qMax(_zoom - 1, 0);
updateTransform(); updateTransform();

View File

@ -18,13 +18,12 @@ public:
const QString &name() const {return _name;} const QString &name() const {return _name;}
QRectF bounds() const; QRectF bounds() const;
qreal resolution(const QPointF &p) const; qreal resolution(const QRectF &rect) const;
qreal zoom() const {return _zoom;} int zoom() const {return _zoom;}
qreal zoomFit(const QSize &size, const RectC &br); int zoomFit(const QSize &size, const RectC &br);
qreal zoomFit(qreal resolution, const Coordinates &c); int zoomIn();
qreal zoomIn(); int zoomOut();
qreal zoomOut();
QPointF ll2xy(const Coordinates &c) QPointF ll2xy(const Coordinates &c)
{return static_cast<const WMTSMap &>(*this).ll2xy(c);} {return static_cast<const WMTSMap &>(*this).ll2xy(c);}