2021-04-10 15:27:40 +02:00
|
|
|
#ifndef MAPSFORGEMAP_H
|
|
|
|
#define MAPSFORGEMAP_H
|
|
|
|
|
|
|
|
#include <QtConcurrent>
|
|
|
|
#include "mapsforge/mapdata.h"
|
|
|
|
#include "mapsforge/rastertile.h"
|
|
|
|
#include "projection.h"
|
|
|
|
#include "transform.h"
|
|
|
|
#include "map.h"
|
|
|
|
|
|
|
|
|
|
|
|
class MapsforgeMapJob : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-09-17 23:22:32 +02:00
|
|
|
MapsforgeMapJob(const QList<Mapsforge::RasterTile> &tiles)
|
|
|
|
: _tiles(tiles) {}
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
2021-09-17 23:22:32 +02:00
|
|
|
connect(&_watcher, &QFutureWatcher<void>::finished, this,
|
|
|
|
&MapsforgeMapJob::handleFinished);
|
2021-04-10 15:27:40 +02:00
|
|
|
_future = QtConcurrent::map(_tiles, &Mapsforge::RasterTile::render);
|
|
|
|
_watcher.setFuture(_future);
|
|
|
|
}
|
2023-04-22 17:28:32 +02:00
|
|
|
void cancel(bool wait)
|
|
|
|
{
|
|
|
|
_future.cancel();
|
|
|
|
if (wait)
|
|
|
|
_future.waitForFinished();
|
|
|
|
}
|
2021-09-16 22:52:46 +02:00
|
|
|
const QList<Mapsforge::RasterTile> &tiles() const {return _tiles;}
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
signals:
|
2021-09-16 22:52:46 +02:00
|
|
|
void finished(MapsforgeMapJob *job);
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
private slots:
|
2021-09-16 22:52:46 +02:00
|
|
|
void handleFinished() {emit finished(this);}
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
QFutureWatcher<void> _watcher;
|
|
|
|
QFuture<void> _future;
|
|
|
|
QList<Mapsforge::RasterTile> _tiles;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MapsforgeMap : public Map
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
MapsforgeMap(const QString &fileName, QObject *parent = 0);
|
|
|
|
|
|
|
|
QRectF bounds() {return _bounds;}
|
2023-05-04 09:38:35 +02:00
|
|
|
RectC llBounds(const Projection &) {return _data.bounds();}
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
int zoom() const {return _zoom;}
|
|
|
|
void setZoom(int zoom);
|
|
|
|
int zoomFit(const QSize &size, const RectC &rect);
|
|
|
|
int zoomIn();
|
|
|
|
int zoomOut();
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
void load(const Projection &in, const Projection &out, qreal deviceRatio,
|
|
|
|
bool hidpi);
|
2021-04-10 15:27:40 +02:00
|
|
|
void unload();
|
|
|
|
|
|
|
|
QPointF ll2xy(const Coordinates &c)
|
|
|
|
{return _transform.proj2img(_projection.ll2xy(c));}
|
|
|
|
Coordinates xy2ll(const QPointF &p)
|
|
|
|
{return _projection.xy2ll(_transform.img2proj(p));}
|
|
|
|
|
|
|
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
|
|
|
|
|
|
|
bool isValid() const {return _data.isValid();}
|
|
|
|
QString errorString() const {return _data.errorString();}
|
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
static Map *create(const QString &path, bool *isMap);
|
2022-04-29 23:16:10 +02:00
|
|
|
|
2021-04-10 15:27:40 +02:00
|
|
|
private slots:
|
2021-09-16 22:52:46 +02:00
|
|
|
void jobFinished(MapsforgeMapJob *job);
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
private:
|
2021-09-17 23:22:32 +02:00
|
|
|
QString key(int zoom, const QPoint &xy) const;
|
2021-04-10 15:27:40 +02:00
|
|
|
Transform transform(int zoom) const;
|
|
|
|
void updateTransform();
|
2021-09-16 22:52:46 +02:00
|
|
|
bool isRunning(int zoom, const QPoint &xy) const;
|
|
|
|
void runJob(MapsforgeMapJob *job);
|
|
|
|
void removeJob(MapsforgeMapJob *job);
|
2023-04-22 17:28:32 +02:00
|
|
|
void cancelJobs(bool wait);
|
2021-04-10 15:27:40 +02:00
|
|
|
|
|
|
|
Mapsforge::MapData _data;
|
2023-04-22 17:28:32 +02:00
|
|
|
Mapsforge::Style _style;
|
2021-04-10 15:27:40 +02:00
|
|
|
int _zoom;
|
|
|
|
|
|
|
|
Projection _projection;
|
|
|
|
Transform _transform;
|
|
|
|
QRectF _bounds;
|
2021-04-18 12:20:07 +02:00
|
|
|
qreal _tileRatio;
|
2021-04-10 15:27:40 +02:00
|
|
|
|
2021-09-16 22:52:46 +02:00
|
|
|
QList<MapsforgeMapJob*> _jobs;
|
2021-04-10 15:27:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MAPSFORGEMAP_H
|