2017-03-18 01:30:31 +01:00
|
|
|
#ifndef ONLINEMAP_H
|
|
|
|
#define ONLINEMAP_H
|
|
|
|
|
2023-12-11 18:54:46 +01:00
|
|
|
#include <QImageReader>
|
|
|
|
#include <QPixmap>
|
2023-12-11 20:11:16 +01:00
|
|
|
#include <QtConcurrent>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "common/range.h"
|
2018-01-28 22:56:08 +01:00
|
|
|
#include "common/rectc.h"
|
2017-03-18 01:30:31 +01:00
|
|
|
#include "map.h"
|
2018-02-20 23:37:19 +01:00
|
|
|
#include "tileloader.h"
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2023-12-11 20:11:16 +01:00
|
|
|
class OnlineMapTile
|
2023-12-11 18:54:46 +01:00
|
|
|
{
|
|
|
|
public:
|
2023-12-11 20:11:16 +01:00
|
|
|
OnlineMapTile(const QPoint &xy, const QString &file, int zoom, int overzoom,
|
|
|
|
int scaledSize, const QString &key) : _zoom(zoom), _overzoom(overzoom),
|
|
|
|
_scaledSize(scaledSize), _xy(xy), _file(file), _key(key) {}
|
2023-12-11 18:54:46 +01:00
|
|
|
|
|
|
|
void load()
|
|
|
|
{
|
|
|
|
QByteArray format(_overzoom
|
|
|
|
? QByteArray::number(_zoom) + ';' + QByteArray::number(_overzoom)
|
|
|
|
: QByteArray::number(_zoom));
|
|
|
|
QImageReader reader(_file, format);
|
|
|
|
if (_scaledSize)
|
|
|
|
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
|
|
|
_pixmap = QPixmap::fromImage(reader.read());
|
|
|
|
}
|
|
|
|
|
|
|
|
const QPoint &xy() const {return _xy;}
|
|
|
|
const QPixmap &pixmap() const {return _pixmap;}
|
2023-12-11 20:11:16 +01:00
|
|
|
const QString &key() const {return _key;}
|
2023-12-11 18:54:46 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _zoom;
|
|
|
|
int _overzoom;
|
|
|
|
int _scaledSize;
|
2023-12-11 20:11:16 +01:00
|
|
|
QPoint _xy;
|
|
|
|
QString _file;
|
|
|
|
QString _key;
|
2023-12-11 18:54:46 +01:00
|
|
|
QPixmap _pixmap;
|
|
|
|
};
|
|
|
|
|
2023-12-11 20:11:16 +01:00
|
|
|
class OnlineMapJob : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
OnlineMapJob(const QList<OnlineMapTile> &tiles) : _tiles(tiles) {}
|
|
|
|
|
|
|
|
void run()
|
|
|
|
{
|
|
|
|
connect(&_watcher, &QFutureWatcher<void>::finished, this,
|
|
|
|
&OnlineMapJob::handleFinished);
|
|
|
|
_future = QtConcurrent::map(_tiles, &OnlineMapTile::load);
|
|
|
|
_watcher.setFuture(_future);
|
|
|
|
}
|
|
|
|
void cancel(bool wait)
|
|
|
|
{
|
|
|
|
_future.cancel();
|
|
|
|
if (wait)
|
|
|
|
_future.waitForFinished();
|
|
|
|
}
|
|
|
|
const QList<OnlineMapTile> &tiles() const {return _tiles;}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void finished(OnlineMapJob *job);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleFinished() {emit finished(this);}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QFutureWatcher<void> _watcher;
|
|
|
|
QFuture<void> _future;
|
|
|
|
QList<OnlineMapTile> _tiles;
|
|
|
|
};
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
class OnlineMap : public Map
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-12-02 23:58:11 +01:00
|
|
|
OnlineMap(const QString &fileName, const QString &name, const QString &url,
|
|
|
|
const Range &zooms, const RectC &bounds, qreal tileRatio,
|
2023-05-13 15:01:35 +02:00
|
|
|
const QList<HTTPHeader> &headers, int tileSize, bool scalable,
|
2020-12-02 23:58:11 +01:00
|
|
|
bool invertY, bool quadTiles, QObject *parent = 0);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
QString name() const {return _name;}
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
QRectF bounds();
|
2023-09-25 18:20:37 +02:00
|
|
|
RectC llBounds() {return _bounds;}
|
2018-06-30 12:14:58 +02:00
|
|
|
qreal resolution(const QRectF &rect);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-02-28 22:19:46 +01:00
|
|
|
int zoom() const {return _zoom;}
|
2018-04-28 22:18:11 +02:00
|
|
|
void setZoom(int zoom) {_zoom = zoom;}
|
2018-04-16 20:26:10 +02:00
|
|
|
int zoomFit(const QSize &size, const RectC &rect);
|
2018-02-28 22:19:46 +01:00
|
|
|
int zoomIn();
|
|
|
|
int zoomOut();
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-07-13 09:51:41 +02:00
|
|
|
QPointF ll2xy(const Coordinates &c);
|
|
|
|
Coordinates xy2ll(const QPointF &p);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-08-23 20:26:10 +02:00
|
|
|
void draw(QPainter *painter, const QRectF &rect, Flags flags);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2023-05-04 09:38:35 +02:00
|
|
|
void load(const Projection &in, const Projection &out, qreal deviceRatio,
|
|
|
|
bool hidpi);
|
2023-12-11 20:11:16 +01:00
|
|
|
void unload();
|
2023-12-11 18:54:46 +01:00
|
|
|
void clearCache();
|
2017-10-04 23:15:39 +02:00
|
|
|
|
2023-12-11 20:11:16 +01:00
|
|
|
private slots:
|
|
|
|
void jobFinished(OnlineMapJob *job);
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
private:
|
2017-09-09 12:33:43 +02:00
|
|
|
int limitZoom(int zoom) const;
|
2018-08-18 21:06:36 +02:00
|
|
|
qreal tileSize() const;
|
|
|
|
qreal coordinatesRatio() const;
|
|
|
|
qreal imageRatio() const;
|
2023-12-11 18:54:46 +01:00
|
|
|
QPoint tileCoordinates(int x, int y, int zoom);
|
|
|
|
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
2023-12-11 20:11:16 +01:00
|
|
|
bool isRunning(const QString &key) const;
|
|
|
|
void runJob(OnlineMapJob *job);
|
|
|
|
void removeJob(OnlineMapJob *job);
|
|
|
|
void cancelJobs(bool wait);
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2018-04-27 19:31:27 +02:00
|
|
|
TileLoader *_tileLoader;
|
2017-03-18 01:30:31 +01:00
|
|
|
QString _name;
|
2018-01-28 22:56:08 +01:00
|
|
|
Range _zooms;
|
|
|
|
RectC _bounds;
|
|
|
|
int _zoom;
|
2018-11-17 10:10:35 +01:00
|
|
|
int _tileSize;
|
2023-12-11 18:54:46 +01:00
|
|
|
int _base;
|
2023-05-04 09:38:35 +02:00
|
|
|
qreal _mapRatio, _tileRatio;
|
2018-11-15 00:38:03 +01:00
|
|
|
bool _scalable;
|
2023-12-11 18:54:46 +01:00
|
|
|
int _scaledSize;
|
2018-09-22 13:32:54 +02:00
|
|
|
bool _invertY;
|
2023-12-11 20:11:16 +01:00
|
|
|
|
|
|
|
QList<OnlineMapJob*> _jobs;
|
2017-03-18 01:30:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ONLINEMAP_H
|