mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-12-03 16:09:08 +01:00
Compare commits
3 Commits
bbc03ae59f
...
95d354f10c
Author | SHA1 | Date | |
---|---|---|---|
95d354f10c | |||
aedbc99a6c | |||
04f9457085 |
@ -347,20 +347,14 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, z.zoom));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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++) {
|
||||||
@ -371,13 +365,11 @@ 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(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
* 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));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,9 +384,8 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||||
* tileSize());
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,20 +243,14 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, z.level));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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++) {
|
||||||
@ -267,13 +261,11 @@ 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(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
* 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));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,9 +280,8 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
tl.y() + (mt.xy().y() - tile.y())* tileSize());
|
||||||
* tileSize());
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,170 @@
|
|||||||
|
|
||||||
#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)
|
||||||
@ -42,90 +206,15 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (!getZooms())
|
||||||
QSqlQuery query("SELECT DISTINCT zoom_level FROM tiles"
|
return;
|
||||||
" ORDER BY zoom_level", _db);
|
if (!getBounds())
|
||||||
while (query.next())
|
return;
|
||||||
_zooms.append(query.value(0).toInt());
|
if (!getTileSize())
|
||||||
if (_zooms.isEmpty()) {
|
return;
|
||||||
_errorString = "Empty tile set";
|
getTileFormat();
|
||||||
return;
|
getTilePixelRatio();
|
||||||
}
|
getName();
|
||||||
if (_zooms.first() < 0) {
|
|
||||||
_errorString = "Invalid zoom levels";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_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;
|
|
||||||
}
|
|
||||||
_tileSize = tileSize.width();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
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();
|
||||||
|
|
||||||
@ -281,23 +370,16 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, zoom));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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++) {
|
||||||
@ -311,9 +393,8 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (QPixmapCache::find(key, &pm)) {
|
if (QPixmapCache::find(key, &pm)) {
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
* 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),
|
||||||
@ -335,9 +416,8 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||||
* tileSize());
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -110,6 +110,14 @@ 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,4 +1,3 @@
|
|||||||
#include <QtCore>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include "common/rectc.h"
|
#include "common/rectc.h"
|
||||||
@ -101,15 +100,11 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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());
|
||||||
|
|
||||||
@ -127,9 +122,10 @@ 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(qMax(tl.x(), b.left()) + (t.xy().x() - tile.x()) * tileSize(),
|
QPointF tp(tl.x() + (t.xy().x() - tile.x()) * tileSize(),
|
||||||
qMax(tl.y(), b.top()) + ((_invertY ? (1<<_zoom) - t.xy().y() - 1 :
|
tl.y() + ((_invertY
|
||||||
t.xy().y()) - tile.y()) * tileSize());
|
? (1<<_zoom) - t.xy().y() - 1
|
||||||
|
: t.xy().y()) - tile.y()) * tileSize());
|
||||||
|
|
||||||
if (!t.pixmap().isNull()) {
|
if (!t.pixmap().isNull()) {
|
||||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||||
|
@ -238,20 +238,14 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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++) {
|
||||||
@ -262,13 +256,11 @@ 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(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
* 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));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,9 +275,8 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||||
* tileSize());
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,20 +185,14 @@ 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);
|
||||||
QPointF tl(floor(rect.left() / tileSize())
|
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
||||||
* tileSize(), floor(rect.top() / tileSize()) * tileSize());
|
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||||
|
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++) {
|
||||||
@ -209,13 +203,11 @@ 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(qMax(tl.x(), b.left()) + (t.x() - tile.x())
|
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
|
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||||
* 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));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,9 +222,8 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
|||||||
|
|
||||||
QPixmapCache::insert(mt.key(), pm);
|
QPixmapCache::insert(mt.key(), pm);
|
||||||
|
|
||||||
QPointF tp(qMax(tl.x(), b.left()) + (mt.xy().x() - tile.x())
|
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||||
* tileSize(), qMax(tl.y(), b.top()) + (mt.xy().y() - tile.y())
|
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||||
* tileSize());
|
|
||||||
drawTile(painter, pm, tp);
|
drawTile(painter, pm, tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user