1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +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)
{
if (rect.isValid()) {
QPointF sc((rect.right() - rect.left()) / size.width(),
(rect.top() - rect.bottom()) / size.height());
double resolution = qMax(qAbs(sc.x()), qAbs(sc.y()));
RectD pr(rect, _projection, 10);
_zoom = _zooms.min();
for (int i = _zooms.min(); i <= _zooms.max(); i++) {
if (360.0 / (1<<i) < resolution)
for (int i = _zooms.min() + 1; i <= _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())
break;
_zoom = i;
}
@ -147,12 +147,17 @@ void IMGMap::setZoom(int zoom)
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()
{
double scale = (2.0 * M_PI * WGS84_RADIUS) / (1<<_zoom);;
PointD topLeft(_projection.ll2xy(_img.bounds().topLeft()));
_transform = Transform(ReferencePoint(PointD(0, 0), topLeft),
PointD(scale, scale));
_transform = transform(_zoom);
}
QPointF IMGMap::ll2xy(const Coordinates &c)

View File

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