1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 03:59:15 +02:00

Provide propper map bounds for overviews

This commit is contained in:
2020-12-13 19:40:09 +01:00
parent 4cef089c81
commit 239e571358
13 changed files with 228 additions and 75 deletions

View File

@ -1,7 +1,6 @@
#include <QtGlobal>
#include <QPainter>
#include "common/rectc.h"
#include "osm.h"
#include "emptymap.h"

View File

@ -1,6 +1,7 @@
#ifndef EMPTYMAP_H
#define EMPTYMAP_H
#include "osm.h"
#include "map.h"
class EmptyMap : public Map
@ -13,6 +14,7 @@ public:
QString name() const {return QString();}
QRectF bounds();
RectC llBounds() {return OSM::BOUNDS;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}

View File

@ -18,6 +18,7 @@ public:
QString name() const {return _data.first()->name();}
QRectF bounds() {return _bounds;}
RectC llBounds() {return _dataBounds;}
int zoom() const {return _zoom;}
void setZoom(int zoom);

View File

@ -20,6 +20,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds() {return _bounds;}
int zoom() const {return _zoom;}
void setZoom(int zoom) {_zoom = zoom;}

View File

@ -1,6 +1,67 @@
#include <cmath>
#include <QLineF>
#include "map.h"
#define SAMPLES 100
void Map::growLeft(const QPointF &p, RectC &rect)
{
Coordinates c(xy2ll(p));
if (c.lon() < rect.left())
rect.setLeft(c.lon());
}
void Map::growRight(const QPointF &p, RectC &rect)
{
Coordinates c(xy2ll(p));
if (c.lon() > rect.right())
rect.setRight(c.lon());
}
void Map::growTop(const QPointF &p, RectC &rect)
{
Coordinates c(xy2ll(p));
if (c.lat() > rect.top())
rect.setTop(c.lat());
}
void Map::growBottom(const QPointF &p, RectC &rect)
{
Coordinates c(xy2ll(p));
if (c.lat() < rect.bottom())
rect.setBottom(c.lat());
}
RectC Map::llBounds()
{
QRectF b(bounds());
double dx = b.width() / SAMPLES;
double dy = b.height() / SAMPLES;
Coordinates tl(xy2ll(b.topLeft()));
Coordinates br(xy2ll(b.bottomRight()));
RectC rect(tl, br);
for (int i = 0; i <= SAMPLES; i++) {
double x = b.left() + i * dx;
growBottom(QPointF(x, b.bottom()), rect);
growTop(QPointF(x, b.top()), rect);
}
for (int i = 0; i <= SAMPLES; i++) {
double y = b.top() + i * dy;
growLeft(QPointF(b.left(), y), rect);
growRight(QPointF(b.right(), y), rect);
}
return rect;
}
qreal Map::resolution(const QRectF &rect)
{
qreal cy = rect.center().y();

View File

@ -5,11 +5,10 @@
#include <QString>
#include <QRectF>
#include <QFlags>
#include "common/coordinates.h"
#include "common/rectc.h"
class QPainter;
class RectC;
class Projection;
class Map : public QObject
@ -31,6 +30,7 @@ public:
const QString &path() const {return _path;}
virtual QString name() const = 0;
virtual RectC llBounds();
virtual QRectF bounds() = 0;
virtual qreal resolution(const QRectF &rect);
@ -60,6 +60,11 @@ signals:
void mapLoaded();
private:
void growLeft(const QPointF &p, RectC &rect);
void growRight(const QPointF &p, RectC &rect);
void growTop(const QPointF &p, RectC &rect);
void growBottom(const QPointF &p, RectC &rect);
QString _path;
};

View File

@ -14,6 +14,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}

View File

@ -19,6 +19,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds() {return _bounds;}
qreal resolution(const QRectF &rect);
int zoom() const {return _zoom;}

View File

@ -4,69 +4,92 @@
#include "rectd.h"
static void growRect(const Projection &proj, const Coordinates &c, RectD &rect)
static void growLeft(const Projection &proj, const Coordinates &c, RectD &rect)
{
if (c.isNull())
return;
PointD p(proj.ll2xy(c));
if (rect.isNull())
rect = RectD(p, p);
else {
if (p.x() < rect.left())
rect.setLeft(p.x());
if (p.x() > rect.right())
rect.setRight(p.x());
if (p.y() < rect.bottom())
rect.setBottom(p.y());
if (p.y() > rect.top())
rect.setTop(p.y());
}
if (p.x() < rect.left())
rect.setLeft(p.x());
}
static void growRect(const Projection &proj, const PointD &p, RectC &rect)
static void growRight(const Projection &proj, const Coordinates &c, RectD &rect)
{
if (p.isNull())
return;
PointD p(proj.ll2xy(c));
if (p.x() > rect.right())
rect.setRight(p.x());
}
static void growTop(const Projection &proj, const Coordinates &c, RectD &rect)
{
PointD p(proj.ll2xy(c));
if (p.y() > rect.top())
rect.setTop(p.y());
}
static void growBottom(const Projection &proj, const Coordinates &c, RectD &rect)
{
PointD p(proj.ll2xy(c));
if (p.y() < rect.bottom())
rect.setBottom(p.y());
}
static void growLeft(const Projection &proj, const PointD &p, RectC &rect)
{
Coordinates c(proj.xy2ll(p));
if (rect.isNull())
rect = RectC(c, c);
else {
if (c.lon() < rect.left())
rect.setLeft(c.lon());
if (c.lon() > rect.right())
rect.setRight(c.lon());
if (c.lat() < rect.bottom())
rect.setBottom(c.lat());
if (c.lat() > rect.top())
rect.setTop(c.lat());
}
if (c.lon() < rect.left())
rect.setLeft(c.lon());
}
static void growRight(const Projection &proj, const PointD &p, RectC &rect)
{
Coordinates c(proj.xy2ll(p));
if (c.lon() > rect.right())
rect.setRight(c.lon());
}
static void growTop(const Projection &proj, const PointD &p, RectC &rect)
{
Coordinates c(proj.xy2ll(p));
if (c.lat() > rect.top())
rect.setTop(c.lat());
}
static void growBottom(const Projection &proj, const PointD &p, RectC &rect)
{
Coordinates c(proj.xy2ll(p));
if (c.lat() < rect.bottom())
rect.setBottom(c.lat());
}
RectD::RectD(const RectC &rect, const Projection &proj, int samples)
{
RectD prect;
if (!rect.isValid())
return;
if (rect.isValid()) {
double dx = rect.width() / samples;
double dy = rect.height() / samples;
double dx = rect.width() / samples;
double dy = rect.height() / samples;
growRect(proj, rect.topLeft(), prect);
PointD tl(proj.ll2xy(rect.topLeft()));
PointD br(proj.ll2xy(rect.bottomRight()));
RectD prect(tl, br);
for (int i = 0; i <= samples; i++) {
double x = remainder(rect.left() + i * dx, 360.0);
growRect(proj, Coordinates(x, rect.bottom()), prect);
growRect(proj, Coordinates(x, rect.top()), prect);
}
for (int i = 0; i <= samples; i++) {
double x = remainder(rect.left() + i * dx, 360.0);
growBottom(proj, Coordinates(x, rect.bottom()), prect);
growTop(proj, Coordinates(x, rect.top()), prect);
}
for (int i = 0; i <= samples; i++ ) {
double y = rect.bottom() + i * dy;
growRect(proj, Coordinates(rect.left(), y), prect);
growRect(proj, Coordinates(rect.right(), y), prect);
}
for (int i = 0; i <= samples; i++) {
double y = rect.bottom() + i * dy;
growLeft(proj, Coordinates(rect.left(), y), prect);
growRight(proj, Coordinates(rect.right(), y), prect);
}
*this = prect;
@ -77,22 +100,23 @@ RectC RectD::toRectC(const Projection &proj, int samples) const
if (!isValid())
return RectC();
RectC rect;
double dx = width() / samples;
double dy = height() / samples;
growRect(proj, topLeft(), rect);
Coordinates tl(proj.xy2ll(topLeft()));
Coordinates br(proj.xy2ll(bottomRight()));
RectC rect(tl, br);
for (int i = 0; i <= samples; i++) {
double x = left() + i * dx;
growRect(proj, PointD(x, bottom()), rect);
growRect(proj, PointD(x, top()), rect);
growBottom(proj, PointD(x, bottom()), rect);
growTop(proj, PointD(x, top()), rect);
}
for (int i = 0; i <= samples; i++ ) {
for (int i = 0; i <= samples; i++) {
double y = bottom() + i * dy;
growRect(proj, PointD(left(), y), rect);
growRect(proj, PointD(right(), y), rect);
growLeft(proj, PointD(left(), y), rect);
growRight(proj, PointD(right(), y), rect);
}
return rect;

View File

@ -20,6 +20,7 @@ public:
QString name() const {return _name;}
QRectF bounds();
RectC llBounds() {return _wms->bbox();}
int zoom() const {return _zoom;}
void setZoom(int zoom);

View File

@ -85,6 +85,7 @@ QRectF WMTSMap::bounds()
bounds = QRectF(_transform.proj2img(_bounds.topLeft())
/ coordinatesRatio(), _transform.proj2img(
_bounds.bottomRight()) / coordinatesRatio());
return bounds.isValid() ? tileBounds.intersected(bounds) : tileBounds;
}