2019-05-10 18:56:19 +02:00
|
|
|
#ifndef IMGMAP_H
|
|
|
|
#define IMGMAP_H
|
|
|
|
|
2022-06-02 18:31:40 +02:00
|
|
|
#include <QtConcurrent>
|
2019-05-10 18:56:19 +02:00
|
|
|
#include "map.h"
|
|
|
|
#include "projection.h"
|
|
|
|
#include "transform.h"
|
2020-02-09 23:24:48 +01:00
|
|
|
#include "IMG/mapdata.h"
|
2022-06-02 18:31:40 +02:00
|
|
|
#include "IMG/rastertile.h"
|
2019-05-10 18:56:19 +02:00
|
|
|
|
|
|
|
|
2022-06-02 18:31:40 +02:00
|
|
|
class IMGMapJob : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
IMGMapJob(const QList<IMG::RasterTile> &tiles)
|
|
|
|
: _tiles(tiles) {}
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
connect(&_watcher, &QFutureWatcher<void>::finished, this,
|
|
|
|
&IMGMapJob::handleFinished);
|
|
|
|
_future = QtConcurrent::map(_tiles, &IMG::RasterTile::render);
|
|
|
|
_watcher.setFuture(_future);
|
|
|
|
}
|
2022-06-02 23:22:34 +02:00
|
|
|
void cancel(bool wait)
|
|
|
|
{
|
|
|
|
_future.cancel();
|
|
|
|
if (wait)
|
|
|
|
_future.waitForFinished();
|
|
|
|
}
|
2022-06-02 18:31:40 +02:00
|
|
|
const QList<IMG::RasterTile> &tiles() const {return _tiles;}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void finished(IMGMapJob *job);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleFinished() {emit finished(this);}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QFutureWatcher<void> _watcher;
|
|
|
|
QFuture<void> _future;
|
|
|
|
QList<IMG::RasterTile> _tiles;
|
|
|
|
};
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
class IMGMap : public Map
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-06-09 00:38:25 +02:00
|
|
|
IMGMap(const QString &fileName, bool GMAP, QObject *parent = 0);
|
2020-04-26 15:46:42 +02:00
|
|
|
~IMGMap() {qDeleteAll(_data);}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2020-04-26 15:46:42 +02:00
|
|
|
QString name() const {return _data.first()->name();}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2020-03-07 19:24:39 +01:00
|
|
|
QRectF bounds() {return _bounds;}
|
2023-05-04 09:38:35 +02:00
|
|
|
RectC llBounds(const Projection &) {return _data.first()->bounds();}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2020-11-15 22:37:49 +01:00
|
|
|
int zoom() const {return _zoom;}
|
|
|
|
void setZoom(int zoom);
|
|
|
|
int zoomFit(const QSize &, const RectC &);
|
|
|
|
int zoomIn();
|
|
|
|
int zoomOut();
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2020-11-15 22:37:49 +01:00
|
|
|
QPointF ll2xy(const Coordinates &c)
|
|
|
|
{return _transform.proj2img(_projection.ll2xy(c));}
|
|
|
|
Coordinates xy2ll(const QPointF &p)
|
|
|
|
{return _projection.xy2ll(_transform.img2proj(p));}
|
2019-05-10 18:56:19 +02:00
|
|
|
|
|
|
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
void load(const Projection &in, const Projection &out, qreal devicelRatio,
|
|
|
|
bool hidpi);
|
2019-07-04 18:18:03 +02:00
|
|
|
void unload();
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
bool isValid() const {return _valid;}
|
|
|
|
QString errorString() const {return _errorString;}
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
static Map* createIMG(const QString &path, bool *isDir);
|
|
|
|
static Map* createGMAP(const QString &path, bool *isDir);
|
2022-04-29 23:16:10 +02:00
|
|
|
|
2022-06-02 18:31:40 +02:00
|
|
|
private slots:
|
|
|
|
void jobFinished(IMGMapJob *job);
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
private:
|
2019-05-29 18:27:11 +02:00
|
|
|
Transform transform(int zoom) const;
|
2019-05-10 18:56:19 +02:00
|
|
|
void updateTransform();
|
2022-06-02 18:31:40 +02:00
|
|
|
bool isRunning(const QString &key) const;
|
|
|
|
void runJob(IMGMapJob *job);
|
|
|
|
void removeJob(IMGMapJob *job);
|
2022-06-02 23:22:34 +02:00
|
|
|
void cancelJobs(bool wait);
|
2019-05-10 18:56:19 +02:00
|
|
|
|
2021-04-10 15:27:40 +02:00
|
|
|
QList<IMG::MapData *> _data;
|
2019-05-10 18:56:19 +02:00
|
|
|
int _zoom;
|
|
|
|
Projection _projection;
|
|
|
|
Transform _transform;
|
2020-03-07 19:24:39 +01:00
|
|
|
QRectF _bounds;
|
2020-04-19 11:36:17 +02:00
|
|
|
RectC _dataBounds;
|
2022-05-10 01:05:30 +02:00
|
|
|
qreal _tileRatio;
|
2019-07-04 18:18:03 +02:00
|
|
|
|
2022-06-02 18:31:40 +02:00
|
|
|
QList<IMGMapJob*> _jobs;
|
|
|
|
|
2019-05-10 18:56:19 +02:00
|
|
|
bool _valid;
|
|
|
|
QString _errorString;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // IMGMAP_H
|