mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-11 04:23:02 +02:00
Compare commits
No commits in common. "6f1f5fd965527d3cc92d351828fe96897982d0d6" and "5525ba6e8ccd98c0405ce77820c20410eb7fac8d" have entirely different histories.
6f1f5fd965
...
5525ba6e8c
@ -9,7 +9,7 @@
|
|||||||
#include "osm.h"
|
#include "osm.h"
|
||||||
#include "mbtilesmap.h"
|
#include "mbtilesmap.h"
|
||||||
|
|
||||||
#define MAX_OVERZOOM 3
|
|
||||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||||
|
|
||||||
static RectC str2bounds(const QString &str)
|
static RectC str2bounds(const QString &str)
|
||||||
@ -79,7 +79,7 @@ bool MBTilesMap::getZooms()
|
|||||||
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
||||||
QSqlQuery query(sql, _db);
|
QSqlQuery query(sql, _db);
|
||||||
if (query.first())
|
if (query.first())
|
||||||
_zooms.append(Zoom(i, i));
|
_zooms.append(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_zooms.size()) {
|
if (!_zooms.size()) {
|
||||||
@ -87,15 +87,6 @@ bool MBTilesMap::getZooms()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_scalable) {
|
|
||||||
for (int i = _zooms.last().base + 1; i <= OSM::ZOOMS.max(); i++) {
|
|
||||||
Zoom z(i, _zooms.last().base);
|
|
||||||
if (z.z - z.base > MAX_OVERZOOM)
|
|
||||||
break;
|
|
||||||
_zooms.append(Zoom(i, _zooms.last().base));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_zi = _zooms.size() - 1;
|
_zi = _zooms.size() - 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -114,7 +105,7 @@ bool MBTilesMap::getBounds()
|
|||||||
} else {
|
} else {
|
||||||
qWarning("%s: missing bounds metadata", qPrintable(path()));
|
qWarning("%s: missing bounds metadata", qPrintable(path()));
|
||||||
|
|
||||||
int z = _zooms.first().z;
|
int z = _zooms.first();
|
||||||
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
||||||
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
||||||
.arg(z);
|
.arg(z);
|
||||||
@ -221,13 +212,13 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTileFormat();
|
|
||||||
if (!getZooms())
|
if (!getZooms())
|
||||||
return;
|
return;
|
||||||
if (!getBounds())
|
if (!getBounds())
|
||||||
return;
|
return;
|
||||||
if (!getTileSize())
|
if (!getTileSize())
|
||||||
return;
|
return;
|
||||||
|
getTileFormat();
|
||||||
getTilePixelRatio();
|
getTilePixelRatio();
|
||||||
getName();
|
getName();
|
||||||
|
|
||||||
@ -275,7 +266,7 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
|||||||
|
|
||||||
_zi = 0;
|
_zi = 0;
|
||||||
for (int i = 1; i < _zooms.size(); i++) {
|
for (int i = 1; i < _zooms.size(); i++) {
|
||||||
if (_zooms.at(i).z > zoom)
|
if (_zooms.at(i) > zoom)
|
||||||
break;
|
break;
|
||||||
_zi = i;
|
_zi = i;
|
||||||
}
|
}
|
||||||
@ -286,7 +277,7 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
|||||||
|
|
||||||
qreal MBTilesMap::resolution(const QRectF &rect)
|
qreal MBTilesMap::resolution(const QRectF &rect)
|
||||||
{
|
{
|
||||||
return OSM::resolution(rect.center(), _zooms.at(_zi).z, _tileSize);
|
return OSM::resolution(rect.center(), _zooms.at(_zi), _tileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MBTilesMap::zoomIn()
|
int MBTilesMap::zoomIn()
|
||||||
@ -385,17 +376,15 @@ void MBTilesMap::cancelJobs(bool wait)
|
|||||||
|
|
||||||
void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
const Zoom &zoom = _zooms.at(_zi);
|
int zoom = _zooms.at(_zi);
|
||||||
unsigned overzoom = zoom.z - zoom.base;
|
qreal scale = OSM::zoom2scale(zoom, _tileSize);
|
||||||
unsigned f = 1U<<overzoom;
|
|
||||||
qreal scale = OSM::zoom2scale(zoom.base, _tileSize * f);
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom.base);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, zoom.base));
|
Coordinates ctl(OSM::tile2ll(tile, zoom));
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||||
int width = ceil(s.width() / (tileSize() * f));
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / (tileSize() * f));
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
QList<MBTile> tiles;
|
QList<MBTile> tiles;
|
||||||
|
|
||||||
@ -403,19 +392,20 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
for (int j = 0; j < height; j++) {
|
for (int j = 0; j < height; j++) {
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
QPoint t(tile.x() + i, tile.y() + j);
|
QPoint t(tile.x() + i, tile.y() + j);
|
||||||
QString key = path() + "-" + QString::number(zoom.z) + "_"
|
QString key = path() + "-" + QString::number(zoom) + "_"
|
||||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||||
|
|
||||||
if (isRunning(key))
|
if (isRunning(key))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize() * f,
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize() * f);
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else {
|
||||||
tiles.append(MBTile(zoom.z, overzoom, _scaledSize, t,
|
tiles.append(MBTile(zoom, _scaledSize, t, tileData(zoom, t),
|
||||||
tileData(zoom.base, t), key));
|
key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,8 +422,8 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize() * f,
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize() * f);
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@ -449,14 +439,14 @@ void MBTilesMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
|||||||
|
|
||||||
QPointF MBTilesMap::ll2xy(const Coordinates &c)
|
QPointF MBTilesMap::ll2xy(const Coordinates &c)
|
||||||
{
|
{
|
||||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi).z, _tileSize);
|
qreal scale = OSM::zoom2scale(_zooms.at(_zi), _tileSize);
|
||||||
QPointF m = OSM::ll2m(c);
|
QPointF m = OSM::ll2m(c);
|
||||||
return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio();
|
return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates MBTilesMap::xy2ll(const QPointF &p)
|
Coordinates MBTilesMap::xy2ll(const QPointF &p)
|
||||||
{
|
{
|
||||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi).z, _tileSize);
|
qreal scale = OSM::zoom2scale(_zooms.at(_zi), _tileSize);
|
||||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||||
* coordinatesRatio());
|
* coordinatesRatio());
|
||||||
}
|
}
|
||||||
@ -470,11 +460,3 @@ Map *MBTilesMap::create(const QString &path, const Projection &proj, bool *isDir
|
|||||||
|
|
||||||
return new MBTilesMap(path);
|
return new MBTilesMap(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG
|
|
||||||
QDebug operator<<(QDebug dbg, const MBTilesMap::Zoom &zoom)
|
|
||||||
{
|
|
||||||
dbg.nospace() << "Zoom(" << zoom.z << ", " << zoom.base << ")";
|
|
||||||
return dbg.space();
|
|
||||||
}
|
|
||||||
#endif // QT_NO_DEBUG
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef MBTILESMAP_H
|
#ifndef MBTILESMAP_H
|
||||||
#define MBTILESMAP_H
|
#define MBTILESMAP_H
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QSqlDatabase>
|
#include <QSqlDatabase>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
@ -13,21 +12,17 @@
|
|||||||
class MBTile
|
class MBTile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MBTile(int zoom, int overzoom, int scaledSize, const QPoint &xy,
|
MBTile(int zoom, int scaledSize, const QPoint &xy, const QByteArray &data,
|
||||||
const QByteArray &data, const QString &key) : _zoom(zoom),
|
const QString &key) : _zoom(zoom), _scaledSize(scaledSize), _xy(xy),
|
||||||
_overzoom(overzoom), _scaledSize(scaledSize), _xy(xy), _data(data),
|
_data(data), _key(key) {}
|
||||||
_key(key) {}
|
|
||||||
|
|
||||||
const QPoint &xy() const {return _xy;}
|
const QPoint &xy() const {return _xy;}
|
||||||
const QString &key() const {return _key;}
|
const QString &key() const {return _key;}
|
||||||
const QPixmap &pixmap() const {return _pixmap;}
|
const QPixmap &pixmap() const {return _pixmap;}
|
||||||
|
|
||||||
void load() {
|
void load() {
|
||||||
QByteArray format(_overzoom
|
|
||||||
? QByteArray::number(_zoom) + ';' + QByteArray::number(_overzoom)
|
|
||||||
: QByteArray::number(_zoom));
|
|
||||||
QBuffer buffer(&_data);
|
QBuffer buffer(&_data);
|
||||||
QImageReader reader(&buffer, format);
|
QImageReader reader(&buffer, QByteArray::number(_zoom));
|
||||||
if (_scaledSize)
|
if (_scaledSize)
|
||||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||||
_pixmap = QPixmap::fromImage(reader.read());
|
_pixmap = QPixmap::fromImage(reader.read());
|
||||||
@ -35,7 +30,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int _zoom;
|
int _zoom;
|
||||||
int _overzoom;
|
|
||||||
int _scaledSize;
|
int _scaledSize;
|
||||||
QPoint _xy;
|
QPoint _xy;
|
||||||
QByteArray _data;
|
QByteArray _data;
|
||||||
@ -114,14 +108,6 @@ private slots:
|
|||||||
void jobFinished(MBTilesMapJob *job);
|
void jobFinished(MBTilesMapJob *job);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Zoom {
|
|
||||||
Zoom() : z(-1), base(-1) {}
|
|
||||||
Zoom(int z, int base) : z(z), base(base) {}
|
|
||||||
|
|
||||||
int z;
|
|
||||||
int base;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool getMinZoom(int &zoom);
|
bool getMinZoom(int &zoom);
|
||||||
bool getMaxZoom(int &zoom);
|
bool getMaxZoom(int &zoom);
|
||||||
bool getZooms();
|
bool getZooms();
|
||||||
@ -140,13 +126,11 @@ private:
|
|||||||
void removeJob(MBTilesMapJob *job);
|
void removeJob(MBTilesMapJob *job);
|
||||||
void cancelJobs(bool wait);
|
void cancelJobs(bool wait);
|
||||||
|
|
||||||
friend QDebug operator<<(QDebug dbg, const Zoom &zoom);
|
|
||||||
|
|
||||||
QSqlDatabase _db;
|
QSqlDatabase _db;
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
RectC _bounds;
|
RectC _bounds;
|
||||||
QVector<Zoom> _zooms;
|
QVector<int> _zooms;
|
||||||
int _zi;
|
int _zi;
|
||||||
int _tileSize;
|
int _tileSize;
|
||||||
qreal _mapRatio, _tileRatio;
|
qreal _mapRatio, _tileRatio;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user