1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-03-18 20:47:46 +01:00
GPXSee/src/map/kmzmap.h

138 lines
3.4 KiB
C
Raw Normal View History

2020-12-22 22:32:07 +01:00
#ifndef KMZMAP_H
#define KMZMAP_H
#include <QImage>
#include "projection.h"
2020-12-22 22:32:07 +01:00
#include "transform.h"
#include "map.h"
class QXmlStreamReader;
class QZipReader;
class KMZMap : public Map
{
Q_OBJECT
public:
KMZMap(const QString &fileName, QObject *parent = 0);
~KMZMap();
2020-12-22 22:32:07 +01:00
RectC llBounds() {return _llbounds;}
2020-12-22 22:32:07 +01:00
QRectF bounds();
int zoom() const {return _zoom;}
void setZoom(int zoom);
int zoomFit(const QSize &size, const RectC &br);
int zoomIn();
int zoomOut();
QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p);
void draw(QPainter *painter, const QRectF &rect, Flags flags);
void load(const Projection &in, const Projection &out, qreal deviceRatio,
bool hidpi);
2020-12-22 22:32:07 +01:00
void unload();
bool isValid() const {return _valid;}
QString errorString() const {return _errorString;}
static Map *create(const QString &path, const Projection &proj, bool *isDir);
2020-12-22 22:32:07 +01:00
private:
2020-12-23 23:05:12 +01:00
class Overlay {
public:
Overlay(const QString &path, const RectC &bbox, double rotation)
: _path(path), _bbox(bbox), _rotation(rotation) {}
2020-12-22 22:32:07 +01:00
const QString &path() const {return _path;}
2020-12-23 23:05:12 +01:00
const RectC &bbox() const {return _bbox;}
qreal rotation() const {return _rotation;}
2020-12-22 22:32:07 +01:00
private:
QString _path;
RectC _bbox;
qreal _rotation;
};
2020-12-22 22:32:07 +01:00
class Tile {
public:
Tile(const Overlay &overlay, QZipReader &zip);
2020-12-22 22:32:07 +01:00
bool operator==(const Tile &other) const
{return _overlay.path() == other._overlay.path();}
bool isValid() const {return _size.isValid();}
const QString &path() const {return _overlay.path();}
qreal rotation() const {return _overlay.rotation();}
const RectC &bbox() const {return _overlay.bbox();}
const Transform &transform() const {return _transform;}
QRectF bounds() const;
qreal resolution() const;
void configure(const Projection &proj);
2020-12-23 23:05:12 +01:00
private:
Overlay _overlay;
QSize _size;
2020-12-23 23:05:12 +01:00
Transform _transform;
2020-12-22 22:32:07 +01:00
};
struct Zoom {
int first;
int last;
Zoom() : first(-1), last(-1) {}
Zoom(int first, int last) : first(first), last(last) {}
};
struct Bounds {
RectC ll;
QRectF xy;
Bounds() {}
Bounds(const RectC &ll, const QRectF &xy) : ll(ll), xy(xy) {}
};
void kml(QXmlStreamReader &reader, QList<Overlay> &overlays);
void document(QXmlStreamReader &reader, QList<Overlay> &overlays);
void folder(QXmlStreamReader &reader, QList<Overlay> &overlays);
void groundOverlay(QXmlStreamReader &reader, QList<Overlay> &overlays);
2020-12-22 22:32:07 +01:00
RectC latLonBox(QXmlStreamReader &reader, double *rotation);
QString icon(QXmlStreamReader &reader);
double number(QXmlStreamReader &reader);
void draw(QPainter *painter, const QRectF &rect, int mapIndex);
bool createTiles(const QList<Overlay> &overlays, QZipReader &zip);
2020-12-22 22:32:07 +01:00
void computeZooms();
void computeBounds();
void computeLLBounds();
QPointF ll2xy(const Coordinates &c, const Transform &transform) const
{return QPointF(transform.proj2img(_projection.ll2xy(c))) / _mapRatio;}
Coordinates xy2ll(const QPointF &p, const Transform &transform) const
{return _projection.xy2ll(transform.img2proj(p * _mapRatio));}
2020-12-22 22:32:07 +01:00
static bool resCmp(const Tile &m1, const Tile &m2);
static bool xCmp(const Tile &m1, const Tile &m2);
static bool yCmp(const Tile &m1, const Tile &m2);
2020-12-22 22:32:07 +01:00
RectC _llbounds;
QList<Tile> _tiles;
2020-12-22 22:32:07 +01:00
QVector<Zoom> _zooms;
QVector<Bounds> _bounds;
int _zoom;
int _mapIndex;
QZipReader *_zip;
2020-12-23 23:05:12 +01:00
qreal _adjust;
Projection _projection;
qreal _mapRatio;
2020-12-22 22:32:07 +01:00
bool _valid;
QString _errorString;
};
#endif // KMZMAP_H