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

Fixed broken zoom fit on IMG maps

This commit is contained in:
Martin Tůma 2019-05-29 18:27:11 +02:00
parent ff3c0aafa1
commit fe69280cc5
2 changed files with 15 additions and 9 deletions

View File

@ -109,13 +109,13 @@ QRectF IMGMap::bounds()
int IMGMap::zoomFit(const QSize &size, const RectC &rect) int IMGMap::zoomFit(const QSize &size, const RectC &rect)
{ {
if (rect.isValid()) { if (rect.isValid()) {
QPointF sc((rect.right() - rect.left()) / size.width(), RectD pr(rect, _projection, 10);
(rect.top() - rect.bottom()) / size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
_zoom = _zooms.min(); _zoom = _zooms.min();
for (int i = _zooms.min(); i <= _zooms.max(); i++) { for (int i = _zooms.min() + 1; i <= _zooms.max(); i++) {
if (360.0 / (1<<i) < resolution) Transform t(transform(i));
QRectF r(t.proj2img(pr.topLeft()), t.proj2img(pr.bottomRight()));
if (size.width() < r.width() || size.height() < r.height())
break; break;
_zoom = i; _zoom = i;
} }
@ -147,12 +147,17 @@ void IMGMap::setZoom(int zoom)
updateTransform(); updateTransform();
} }
Transform IMGMap::transform(int zoom) const
{
double scale = (2.0 * M_PI * WGS84_RADIUS) / (1<<zoom);
PointD topLeft(_projection.ll2xy(_img.bounds().topLeft()));
return Transform(ReferencePoint(PointD(0, 0), topLeft),
PointD(scale, scale));
}
void IMGMap::updateTransform() void IMGMap::updateTransform()
{ {
double scale = (2.0 * M_PI * WGS84_RADIUS) / (1<<_zoom);; _transform = transform(_zoom);
PointD topLeft(_projection.ll2xy(_img.bounds().topLeft()));
_transform = Transform(ReferencePoint(PointD(0, 0), topLeft),
PointD(scale, scale));
} }
QPointF IMGMap::ll2xy(const Coordinates &c) QPointF IMGMap::ll2xy(const Coordinates &c)

View File

@ -39,6 +39,7 @@ public:
private: private:
friend class RasterTile; friend class RasterTile;
Transform transform(int zoom) const;
void updateTransform(); void updateTransform();
void drawPolygons(QPainter *painter, QList<IMG::Poly> &polygons); void drawPolygons(QPainter *painter, QList<IMG::Poly> &polygons);
void drawLines(QPainter *painter, QList<IMG::Poly> &lines, void drawLines(QPainter *painter, QList<IMG::Poly> &lines,