mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-31 09:05:14 +01:00
Code cleanup
This commit is contained in:
parent
c39298000d
commit
e9f7642cde
@ -19,6 +19,8 @@ public:
|
||||
void setMin(int min) {_min = min;}
|
||||
void setMax(int max) {_max = max;}
|
||||
|
||||
bool contains(int val) const {return (val >= _min && val <= _max);}
|
||||
|
||||
private:
|
||||
int _min, _max;
|
||||
};
|
||||
|
@ -23,6 +23,11 @@ public:
|
||||
{return Coordinates((_tl.lon() + _br.lon()) / 2.0,
|
||||
(_tl.lat() + _br.lat()) / 2.0);}
|
||||
|
||||
double top() const {return _tl.lat();}
|
||||
double bottom() const {return _br.lat();}
|
||||
double left() const {return _tl.lon();}
|
||||
double right() const {return _br.lon();}
|
||||
|
||||
RectC operator|(const RectC &r) const;
|
||||
RectC &operator|=(const RectC &r) {*this = *this | r; return *this;}
|
||||
RectC operator&(const RectC &r) const;
|
||||
|
@ -4,19 +4,12 @@
|
||||
#include "onlinemap.h"
|
||||
#include "wmtsmap.h"
|
||||
#include "wmsmap.h"
|
||||
#include "osm.h"
|
||||
#include "mapsource.h"
|
||||
|
||||
#define ZOOM_MAX 19
|
||||
#define ZOOM_MIN 0
|
||||
#define BOUNDS_LEFT -180
|
||||
#define BOUNDS_TOP 85.0511
|
||||
#define BOUNDS_RIGHT 180
|
||||
#define BOUNDS_BOTTOM -85.0511
|
||||
|
||||
|
||||
MapSource::Config::Config() : type(OSM), zooms(ZOOM_MIN, ZOOM_MAX),
|
||||
bounds(Coordinates(BOUNDS_LEFT, BOUNDS_TOP), Coordinates(BOUNDS_RIGHT,
|
||||
BOUNDS_BOTTOM)), format("image/png"), rest(false), tileRatio(1.0) {}
|
||||
MapSource::Config::Config() : type(OSM), zooms(osm::zooms), bounds(osm::bounds),
|
||||
format("image/png"), rest(false), tileRatio(1.0) {}
|
||||
|
||||
|
||||
static CoordinateSystem coordinateSystem(QXmlStreamReader &reader)
|
||||
@ -38,21 +31,21 @@ Range MapSource::zooms(QXmlStreamReader &reader)
|
||||
|
||||
if (attr.hasAttribute("min")) {
|
||||
min = attr.value("min").toString().toInt(&res);
|
||||
if (!res || (min < ZOOM_MIN || min > ZOOM_MAX)) {
|
||||
if (!res || !osm::zooms.contains(min)) {
|
||||
reader.raiseError("Invalid minimal zoom level");
|
||||
return Range();
|
||||
}
|
||||
} else
|
||||
min = ZOOM_MIN;
|
||||
min = osm::zooms.min();
|
||||
|
||||
if (attr.hasAttribute("max")) {
|
||||
max = attr.value("max").toString().toInt(&res);
|
||||
if (!res || (max < ZOOM_MIN || max > ZOOM_MAX)) {
|
||||
if (!res || !osm::zooms.contains(max)) {
|
||||
reader.raiseError("Invalid maximal zoom level");
|
||||
return Range();
|
||||
}
|
||||
} else
|
||||
max = ZOOM_MAX;
|
||||
max = osm::zooms.max();
|
||||
|
||||
if (min > max) {
|
||||
reader.raiseError("Invalid maximal/minimal zoom level combination");
|
||||
@ -70,39 +63,41 @@ RectC MapSource::bounds(QXmlStreamReader &reader)
|
||||
|
||||
if (attr.hasAttribute("top")) {
|
||||
top = attr.value("top").toString().toDouble(&res);
|
||||
if (!res || (top < BOUNDS_BOTTOM || top > BOUNDS_TOP)) {
|
||||
if (!res || (top < osm::bounds.bottom() || top > osm::bounds.top())) {
|
||||
reader.raiseError("Invalid bounds top value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
top = BOUNDS_TOP;
|
||||
top = osm::bounds.top();
|
||||
|
||||
if (attr.hasAttribute("bottom")) {
|
||||
bottom = attr.value("bottom").toString().toDouble(&res);
|
||||
if (!res || (bottom < BOUNDS_BOTTOM || bottom > BOUNDS_TOP)) {
|
||||
if (!res || (bottom < osm::bounds.bottom()
|
||||
|| bottom > osm::bounds.top())) {
|
||||
reader.raiseError("Invalid bounds bottom value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
bottom = BOUNDS_BOTTOM;
|
||||
bottom = osm::bounds.bottom();
|
||||
|
||||
if (attr.hasAttribute("left")) {
|
||||
left = attr.value("left").toString().toDouble(&res);
|
||||
if (!res || (left < BOUNDS_LEFT || left > BOUNDS_RIGHT)) {
|
||||
if (!res || (left < osm::bounds.left() || left > osm::bounds.right())) {
|
||||
reader.raiseError("Invalid bounds left value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
left = BOUNDS_LEFT;
|
||||
left = osm::bounds.left();
|
||||
|
||||
if (attr.hasAttribute("right")) {
|
||||
right = attr.value("right").toString().toDouble(&res);
|
||||
if (!res || (right < BOUNDS_LEFT || right > BOUNDS_RIGHT)) {
|
||||
if (!res || (right < osm::bounds.left()
|
||||
|| right > osm::bounds.right())) {
|
||||
reader.raiseError("Invalid bounds right value");
|
||||
return RectC();
|
||||
}
|
||||
} else
|
||||
right = BOUNDS_RIGHT;
|
||||
right = osm::bounds.right();
|
||||
|
||||
if (bottom >= top) {
|
||||
reader.raiseError("Invalid bottom/top bounds combination");
|
||||
|
@ -77,8 +77,8 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
Coordinates tl(osm::m2ll(QPointF(minX, maxY)));
|
||||
Coordinates br(osm::m2ll(QPointF(maxX, minY)));
|
||||
// Workaround of broken zoom levels 0 and 1 due to numerical instability
|
||||
tl.rlat() = qMin(tl.lat(), 85.0511);
|
||||
br.rlat() = qMax(br.lat(), -85.0511);
|
||||
tl.rlat() = qMin(tl.lat(), osm::bounds.top());
|
||||
br.rlat() = qMax(br.lat(), osm::bounds.bottom());
|
||||
_bounds = RectC(tl, br);
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,15 @@
|
||||
|
||||
#include <QPointF>
|
||||
#include <common/coordinates.h>
|
||||
#include <common/rectc.h>
|
||||
#include <common/range.h>
|
||||
|
||||
namespace osm
|
||||
{
|
||||
static const RectC bounds(Coordinates(-180, 85.0511),
|
||||
Coordinates(180, -85.0511));
|
||||
static const Range zooms(0, 19);
|
||||
|
||||
QPointF ll2m(const Coordinates &c);
|
||||
Coordinates m2ll(const QPointF &p);
|
||||
QPoint mercator2tile(const QPointF &m, int z);
|
||||
|
Loading…
x
Reference in New Issue
Block a user