mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-12-05 00:39:09 +01:00
Compare commits
No commits in common. "95d354f10c42af82aed953719d8c9222e6ef5191" and "bbc03ae59fc5fff64889d916098ac506526bd93d" have entirely different histories.
95d354f10c
...
bbc03ae59f
@ -347,14 +347,20 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
Q_UNUSED(flags);
|
Q_UNUSED(flags);
|
||||||
const Zoom &z = _zooms.at(_zoom);
|
const Zoom &z = _zooms.at(_zoom);
|
||||||
qreal scale = OSM::zoom2scale(z.zoom, z.tileSize);
|
qreal scale = OSM::zoom2scale(z.zoom, z.tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * _mapRatio, z.zoom);
|
-rect.topLeft().y() * scale) * _mapRatio, z.zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, z.zoom));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<RenderTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
@ -365,13 +371,15 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else {
|
||||||
tiles.append(RenderTile(t, tileData(t), key));
|
tiles.append(RenderTile(t, tileData(t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
@ -384,8 +392,9 @@ void AQMMap::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(),
|
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,14 +243,20 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
Q_UNUSED(flags);
|
Q_UNUSED(flags);
|
||||||
const Zoom &z = _zooms.at(_zi);
|
const Zoom &z = _zooms.at(_zi);
|
||||||
qreal scale = OSM::zoom2scale(z.level, _tileSize);
|
qreal scale = OSM::zoom2scale(z.level, _tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * _mapRatio, z.level);
|
-rect.topLeft().y() * scale) * _mapRatio, z.level);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, z.level));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<RenderTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
@ -261,13 +267,15 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else {
|
||||||
tiles.append(RenderTile(t, tileData(t), key));
|
tiles.append(RenderTile(t, tileData(t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
@ -280,8 +288,9 @@ void GEMFMap::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(),
|
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||||
tl.y() + (mt.xy().y() - tile.y())* tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,170 +12,6 @@
|
|||||||
|
|
||||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||||
|
|
||||||
static RectC str2bounds(const QString &str)
|
|
||||||
{
|
|
||||||
QStringList list(str.split(','));
|
|
||||||
if (list.size() != 4)
|
|
||||||
return RectC();
|
|
||||||
|
|
||||||
bool lok, rok, bok, tok;
|
|
||||||
double left = list.at(0).toDouble(&lok);
|
|
||||||
double bottom = list.at(1).toDouble(&bok);
|
|
||||||
double right = list.at(2).toDouble(&rok);
|
|
||||||
double top = list.at(3).toDouble(&tok);
|
|
||||||
|
|
||||||
return (lok && rok && bok && tok)
|
|
||||||
? RectC(Coordinates(left, top), Coordinates(right, bottom))
|
|
||||||
: RectC();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MBTilesMap::getMinZoom(int &zoom)
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'minzoom'", _db);
|
|
||||||
|
|
||||||
if (query.first()) {
|
|
||||||
bool ok;
|
|
||||||
zoom = query.value(0).toString().toInt(&ok);
|
|
||||||
if (!ok || zoom < 0) {
|
|
||||||
_errorString = "Invalid minzoom metadata";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qWarning("%s: missing minzoom metadata", qPrintable(path()));
|
|
||||||
zoom = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MBTilesMap::getMaxZoom(int &zoom)
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'maxzoom'", _db);
|
|
||||||
|
|
||||||
if (query.first()) {
|
|
||||||
bool ok;
|
|
||||||
zoom = query.value(0).toString().toInt(&ok);
|
|
||||||
if (!ok && zoom < 0) {
|
|
||||||
_errorString = "Invalid maxzoom metadata";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qWarning("%s: missing maxzoom metadata", qPrintable(path()));
|
|
||||||
zoom = 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MBTilesMap::getZooms()
|
|
||||||
{
|
|
||||||
int minZoom, maxZoom;
|
|
||||||
|
|
||||||
if (!(getMinZoom(minZoom) && getMaxZoom(maxZoom)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (int i = minZoom; i <= maxZoom; i++) {
|
|
||||||
QString sql = QString("SELECT zoom_level FROM tiles"
|
|
||||||
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
|
||||||
QSqlQuery query(sql, _db);
|
|
||||||
if (query.first())
|
|
||||||
_zooms.append(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
_zi = _zooms.size() - 1;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MBTilesMap::getBounds()
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'bounds'", _db);
|
|
||||||
if (query.first()) {
|
|
||||||
RectC b(str2bounds(query.value(0).toString()));
|
|
||||||
if (!b.isValid()) {
|
|
||||||
_errorString = "Invalid bounds metadata";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_bounds = b;
|
|
||||||
} else {
|
|
||||||
qWarning("%s: missing bounds metadata", qPrintable(path()));
|
|
||||||
|
|
||||||
int z = _zooms.first();
|
|
||||||
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
|
||||||
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
|
||||||
.arg(z);
|
|
||||||
QSqlQuery query(sql, _db);
|
|
||||||
query.first();
|
|
||||||
|
|
||||||
int minX = qMin((1<<z) - 1, qMax(0, query.value(0).toInt()));
|
|
||||||
int minY = qMin((1<<z) - 1, qMax(0, query.value(1).toInt()));
|
|
||||||
int maxX = qMin((1<<z) - 1, qMax(0, query.value(2).toInt())) + 1;
|
|
||||||
int maxY = qMin((1<<z) - 1, qMax(0, query.value(3).toInt())) + 1;
|
|
||||||
Coordinates tl(OSM::tile2ll(QPoint(minX, maxY), z));
|
|
||||||
Coordinates br(OSM::tile2ll(QPoint(maxX, minY), z));
|
|
||||||
// Workaround of broken zoom levels 0 and 1 due to numerical instability
|
|
||||||
tl.rlat() = qMin(tl.lat(), OSM::BOUNDS.top());
|
|
||||||
br.rlat() = qMax(br.lat(), OSM::BOUNDS.bottom());
|
|
||||||
_bounds = RectC(tl, br);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MBTilesMap::getTileSize()
|
|
||||||
{
|
|
||||||
QString sql("SELECT tile_data FROM tiles LIMIT 1");
|
|
||||||
QSqlQuery query(sql, _db);
|
|
||||||
query.first();
|
|
||||||
|
|
||||||
QByteArray data = query.value(0).toByteArray();
|
|
||||||
QBuffer buffer(&data);
|
|
||||||
QImageReader reader(&buffer);
|
|
||||||
QSize tileSize(reader.size());
|
|
||||||
|
|
||||||
if (!tileSize.isValid() || tileSize.width() != tileSize.height()) {
|
|
||||||
_errorString = "Unsupported/invalid tile images";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tileSize = tileSize.width();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MBTilesMap::getTileFormat()
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'format'", _db);
|
|
||||||
if (query.first()) {
|
|
||||||
if (query.value(0).toString() == "pbf")
|
|
||||||
_scalable = true;
|
|
||||||
} else
|
|
||||||
qWarning("%s: missing tiles format metadata", qPrintable(path()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MBTilesMap::getTilePixelRatio()
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'tilepixelratio'",
|
|
||||||
_db);
|
|
||||||
if (query.first()) {
|
|
||||||
bool ok;
|
|
||||||
double ratio = query.value(0).toString().toDouble(&ok);
|
|
||||||
if (ok)
|
|
||||||
_tileRatio = ratio;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MBTilesMap::getName()
|
|
||||||
{
|
|
||||||
QSqlQuery query("SELECT value FROM metadata WHERE name = 'name'", _db);
|
|
||||||
if (query.first())
|
|
||||||
_name = query.value(0).toString();
|
|
||||||
else {
|
|
||||||
qWarning("%s: missing map name", qPrintable(path()));
|
|
||||||
_name = Util::file2name(path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||||
: Map(fileName, parent), _mapRatio(1.0), _tileRatio(1.0), _scalable(false),
|
: Map(fileName, parent), _mapRatio(1.0), _tileRatio(1.0), _scalable(false),
|
||||||
_scaledSize(0), _valid(false)
|
_scaledSize(0), _valid(false)
|
||||||
@ -206,15 +42,90 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getZooms())
|
{
|
||||||
|
QSqlQuery query("SELECT DISTINCT zoom_level FROM tiles"
|
||||||
|
" ORDER BY zoom_level", _db);
|
||||||
|
while (query.next())
|
||||||
|
_zooms.append(query.value(0).toInt());
|
||||||
|
if (_zooms.isEmpty()) {
|
||||||
|
_errorString = "Empty tile set";
|
||||||
return;
|
return;
|
||||||
if (!getBounds())
|
}
|
||||||
|
if (_zooms.first() < 0) {
|
||||||
|
_errorString = "Invalid zoom levels";
|
||||||
return;
|
return;
|
||||||
if (!getTileSize())
|
}
|
||||||
|
}
|
||||||
|
_zi = _zooms.size() - 1;
|
||||||
|
|
||||||
|
{
|
||||||
|
int z = _zooms.first();
|
||||||
|
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
||||||
|
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
||||||
|
.arg(z);
|
||||||
|
QSqlQuery query(sql, _db);
|
||||||
|
query.first();
|
||||||
|
|
||||||
|
int minX = qMin((1<<z) - 1, qMax(0, query.value(0).toInt()));
|
||||||
|
int minY = qMin((1<<z) - 1, qMax(0, query.value(1).toInt()));
|
||||||
|
int maxX = qMin((1<<z) - 1, qMax(0, query.value(2).toInt())) + 1;
|
||||||
|
int maxY = qMin((1<<z) - 1, qMax(0, query.value(3).toInt())) + 1;
|
||||||
|
Coordinates tl(OSM::tile2ll(QPoint(minX, maxY), z));
|
||||||
|
Coordinates br(OSM::tile2ll(QPoint(maxX, minY), z));
|
||||||
|
// Workaround of broken zoom levels 0 and 1 due to numerical instability
|
||||||
|
tl.rlat() = qMin(tl.lat(), OSM::BOUNDS.top());
|
||||||
|
br.rlat() = qMax(br.lat(), OSM::BOUNDS.bottom());
|
||||||
|
_bounds = RectC(tl, br);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QString sql = QString("SELECT tile_data FROM tiles LIMIT 1");
|
||||||
|
QSqlQuery query(sql, _db);
|
||||||
|
query.first();
|
||||||
|
|
||||||
|
QByteArray data = query.value(0).toByteArray();
|
||||||
|
QBuffer buffer(&data);
|
||||||
|
QImageReader reader(&buffer);
|
||||||
|
QSize tileSize(reader.size());
|
||||||
|
|
||||||
|
if (!tileSize.isValid() || tileSize.width() != tileSize.height()) {
|
||||||
|
_errorString = "Unsupported/invalid tile images";
|
||||||
return;
|
return;
|
||||||
getTileFormat();
|
}
|
||||||
getTilePixelRatio();
|
_tileSize = tileSize.width();
|
||||||
getName();
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QSqlQuery query("SELECT value FROM metadata WHERE name = 'format'", _db);
|
||||||
|
if (query.first()) {
|
||||||
|
if (query.value(0).toString() == "pbf")
|
||||||
|
_scalable = true;
|
||||||
|
} else
|
||||||
|
qWarning("%s: missing tiles format", qPrintable(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QSqlQuery query("SELECT value FROM metadata WHERE name = 'name'", _db);
|
||||||
|
if (query.first())
|
||||||
|
_name = query.value(0).toString();
|
||||||
|
else {
|
||||||
|
qWarning("%s: missing map name", qPrintable(fileName));
|
||||||
|
_name = Util::file2name(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QSqlQuery query(
|
||||||
|
"SELECT value FROM metadata WHERE name = 'tilepixelratio'", _db);
|
||||||
|
if (query.first()) {
|
||||||
|
bool ok;
|
||||||
|
_tileRatio = query.value(0).toString().toDouble(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
_errorString = "Invalid tile pixel ratio";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_db.close();
|
_db.close();
|
||||||
|
|
||||||
@ -370,16 +281,23 @@ 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)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(flags);
|
||||||
int zoom = _zooms.at(_zi);
|
int zoom = _zooms.at(_zi);
|
||||||
qreal scale = OSM::zoom2scale(zoom, _tileSize);
|
qreal scale = OSM::zoom2scale(zoom, _tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, zoom));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
|
|
||||||
QList<MBTile> tiles;
|
QList<MBTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
@ -393,8 +311,9 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else {
|
} else {
|
||||||
tiles.append(MBTile(zoom, _scaledSize, t, tileData(zoom, t),
|
tiles.append(MBTile(zoom, _scaledSize, t, tileData(zoom, t),
|
||||||
@ -416,8 +335,9 @@ 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(),
|
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -110,14 +110,6 @@ private slots:
|
|||||||
void jobFinished(MBTilesMapJob *job);
|
void jobFinished(MBTilesMapJob *job);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool getMinZoom(int &zoom);
|
|
||||||
bool getMaxZoom(int &zoom);
|
|
||||||
bool getZooms();
|
|
||||||
bool getBounds();
|
|
||||||
bool getTileSize();
|
|
||||||
void getTileFormat();
|
|
||||||
void getTilePixelRatio();
|
|
||||||
void getName();
|
|
||||||
qreal tileSize() const;
|
qreal tileSize() const;
|
||||||
qreal coordinatesRatio() const;
|
qreal coordinatesRatio() const;
|
||||||
qreal imageRatio() const;
|
qreal imageRatio() const;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <QtCore>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
@ -100,11 +101,15 @@ qreal OnlineMap::tileSize() const
|
|||||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||||
{
|
{
|
||||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
@ -122,10 +127,9 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
for (int i = 0; i < tiles.count(); i++) {
|
for (int i = 0; i < tiles.count(); i++) {
|
||||||
FetchTile &t = tiles[i];
|
FetchTile &t = tiles[i];
|
||||||
QPointF tp(tl.x() + (t.xy().x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.xy().x() - tile.x()) * tileSize(),
|
||||||
tl.y() + ((_invertY
|
qMax(tl.y(), b.top()) + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 :
|
||||||
? (1<<_zoom) - t.xy().y() - 1
|
t.xy().y()) - tile.y()) * tileSize());
|
||||||
: t.xy().y()) - tile.y()) * tileSize());
|
|
||||||
|
|
||||||
if (!t.pixmap().isNull()) {
|
if (!t.pixmap().isNull()) {
|
||||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||||
|
@ -238,14 +238,20 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(flags);
|
Q_UNUSED(flags);
|
||||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * _mapRatio, _zoom);
|
-rect.topLeft().y() * scale) * _mapRatio, _zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<RenderTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
@ -256,13 +262,15 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else {
|
||||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
@ -275,8 +283,9 @@ void OsmdroidMap::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(),
|
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,14 +185,20 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(flags);
|
Q_UNUSED(flags);
|
||||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||||
|
QRectF b(bounds());
|
||||||
|
|
||||||
|
|
||||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||||
-rect.topLeft().y() * scale) * _mapRatio, _zoom);
|
-rect.topLeft().y() * scale) * _mapRatio, _zoom);
|
||||||
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
QPointF tl(floor(rect.left() / tileSize())
|
||||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
||||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
|
||||||
|
QSizeF s(qMin(rect.right() - tl.x(), b.width()),
|
||||||
|
qMin(rect.bottom() - tl.y(), b.height()));
|
||||||
int width = ceil(s.width() / tileSize());
|
int width = ceil(s.width() / tileSize());
|
||||||
int height = ceil(s.height() / tileSize());
|
int height = ceil(s.height() / tileSize());
|
||||||
|
|
||||||
|
|
||||||
QList<RenderTile> tiles;
|
QList<RenderTile> tiles;
|
||||||
|
|
||||||
for (int i = 0; i < width; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
@ -203,13 +209,15 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
||||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
} else
|
} else {
|
||||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
@ -222,8 +230,9 @@ void SqliteMap::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(),
|
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
||||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
||||||
|
* tileSize());
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user