mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-07-10 01:04:27 +02:00
Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
c1c8f6303c | |||
5fcc27c176 | |||
77e9fae19d | |||
148fc76d5a | |||
6f1f5fd965 | |||
58cd2a826d | |||
5525ba6e8c | |||
63d3558b14 | |||
eee4f31369 | |||
bac55e317b | |||
029f36a5da | |||
d3b62df42c | |||
48e1900958 | |||
00665647b1 | |||
4605a6f1f6 | |||
84d8051f6a | |||
c4bd3d39d1 | |||
9fffb8b20d | |||
6d03834167 | |||
cbca92513b | |||
3104e50727 | |||
e504de37c3 | |||
312231b8b2 | |||
b56609e684 | |||
8effc2df33 | |||
4368211710 | |||
0a5d5315c0 |
@ -1,4 +1,4 @@
|
||||
version: 13.11.{build}
|
||||
version: 13.12.{build}
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
|
@ -5,7 +5,7 @@ GPS log file formats.
|
||||
## Features
|
||||
* Opens GPX, TCX, FIT, KML, NMEA, IGC, CUP, SIGMA SLF, Suunto SML, LOC, GeoJSON,
|
||||
OziExplorer (PLT, RTE, WPT), Garmin GPI&CSV, TomTom OV2&ITN, ONmove OMD/GHP,
|
||||
TwoNav (TRK, RTE, WPT), GPSDump and geotagged JPEG files.
|
||||
TwoNav (TRK, RTE, WPT), GPSDump WPT and geotagged JPEG files.
|
||||
* User-definable online maps (OpenStreetMap/Google tiles, WMTS, WMS, TMS,
|
||||
QuadTiles).
|
||||
* Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases,
|
||||
|
@ -3,7 +3,7 @@ unix:!macx:!android {
|
||||
} else {
|
||||
TARGET = GPXSee
|
||||
}
|
||||
VERSION = 13.11
|
||||
VERSION = 13.12
|
||||
|
||||
|
||||
QT += core \
|
||||
|
@ -414,7 +414,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Esborrar la llista</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -701,7 +701,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Obert fa poc</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="656"/>
|
||||
@ -1042,6 +1042,7 @@
|
||||
<translation>
|
||||
<numerusform>%n fitxer</numerusform>
|
||||
<numerusform>%n fitxers</numerusform>
|
||||
<numerusform>%n fitxers</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
</context>
|
||||
|
@ -172,7 +172,7 @@
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="180"/>
|
||||
<source>GPSDump files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>GPSDump-dosieroj</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="181"/>
|
||||
@ -414,7 +414,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Vakigi liston</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -701,7 +701,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Malfermi lastatempajn</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="656"/>
|
||||
@ -745,7 +745,7 @@
|
||||
<location filename="../src/GUI/gui.cpp" line="1775"/>
|
||||
<location filename="../src/GUI/gui.cpp" line="1875"/>
|
||||
<source>Don't show again</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Ne montri denove</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="1938"/>
|
||||
|
@ -172,7 +172,7 @@
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="180"/>
|
||||
<source>GPSDump files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>GPSDump-tiedostot</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="181"/>
|
||||
@ -445,7 +445,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Tyhjennä lista</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -680,7 +680,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Avaa viimeisimmät</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="683"/>
|
||||
|
@ -1041,6 +1041,7 @@
|
||||
<source>%n files</source>
|
||||
<translation>
|
||||
<numerusform>%n fájl</numerusform>
|
||||
<numerusform>%n fájl</numerusform>
|
||||
</translation>
|
||||
</message>
|
||||
</context>
|
||||
|
@ -172,7 +172,7 @@
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="180"/>
|
||||
<source>GPSDump files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>GPSDump файлы</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="181"/>
|
||||
@ -445,7 +445,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Очистить список</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -680,7 +680,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Открыть недавние</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="683"/>
|
||||
|
@ -457,7 +457,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Rensa lista</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -692,7 +692,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Öppna senaste</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="683"/>
|
||||
|
@ -172,7 +172,7 @@
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="180"/>
|
||||
<source>GPSDump files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>GPSDump файли</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/data/data.cpp" line="181"/>
|
||||
@ -414,7 +414,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="272"/>
|
||||
<source>Clear list</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Очистити список</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="284"/>
|
||||
@ -566,7 +566,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="447"/>
|
||||
<source>Use styles</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Використовувати стилі</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="454"/>
|
||||
@ -701,7 +701,7 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="631"/>
|
||||
<source>Open recent</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Відкрити недавні</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="656"/>
|
||||
@ -745,7 +745,7 @@
|
||||
<location filename="../src/GUI/gui.cpp" line="1775"/>
|
||||
<location filename="../src/GUI/gui.cpp" line="1875"/>
|
||||
<source>Don't show again</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Більше не показувати</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/gui.cpp" line="1938"/>
|
||||
@ -1264,7 +1264,7 @@
|
||||
<message>
|
||||
<location filename="../src/map/maplist.cpp" line="160"/>
|
||||
<source>Electronic Navigational Charts</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Морські карти ENC</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/map/maplist.cpp" line="168"/>
|
||||
@ -1737,12 +1737,12 @@
|
||||
<message>
|
||||
<location filename="../src/GUI/optionsdialog.cpp" line="70"/>
|
||||
<source>Select the proper coordinate reference system (CRS) of maps without a CRS definition (JNX, KMZ and World file maps).</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Виберіть правильну систему координат (CRS) для карт без визначеного CRS (JNX, KMZ і World-файли).</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/optionsdialog.cpp" line="73"/>
|
||||
<source>Select the desired projection of vector maps (IMG, Mapsforge and ENC maps). The projection must be valid for the whole map area.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Виберіть необхідну проєкцію векторних карт (IMG, Mapsforge та ENC мапи). Проєкція має бути дійсною для всієї області карти.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/GUI/optionsdialog.cpp" line="295"/>
|
||||
|
@ -15,7 +15,8 @@
|
||||
<li>Opens GPX, TCX, FIT, KML, IGC, NMEA, SIGMA SLF, Suunto SML, LOC,
|
||||
OziExplorer (PLT, WPT, RTE), GeoJSON, SeeYou CUP,
|
||||
Garmin GPI & CSV, TomTom OV2 & ITN, ONmove OMD/GHP,
|
||||
TwoNav (TRK, RTE, WPT) and geotagged JPEG files.</li>
|
||||
TwoNav (TRK, RTE, WPT), GPSDump WPT and geotagged JPEG
|
||||
files.</li>
|
||||
<li>User-definable online maps (OpenStreetMap/Google tiles, WMTS,
|
||||
WMS, TMS, QuadTiles).</li>
|
||||
<li>Offline maps (MBTiles, OziExplorer maps, TrekBuddy maps/atlases,
|
||||
@ -41,7 +42,7 @@
|
||||
<image>https://www.gpxsee.org/gallery/linux.png</image>
|
||||
</screenshot>
|
||||
<screenshot>
|
||||
<image>https://www.gpxsee.org/gallery/poi2.png</image>
|
||||
<image>https://www.gpxsee.org/gallery/gear_ratio.png</image>
|
||||
</screenshot>
|
||||
</screenshots>
|
||||
|
||||
@ -109,5 +110,6 @@
|
||||
<mimetype>application/vnd.orux.map+xml</mimetype>
|
||||
<mimetype>application/vnd.iho.s57-data</mimetype>
|
||||
<mimetype>application/vnd.iho.s57-catalogue</mimetype>
|
||||
<mimetype>application/vnd.gpsdump.wpt</mimetype>
|
||||
</mimetypes>
|
||||
</component>
|
||||
|
@ -37,7 +37,7 @@ Unicode true
|
||||
; The name of the installer
|
||||
Name "GPXSee"
|
||||
; Program version
|
||||
!define VERSION "13.11"
|
||||
!define VERSION "13.12"
|
||||
|
||||
; The file to write
|
||||
OutFile "GPXSee-${VERSION}_x64.exe"
|
||||
|
@ -13,8 +13,7 @@ bool AtlasData::pointCb(const QString *map, void *context)
|
||||
if (!cached) {
|
||||
MapData *data = new MapData(*map);
|
||||
data->points(ctx->rect, ctx->points);
|
||||
if (!ctx->cache.insert(map, data))
|
||||
delete data;
|
||||
ctx->cache.insert(map, data);
|
||||
} else
|
||||
cached->points(ctx->rect, ctx->points);
|
||||
|
||||
@ -35,8 +34,7 @@ bool AtlasData::polyCb(const QString *map, void *context)
|
||||
MapData *data = new MapData(*map);
|
||||
data->polygons(ctx->rect, ctx->polygons);
|
||||
data->lines(ctx->rect, ctx->lines);
|
||||
if (!ctx->cache.insert(map, data))
|
||||
delete data;
|
||||
ctx->cache.insert(map, data);
|
||||
} else {
|
||||
cached->polygons(ctx->rect, ctx->polygons);
|
||||
cached->lines(ctx->rect, ctx->lines);
|
||||
|
@ -355,7 +355,7 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
QList<RenderTile> tiles;
|
||||
QList<DataTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -369,15 +369,15 @@ void AQMMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
tiles.append(RenderTile(t, tileData(t), key));
|
||||
tiles.append(DataTile(t, tileData(t), key));
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
const DataTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -112,7 +112,7 @@ Atlas::Atlas(const QString &fileName, bool TAR, const Projection &proj,
|
||||
|
||||
if (TAR) {
|
||||
if (!tar.open()) {
|
||||
_errorString = "Error reading tar file";
|
||||
_errorString = "Error reading tar file: " + tar.errorString();
|
||||
return;
|
||||
}
|
||||
QString tbaFileName(tbaFile(tar.files()));
|
||||
|
@ -251,7 +251,7 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
QList<RenderTile> tiles;
|
||||
QList<DataTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -265,15 +265,15 @@ void GEMFMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
tiles.append(RenderTile(t, tileData(t), key));
|
||||
tiles.append(DataTile(t, tileData(t), key));
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
const DataTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "osm.h"
|
||||
#include "mbtilesmap.h"
|
||||
|
||||
|
||||
#define MAX_OVERZOOM 3
|
||||
#define META_TYPE(type) static_cast<QMetaType::Type>(type)
|
||||
|
||||
static RectC str2bounds(const QString &str)
|
||||
@ -42,7 +42,7 @@ bool MBTilesMap::getMinZoom(int &zoom)
|
||||
}
|
||||
} else {
|
||||
qWarning("%s: missing minzoom metadata", qPrintable(path()));
|
||||
zoom = 0;
|
||||
zoom = OSM::ZOOMS.min();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -61,7 +61,7 @@ bool MBTilesMap::getMaxZoom(int &zoom)
|
||||
}
|
||||
} else {
|
||||
qWarning("%s: missing maxzoom metadata", qPrintable(path()));
|
||||
zoom = 20;
|
||||
zoom = OSM::ZOOMS.max();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -79,7 +79,21 @@ bool MBTilesMap::getZooms()
|
||||
" WHERE zoom_level = %1 LIMIT 1").arg(i);
|
||||
QSqlQuery query(sql, _db);
|
||||
if (query.first())
|
||||
_zooms.append(i);
|
||||
_zooms.append(Zoom(i, i));
|
||||
}
|
||||
|
||||
if (!_zooms.size()) {
|
||||
_errorString = "Empty tile set";
|
||||
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;
|
||||
@ -100,7 +114,7 @@ bool MBTilesMap::getBounds()
|
||||
} else {
|
||||
qWarning("%s: missing bounds metadata", qPrintable(path()));
|
||||
|
||||
int z = _zooms.first();
|
||||
int z = _zooms.first().z;
|
||||
QString sql = QString("SELECT min(tile_column), min(tile_row), "
|
||||
"max(tile_column), max(tile_row) FROM tiles WHERE zoom_level = %1")
|
||||
.arg(z);
|
||||
@ -124,13 +138,14 @@ bool MBTilesMap::getBounds()
|
||||
|
||||
bool MBTilesMap::getTileSize()
|
||||
{
|
||||
QString sql("SELECT tile_data FROM tiles LIMIT 1");
|
||||
QString sql("SELECT zoom_level, tile_data FROM tiles LIMIT 1");
|
||||
QSqlQuery query(sql, _db);
|
||||
query.first();
|
||||
|
||||
QByteArray data = query.value(0).toByteArray();
|
||||
QByteArray z(QByteArray::number(query.value(0).toInt()));
|
||||
QByteArray data = query.value(1).toByteArray();
|
||||
QBuffer buffer(&data);
|
||||
QImageReader reader(&buffer);
|
||||
QImageReader reader(&buffer, z);
|
||||
QSize tileSize(reader.size());
|
||||
|
||||
if (!tileSize.isValid() || tileSize.width() != tileSize.height()) {
|
||||
@ -206,13 +221,13 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
|
||||
return;
|
||||
}
|
||||
|
||||
getTileFormat();
|
||||
if (!getZooms())
|
||||
return;
|
||||
if (!getBounds())
|
||||
return;
|
||||
if (!getTileSize())
|
||||
return;
|
||||
getTileFormat();
|
||||
getTilePixelRatio();
|
||||
getName();
|
||||
|
||||
@ -260,7 +275,7 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
|
||||
_zi = 0;
|
||||
for (int i = 1; i < _zooms.size(); i++) {
|
||||
if (_zooms.at(i) > zoom)
|
||||
if (_zooms.at(i).z > zoom)
|
||||
break;
|
||||
_zi = i;
|
||||
}
|
||||
@ -271,7 +286,7 @@ int MBTilesMap::zoomFit(const QSize &size, const RectC &rect)
|
||||
|
||||
qreal MBTilesMap::resolution(const QRectF &rect)
|
||||
{
|
||||
return OSM::resolution(rect.center(), _zooms.at(_zi), _tileSize);
|
||||
return OSM::resolution(rect.center(), _zooms.at(_zi).z, _tileSize);
|
||||
}
|
||||
|
||||
int MBTilesMap::zoomIn()
|
||||
@ -370,15 +385,17 @@ void MBTilesMap::cancelJobs(bool wait)
|
||||
|
||||
void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
{
|
||||
int zoom = _zooms.at(_zi);
|
||||
qreal scale = OSM::zoom2scale(zoom, _tileSize);
|
||||
const Zoom &zoom = _zooms.at(_zi);
|
||||
unsigned overzoom = zoom.z - zoom.base;
|
||||
unsigned f = 1U<<overzoom;
|
||||
qreal scale = OSM::zoom2scale(zoom.base, _tileSize * f);
|
||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom);
|
||||
Coordinates ctl(OSM::tile2ll(tile, zoom));
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), zoom.base);
|
||||
Coordinates ctl(OSM::tile2ll(tile, zoom.base));
|
||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
int width = ceil(s.width() / (tileSize() * f));
|
||||
int height = ceil(s.height() / (tileSize() * f));
|
||||
|
||||
QList<MBTile> tiles;
|
||||
|
||||
@ -386,20 +403,19 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
for (int j = 0; j < height; j++) {
|
||||
QPixmap pm;
|
||||
QPoint t(tile.x() + i, tile.y() + j);
|
||||
QString key = path() + "-" + QString::number(zoom) + "_"
|
||||
QString key = path() + "-" + QString::number(zoom.z) + "_"
|
||||
+ QString::number(t.x()) + "_" + QString::number(t.y());
|
||||
|
||||
if (isRunning(key))
|
||||
continue;
|
||||
|
||||
if (QPixmapCache::find(key, &pm)) {
|
||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize(),
|
||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||
QPointF tp(tl.x() + (t.x() - tile.x()) * tileSize() * f,
|
||||
tl.y() + (t.y() - tile.y()) * tileSize() * f);
|
||||
drawTile(painter, pm, tp);
|
||||
} else {
|
||||
tiles.append(MBTile(zoom, _scaledSize, t, tileData(zoom, t),
|
||||
key));
|
||||
}
|
||||
} else
|
||||
tiles.append(MBTile(zoom.z, overzoom, _scaledSize, t,
|
||||
tileData(zoom.base, t), key));
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,8 +432,8 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
|
||||
QPixmapCache::insert(mt.key(), pm);
|
||||
|
||||
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize(),
|
||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize());
|
||||
QPointF tp(tl.x() + (mt.xy().x() - tile.x()) * tileSize() * f,
|
||||
tl.y() + (mt.xy().y() - tile.y()) * tileSize() * f);
|
||||
drawTile(painter, pm, tp);
|
||||
}
|
||||
} else
|
||||
@ -433,14 +449,14 @@ void MBTilesMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||
|
||||
QPointF MBTilesMap::ll2xy(const Coordinates &c)
|
||||
{
|
||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi), _tileSize);
|
||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi).z, _tileSize);
|
||||
QPointF m = OSM::ll2m(c);
|
||||
return QPointF(m.x() / scale, m.y() / -scale) / coordinatesRatio();
|
||||
}
|
||||
|
||||
Coordinates MBTilesMap::xy2ll(const QPointF &p)
|
||||
{
|
||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi), _tileSize);
|
||||
qreal scale = OSM::zoom2scale(_zooms.at(_zi).z, _tileSize);
|
||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
* coordinatesRatio());
|
||||
}
|
||||
@ -454,3 +470,11 @@ Map *MBTilesMap::create(const QString &path, const Projection &proj, bool *isDir
|
||||
|
||||
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,6 +1,7 @@
|
||||
#ifndef MBTILESMAP_H
|
||||
#define MBTILESMAP_H
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSqlDatabase>
|
||||
#include <QVector>
|
||||
#include <QImageReader>
|
||||
@ -12,19 +13,21 @@
|
||||
class MBTile
|
||||
{
|
||||
public:
|
||||
MBTile(int zoom, int scaledSize, const QPoint &xy, const QByteArray &data,
|
||||
const QString &key) : _zoom(zoom), _scaledSize(scaledSize), _xy(xy),
|
||||
_data(data), _key(key) {}
|
||||
MBTile(int zoom, int overzoom, int scaledSize, const QPoint &xy,
|
||||
const QByteArray &data, const QString &key) : _zoom(zoom),
|
||||
_overzoom(overzoom), _scaledSize(scaledSize), _xy(xy), _data(data),
|
||||
_key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const QString &key() const {return _key;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {
|
||||
QByteArray z(QString::number(_zoom).toLatin1());
|
||||
|
||||
QByteArray format(_overzoom
|
||||
? QByteArray::number(_zoom) + ';' + QByteArray::number(_overzoom)
|
||||
: QByteArray::number(_zoom));
|
||||
QBuffer buffer(&_data);
|
||||
QImageReader reader(&buffer, z);
|
||||
QImageReader reader(&buffer, format);
|
||||
if (_scaledSize)
|
||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||
_pixmap = QPixmap::fromImage(reader.read());
|
||||
@ -32,6 +35,7 @@ public:
|
||||
|
||||
private:
|
||||
int _zoom;
|
||||
int _overzoom;
|
||||
int _scaledSize;
|
||||
QPoint _xy;
|
||||
QByteArray _data;
|
||||
@ -110,6 +114,14 @@ private slots:
|
||||
void jobFinished(MBTilesMapJob *job);
|
||||
|
||||
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 getMaxZoom(int &zoom);
|
||||
bool getZooms();
|
||||
@ -128,11 +140,13 @@ private:
|
||||
void removeJob(MBTilesMapJob *job);
|
||||
void cancelJobs(bool wait);
|
||||
|
||||
friend QDebug operator<<(QDebug dbg, const Zoom &zoom);
|
||||
|
||||
QSqlDatabase _db;
|
||||
|
||||
QString _name;
|
||||
RectC _bounds;
|
||||
QVector<int> _zooms;
|
||||
QVector<Zoom> _zooms;
|
||||
int _zi;
|
||||
int _tileSize;
|
||||
qreal _mapRatio, _tileRatio;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <QPainter>
|
||||
#include <QDir>
|
||||
#include <QPixmapCache>
|
||||
#include "common/rectc.h"
|
||||
#include "common/programpaths.h"
|
||||
#include "common/downloader.h"
|
||||
@ -7,19 +8,26 @@
|
||||
#include "onlinemap.h"
|
||||
|
||||
|
||||
#define MAX_OVERZOOM 3
|
||||
|
||||
OnlineMap::OnlineMap(const QString &fileName, const QString &name,
|
||||
const QString &url, const Range &zooms, const RectC &bounds, qreal tileRatio,
|
||||
const QList<HTTPHeader> &headers, int tileSize, bool scalable, bool invertY,
|
||||
bool quadTiles, QObject *parent)
|
||||
: Map(fileName, parent), _name(name), _zooms(zooms), _bounds(bounds),
|
||||
_zoom(_zooms.max()), _tileSize(tileSize), _mapRatio(1.0),
|
||||
_tileRatio(tileRatio), _scalable(scalable), _invertY(invertY)
|
||||
_zoom(_zooms.max()), _tileSize(tileSize), _baseZoom(0), _mapRatio(1.0),
|
||||
_tileRatio(tileRatio), _scalable(scalable), _scaledSize(0), _invertY(invertY)
|
||||
{
|
||||
_tileLoader = new TileLoader(QDir(ProgramPaths::tilesDir()).filePath(_name),
|
||||
this);
|
||||
_tileLoader->setUrl(url, quadTiles ? TileLoader::QuadTiles : TileLoader::XYZ);
|
||||
_tileLoader->setHeaders(headers);
|
||||
connect(_tileLoader, &TileLoader::finished, this, &OnlineMap::tilesLoaded);
|
||||
|
||||
if (_scalable) {
|
||||
_baseZoom = _zooms.max();
|
||||
_zooms.setMax(qMin(_zooms.max() + MAX_OVERZOOM, OSM::ZOOMS.max()));
|
||||
}
|
||||
}
|
||||
|
||||
QRectF OnlineMap::bounds()
|
||||
@ -58,12 +66,16 @@ qreal OnlineMap::resolution(const QRectF &rect)
|
||||
|
||||
int OnlineMap::zoomIn()
|
||||
{
|
||||
cancelJobs(false);
|
||||
|
||||
_zoom = qMin(_zoom + 1, _zooms.max());
|
||||
return _zoom;
|
||||
}
|
||||
|
||||
int OnlineMap::zoomOut()
|
||||
{
|
||||
cancelJobs(false);
|
||||
|
||||
_zoom = qMax(_zoom - 1, _zooms.min());
|
||||
return _zoom;
|
||||
}
|
||||
@ -77,11 +89,16 @@ void OnlineMap::load(const Projection &in, const Projection &out,
|
||||
_mapRatio = hidpi ? deviceRatio : 1.0;
|
||||
|
||||
if (_scalable) {
|
||||
_tileLoader->setScaledSize(_tileSize * deviceRatio);
|
||||
_scaledSize = _tileSize * deviceRatio;
|
||||
_tileRatio = deviceRatio;
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineMap::unload()
|
||||
{
|
||||
cancelJobs(true);
|
||||
}
|
||||
|
||||
qreal OnlineMap::coordinatesRatio() const
|
||||
{
|
||||
return _mapRatio > 1.0 ? _mapRatio / _tileRatio : 1.0;
|
||||
@ -97,41 +114,137 @@ qreal OnlineMap::tileSize() const
|
||||
return (_tileSize / coordinatesRatio());
|
||||
}
|
||||
|
||||
QPoint OnlineMap::tileCoordinates(int x, int y, int zoom)
|
||||
{
|
||||
return QPoint(x, _invertY ? (1<<zoom) - y - 1 : y);
|
||||
}
|
||||
|
||||
bool OnlineMap::isRunning(const QString &key) const
|
||||
{
|
||||
for (int i = 0; i < _jobs.size(); i++) {
|
||||
const QList<OnlineMapTile> &tiles = _jobs.at(i)->tiles();
|
||||
for (int j = 0; j < tiles.size(); j++)
|
||||
if (tiles.at(j).key() == key)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnlineMap::runJob(OnlineMapJob *job)
|
||||
{
|
||||
_jobs.append(job);
|
||||
|
||||
connect(job, &OnlineMapJob::finished, this, &OnlineMap::jobFinished);
|
||||
job->run();
|
||||
}
|
||||
|
||||
void OnlineMap::removeJob(OnlineMapJob *job)
|
||||
{
|
||||
_jobs.removeOne(job);
|
||||
job->deleteLater();
|
||||
}
|
||||
|
||||
void OnlineMap::jobFinished(OnlineMapJob *job)
|
||||
{
|
||||
const QList<OnlineMapTile> &tiles = job->tiles();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const OnlineMapTile &mt = tiles.at(i);
|
||||
if (!mt.pixmap().isNull())
|
||||
QPixmapCache::insert(mt.key(), mt.pixmap());
|
||||
}
|
||||
|
||||
removeJob(job);
|
||||
|
||||
emit tilesLoaded();
|
||||
}
|
||||
|
||||
void OnlineMap::cancelJobs(bool wait)
|
||||
{
|
||||
for (int i = 0; i < _jobs.size(); i++)
|
||||
_jobs.at(i)->cancel(wait);
|
||||
}
|
||||
|
||||
void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
{
|
||||
qreal scale = OSM::zoom2scale(_zoom, _tileSize);
|
||||
int baseZoom = _scalable ? qMin(_baseZoom, _zoom) : _zoom;
|
||||
unsigned overzoom = _zoom - baseZoom;
|
||||
unsigned f = 1U<<overzoom;
|
||||
|
||||
qreal scale = OSM::zoom2scale(baseZoom, _tileSize * f);
|
||||
QPoint tile = OSM::mercator2tile(QPointF(rect.topLeft().x() * scale,
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), _zoom);
|
||||
Coordinates ctl(OSM::tile2ll(tile, _zoom));
|
||||
-rect.topLeft().y() * scale) * coordinatesRatio(), baseZoom);
|
||||
Coordinates ctl(OSM::tile2ll(tile, baseZoom));
|
||||
QPointF tl(ll2xy(Coordinates(ctl.lon(), -ctl.lat())));
|
||||
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
int width = ceil(s.width() / (tileSize() * f));
|
||||
int height = ceil(s.height() / (tileSize() * f));
|
||||
|
||||
QVector<FetchTile> tiles;
|
||||
tiles.reserve(width * height);
|
||||
for (int i = 0; i < width; i++)
|
||||
for (int j = 0; j < height; j++)
|
||||
tiles.append(FetchTile(QPoint(tile.x() + i, _invertY ? (1<<_zoom)
|
||||
- (tile.y() + j) - 1 : tile.y() + j), _zoom));
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(tiles);
|
||||
else
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp(tl.x() + (t.xy().x() - tile.x()) * tileSize(),
|
||||
tl.y() + ((_invertY
|
||||
? (1<<_zoom) - t.xy().y() - 1
|
||||
: t.xy().y()) - tile.y()) * tileSize());
|
||||
|
||||
if (!t.pixmap().isNull()) {
|
||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
QVector<TileLoader::Tile> fetchTiles;
|
||||
fetchTiles.reserve(width * height);
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
QPoint tc(tileCoordinates(tile.x() + i, tile.y() + j, baseZoom));
|
||||
fetchTiles.append(TileLoader::Tile(tc, baseZoom));
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(fetchTiles);
|
||||
else
|
||||
_tileLoader->loadTilesAsync(fetchTiles);
|
||||
|
||||
QList<OnlineMapTile> renderTiles;
|
||||
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||
if (t.file().isNull())
|
||||
continue;
|
||||
|
||||
QString key(overzoom
|
||||
? t.file() + ":" + QString::number(overzoom) : t.file());
|
||||
if (isRunning(key))
|
||||
continue;
|
||||
|
||||
QPixmap pm;
|
||||
if (QPixmapCache::find(key, &pm)) {
|
||||
QPoint tc(tileCoordinates(t.xy().x(), t.xy().y(), baseZoom));
|
||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
renderTiles.append(OnlineMapTile(t.xy(), t.file(), _zoom, overzoom,
|
||||
_scaledSize, key));
|
||||
}
|
||||
|
||||
if (!renderTiles.isEmpty()) {
|
||||
if (flags & Map::Block || !_scalable) {
|
||||
QFuture<void> future = QtConcurrent::map(renderTiles,
|
||||
&OnlineMapTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < renderTiles.size(); i++) {
|
||||
const OnlineMapTile &mt = renderTiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
||||
QPixmapCache::insert(mt.key(), pm);
|
||||
|
||||
QPoint tc(tileCoordinates(mt.xy().x(), mt.xy().y(), baseZoom));
|
||||
QPointF tp(tl.x() + (tc.x() - tile.x()) * tileSize() * f,
|
||||
tl.y() + (tc.y() - tile.y()) * tileSize() * f);
|
||||
drawTile(painter, pm, tp);
|
||||
}
|
||||
} else
|
||||
runJob(new OnlineMapJob(renderTiles));
|
||||
}
|
||||
}
|
||||
|
||||
void OnlineMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||
{
|
||||
pixmap.setDevicePixelRatio(imageRatio());
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
}
|
||||
|
||||
QPointF OnlineMap::ll2xy(const Coordinates &c)
|
||||
@ -147,3 +260,9 @@ Coordinates OnlineMap::xy2ll(const QPointF &p)
|
||||
return OSM::m2ll(QPointF(p.x() * scale, -p.y() * scale)
|
||||
* coordinatesRatio());
|
||||
}
|
||||
|
||||
void OnlineMap::clearCache()
|
||||
{
|
||||
_tileLoader->clearCache();
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
@ -1,11 +1,80 @@
|
||||
#ifndef ONLINEMAP_H
|
||||
#define ONLINEMAP_H
|
||||
|
||||
#include <QImageReader>
|
||||
#include <QPixmap>
|
||||
#include <QtConcurrent>
|
||||
#include "common/range.h"
|
||||
#include "common/rectc.h"
|
||||
#include "map.h"
|
||||
#include "tileloader.h"
|
||||
|
||||
class OnlineMapTile
|
||||
{
|
||||
public:
|
||||
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) {}
|
||||
|
||||
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;}
|
||||
const QString &key() const {return _key;}
|
||||
|
||||
private:
|
||||
int _zoom;
|
||||
int _overzoom;
|
||||
int _scaledSize;
|
||||
QPoint _xy;
|
||||
QString _file;
|
||||
QString _key;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class OnlineMap : public Map
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -35,13 +104,23 @@ public:
|
||||
|
||||
void load(const Projection &in, const Projection &out, qreal deviceRatio,
|
||||
bool hidpi);
|
||||
void clearCache() {_tileLoader->clearCache();}
|
||||
void unload();
|
||||
void clearCache();
|
||||
|
||||
private slots:
|
||||
void jobFinished(OnlineMapJob *job);
|
||||
|
||||
private:
|
||||
int limitZoom(int zoom) const;
|
||||
qreal tileSize() const;
|
||||
qreal coordinatesRatio() const;
|
||||
qreal imageRatio() const;
|
||||
QPoint tileCoordinates(int x, int y, int zoom);
|
||||
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||
bool isRunning(const QString &key) const;
|
||||
void runJob(OnlineMapJob *job);
|
||||
void removeJob(OnlineMapJob *job);
|
||||
void cancelJobs(bool wait);
|
||||
|
||||
TileLoader *_tileLoader;
|
||||
QString _name;
|
||||
@ -49,9 +128,13 @@ private:
|
||||
RectC _bounds;
|
||||
int _zoom;
|
||||
int _tileSize;
|
||||
int _baseZoom;
|
||||
qreal _mapRatio, _tileRatio;
|
||||
bool _scalable;
|
||||
int _scaledSize;
|
||||
bool _invertY;
|
||||
|
||||
QList<OnlineMapJob*> _jobs;
|
||||
};
|
||||
|
||||
#endif // ONLINEMAP_H
|
||||
|
@ -246,7 +246,7 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
QList<RenderTile> tiles;
|
||||
QList<DataTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -260,15 +260,15 @@ void OsmdroidMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||
tiles.append(DataTile(t, tileData(_zoom, t), key));
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
const DataTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -179,20 +179,22 @@ bool OZF::readTileTable()
|
||||
|
||||
bool OZF::open()
|
||||
{
|
||||
if (!_file.open(QIODevice::ReadOnly))
|
||||
if (!_file.open(QIODevice::ReadOnly)) {
|
||||
_errorString = _file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_zooms.isEmpty())
|
||||
return true;
|
||||
|
||||
if (!readHeaders()) {
|
||||
qWarning("%s: Invalid header", qPrintable(_file.fileName()));
|
||||
_errorString = "Invalid header";
|
||||
_file.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!readTileTable()) {
|
||||
qWarning("%s: Invalid tile table", qPrintable(_file.fileName()));
|
||||
_errorString = "Invalid tile table";
|
||||
_file.close();
|
||||
return false;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
|
||||
bool open();
|
||||
void close() {_file.close();}
|
||||
const QString &errorString() const {return _errorString;}
|
||||
|
||||
QString fileName() const {return _file.fileName();}
|
||||
bool isOpen() const {return _file.isOpen();}
|
||||
@ -49,6 +50,7 @@ private:
|
||||
quint8 _key;
|
||||
QList<Zoom> _zooms;
|
||||
QFile _file;
|
||||
QString _errorString;
|
||||
};
|
||||
|
||||
#endif // OZF_H
|
||||
|
@ -66,7 +66,7 @@ OziMap::OziMap(const QString &fileName, const Projection &proj, QObject *parent)
|
||||
|
||||
_tar = new Tar(fileName);
|
||||
if (!_tar->open()) {
|
||||
_errorString = "Error reading tar file";
|
||||
_errorString = "Error reading tar file: " + _tar->errorString();
|
||||
return;
|
||||
}
|
||||
QStringList files(_tar->files());
|
||||
@ -202,7 +202,7 @@ OziMap::OziMap(const QString &dirName, Tar &tar, const Projection &proj,
|
||||
}
|
||||
_tar = new Tar(tf);
|
||||
if (!_tar->open()) {
|
||||
_errorString = _tar->fileName() + ": error reading tar file";
|
||||
_errorString = _tar->fileName() + ": " + _tar->errorString();
|
||||
return;
|
||||
}
|
||||
if (!setTileInfo(_tar->files())) {
|
||||
@ -245,8 +245,8 @@ bool OziMap::setImageInfo(const QString &path)
|
||||
|
||||
if (OZF::isOZF(_map.path)) {
|
||||
_ozf = new OZF(_map.path);
|
||||
if (!_ozf || !_ozf->open()) {
|
||||
_errorString = QString("%1: Error loading OZF file").arg(_map.path);
|
||||
if (!_ozf->open()) {
|
||||
_errorString = QString("%1: %2").arg(_map.path, _ozf->errorString());
|
||||
return false;
|
||||
}
|
||||
_scale = _ozf->scale(_zoom);
|
||||
@ -312,19 +312,24 @@ void OziMap::load(const Projection &in, const Projection &out,
|
||||
|
||||
if (_tar) {
|
||||
Q_ASSERT(!_tar->isOpen());
|
||||
if (!_tar->open())
|
||||
if (!_tar->open()) {
|
||||
qWarning("%s: %s", qPrintable(_tar->fileName()),
|
||||
qPrintable(_tar->errorString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (_ozf) {
|
||||
Q_ASSERT(!_ozf->isOpen());
|
||||
if (!_ozf->open())
|
||||
if (!_ozf->open()) {
|
||||
qWarning("%s: %s", qPrintable(_ozf->fileName()),
|
||||
qPrintable(_ozf->errorString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!_tile.isValid() && !_ozf) {
|
||||
Q_ASSERT(!_img);
|
||||
_img = new Image(_map.path);
|
||||
if (_img)
|
||||
_img->setDevicePixelRatio(_mapRatio);
|
||||
_img->setDevicePixelRatio(_mapRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
int width = ceil(s.width() / tileSize());
|
||||
int height = ceil(s.height() / tileSize());
|
||||
|
||||
QList<RenderTile> tiles;
|
||||
QList<DataTile> tiles;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
@ -207,15 +207,15 @@ void SqliteMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
tl.y() + (t.y() - tile.y()) * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
tiles.append(RenderTile(t, tileData(_zoom, t), key));
|
||||
tiles.append(DataTile(t, tileData(_zoom, t), key));
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &RenderTile::load);
|
||||
QFuture<void> future = QtConcurrent::map(tiles, &DataTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < tiles.size(); i++) {
|
||||
const RenderTile &mt = tiles.at(i);
|
||||
const DataTile &mt = tiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
@ -46,8 +46,10 @@ static quint64 number(const char* data, size_t size, int base = 8)
|
||||
|
||||
bool Tar::open()
|
||||
{
|
||||
if (!_file.open(QIODevice::ReadOnly))
|
||||
if (!_file.open(QIODevice::ReadOnly)) {
|
||||
_errorString = _file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_index.isEmpty())
|
||||
return true;
|
||||
@ -72,6 +74,7 @@ bool Tar::loadTar()
|
||||
if (ret < BLOCKSIZE) {
|
||||
_file.close();
|
||||
_index.clear();
|
||||
_errorString = "Error reading header block";
|
||||
return false;
|
||||
}
|
||||
size = number(hdr->size, sizeof(hdr->size));
|
||||
@ -79,6 +82,7 @@ bool Tar::loadTar()
|
||||
if (!_file.seek(_file.pos() + BLOCKCOUNT(size) * BLOCKSIZE)) {
|
||||
_file.close();
|
||||
_index.clear();
|
||||
_errorString = "Error skipping data blocks";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public:
|
||||
|
||||
bool open();
|
||||
void close() {_file.close();}
|
||||
const QString &errorString() const {return _errorString;}
|
||||
|
||||
QStringList files() const {return _index.keys();}
|
||||
QByteArray file(const QString &name);
|
||||
@ -26,6 +27,7 @@ private:
|
||||
|
||||
QFile _file;
|
||||
QMap<QString, quint64> _index;
|
||||
QString _errorString;
|
||||
};
|
||||
|
||||
#endif // TAR_H
|
||||
|
@ -4,32 +4,29 @@
|
||||
#include <QVariant>
|
||||
#include <QPixmap>
|
||||
#include <QPoint>
|
||||
#include <QDebug>
|
||||
#include "rectd.h"
|
||||
|
||||
class FetchTile
|
||||
class FileTile
|
||||
{
|
||||
public:
|
||||
FetchTile() {}
|
||||
FetchTile(const QPoint &xy, const QVariant &zoom, const RectD &bbox = RectD())
|
||||
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
|
||||
FileTile(const QPoint &xy, const QString &file)
|
||||
: _xy(xy), _file(file) {}
|
||||
|
||||
const QVariant &zoom() const {return _zoom;}
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const RectD &bbox() const {return _bbox;}
|
||||
QPixmap &pixmap() {return _pixmap;}
|
||||
const QString &file() const {return _file;}
|
||||
const QPixmap &pixmap() const {return _pixmap;}
|
||||
|
||||
void load() {_pixmap.load(_file);}
|
||||
|
||||
private:
|
||||
QPoint _xy;
|
||||
QVariant _zoom;
|
||||
RectD _bbox;
|
||||
QString _file;
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
class RenderTile
|
||||
class DataTile
|
||||
{
|
||||
public:
|
||||
RenderTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
DataTile(const QPoint &xy, const QByteArray &data, const QString &key)
|
||||
: _xy(xy), _data(data), _key(key) {}
|
||||
|
||||
const QPoint &xy() const {return _xy;}
|
||||
@ -45,13 +42,4 @@ private:
|
||||
QPixmap _pixmap;
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
inline QDebug operator<<(QDebug dbg, const FetchTile &tile)
|
||||
{
|
||||
dbg.nospace() << "Tile(" << tile.zoom() << ", " << tile.xy() << ", "
|
||||
<< tile.bbox() << ")";
|
||||
return dbg.space();
|
||||
}
|
||||
#endif // QT_NO_DEBUG
|
||||
|
||||
#endif // TILE_H
|
||||
|
@ -1,39 +1,12 @@
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QEventLoop>
|
||||
#include <QPixmapCache>
|
||||
#include <QImageReader>
|
||||
#include <QtConcurrent>
|
||||
#include "tileloader.h"
|
||||
|
||||
#define SUBSTITUTE_CHAR '$'
|
||||
#define IS_INT(zoom) \
|
||||
((QMetaType::Type)((zoom).type()) == QMetaType::Int)
|
||||
|
||||
class TileImage
|
||||
{
|
||||
public:
|
||||
TileImage() : _tile(0), _scaledSize(0) {}
|
||||
TileImage(const QString &file, FetchTile *tile, int scaledSize)
|
||||
: _file(file), _tile(tile), _scaledSize(scaledSize) {}
|
||||
|
||||
void load()
|
||||
{
|
||||
QImage img;
|
||||
QByteArray z(_tile->zoom().toString().toLatin1());
|
||||
QImageReader reader(_file, z);
|
||||
if (_scaledSize)
|
||||
reader.setScaledSize(QSize(_scaledSize, _scaledSize));
|
||||
reader.read(&img);
|
||||
_tile->pixmap().convertFromImage(img);
|
||||
}
|
||||
|
||||
const QString &file() const {return _file;}
|
||||
FetchTile *tile() {return _tile;}
|
||||
|
||||
private:
|
||||
QString _file;
|
||||
FetchTile *_tile;
|
||||
int _scaledSize;
|
||||
};
|
||||
|
||||
static QString fsSafeStr(const QString &str)
|
||||
{
|
||||
@ -74,7 +47,7 @@ static QString quadKey(const QPoint &xy, int zoom)
|
||||
}
|
||||
|
||||
TileLoader::TileLoader(const QString &dir, QObject *parent)
|
||||
: QObject(parent), _urlType(XYZ), _dir(dir), _scaledSize(0)
|
||||
: QObject(parent), _urlType(XYZ), _dir(dir)
|
||||
{
|
||||
if (!QDir().mkpath(_dir))
|
||||
qWarning("%s: %s", qPrintable(_dir), "Error creating tiles directory");
|
||||
@ -84,26 +57,20 @@ TileLoader::TileLoader(const QString &dir, QObject *parent)
|
||||
}
|
||||
|
||||
|
||||
void TileLoader::loadTilesAsync(QVector<FetchTile> &list)
|
||||
void TileLoader::loadTilesAsync(QVector<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<TileImage> imgs;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
FetchTile &t = list[i];
|
||||
Tile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
|
||||
if (QPixmapCache::find(file, &t.pixmap()))
|
||||
continue;
|
||||
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (fi.exists())
|
||||
imgs.append(TileImage(file, &t, _scaledSize));
|
||||
if (QFileInfo::exists(file))
|
||||
t.setFile(file);
|
||||
else {
|
||||
QUrl url(tileUrl(t));
|
||||
if (url.isLocalFile())
|
||||
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
|
||||
t.setFile(url.toLocalFile());
|
||||
else
|
||||
dl.append(Download(url, file));
|
||||
}
|
||||
@ -111,37 +78,23 @@ void TileLoader::loadTilesAsync(QVector<FetchTile> &list)
|
||||
|
||||
if (!dl.empty())
|
||||
_downloader->get(dl, _headers);
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(imgs, &TileImage::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++) {
|
||||
TileImage &ti = imgs[i];
|
||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void TileLoader::loadTilesSync(QVector<FetchTile> &list)
|
||||
void TileLoader::loadTilesSync(QVector<Tile> &list)
|
||||
{
|
||||
QList<Download> dl;
|
||||
QList<FetchTile *> tl;
|
||||
QList<TileImage> imgs;
|
||||
QList<Tile *> tl;
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
FetchTile &t = list[i];
|
||||
Tile &t = list[i];
|
||||
QString file(tileFile(t));
|
||||
|
||||
if (QPixmapCache::find(file, &t.pixmap()))
|
||||
continue;
|
||||
|
||||
QFileInfo fi(file);
|
||||
|
||||
if (fi.exists())
|
||||
imgs.append(TileImage(file, &t, _scaledSize));
|
||||
if (QFileInfo::exists(file))
|
||||
t.setFile(file);
|
||||
else {
|
||||
QUrl url(tileUrl(t));
|
||||
if (url.isLocalFile())
|
||||
imgs.append(TileImage(url.toLocalFile(), &t, _scaledSize));
|
||||
t.setFile(url.toLocalFile());
|
||||
else {
|
||||
dl.append(Download(url, file));
|
||||
tl.append(&t);
|
||||
@ -156,20 +109,12 @@ void TileLoader::loadTilesSync(QVector<FetchTile> &list)
|
||||
wait.exec();
|
||||
|
||||
for (int i = 0; i < tl.size(); i++) {
|
||||
FetchTile *t = tl[i];
|
||||
Tile *t = tl[i];
|
||||
QString file = tileFile(*t);
|
||||
if (QFileInfo(file).exists())
|
||||
imgs.append(TileImage(file, t, _scaledSize));
|
||||
t->setFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(imgs, &TileImage::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < imgs.size(); i++) {
|
||||
TileImage &ti = imgs[i];
|
||||
QPixmapCache::insert(ti.file(), ti.tile()->pixmap());
|
||||
}
|
||||
}
|
||||
|
||||
void TileLoader::clearCache()
|
||||
@ -181,20 +126,9 @@ void TileLoader::clearCache()
|
||||
dir.remove(list.at(i));
|
||||
|
||||
_downloader->clearErrors();
|
||||
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
void TileLoader::setScaledSize(int size)
|
||||
{
|
||||
if (_scaledSize == size)
|
||||
return;
|
||||
|
||||
_scaledSize = size;
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
QUrl TileLoader::tileUrl(const FetchTile &tile) const
|
||||
QUrl TileLoader::tileUrl(const Tile &tile) const
|
||||
{
|
||||
QString url(_url);
|
||||
|
||||
@ -218,9 +152,9 @@ QUrl TileLoader::tileUrl(const FetchTile &tile) const
|
||||
return QUrl(url);
|
||||
}
|
||||
|
||||
QString TileLoader::tileFile(const FetchTile &tile) const
|
||||
QString TileLoader::tileFile(const Tile &tile) const
|
||||
{
|
||||
QString zoom(((QMetaType::Type)(tile.zoom().type()) == QMetaType::Int)
|
||||
QString zoom(IS_INT(tile.zoom())
|
||||
? tile.zoom().toString() : fsSafeStr(tile.zoom().toString()));
|
||||
|
||||
return _dir + QLatin1Char('/') + zoom + QLatin1Char('-')
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include "common/downloader.h"
|
||||
#include "tile.h"
|
||||
#include "rectd.h"
|
||||
|
||||
class TileLoader : public QObject
|
||||
{
|
||||
@ -17,29 +17,55 @@ public:
|
||||
BoundingBox
|
||||
};
|
||||
|
||||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile() {}
|
||||
Tile(const QPoint &xy, int zoom)
|
||||
: _xy(xy), _zoom(zoom) {}
|
||||
Tile(const QPoint &xy, const QString &zoom)
|
||||
: _xy(xy), _zoom(zoom) {}
|
||||
Tile(const QPoint &xy, int zoom, const RectD &bbox)
|
||||
: _xy(xy), _zoom(zoom), _bbox(bbox) {}
|
||||
|
||||
const QVariant &zoom() const {return _zoom;}
|
||||
const QPoint &xy() const {return _xy;}
|
||||
const RectD &bbox() const {return _bbox;}
|
||||
const QString &file() const {return _file;}
|
||||
|
||||
private:
|
||||
friend class TileLoader;
|
||||
|
||||
void setFile(const QString &file) {_file = file;}
|
||||
|
||||
QPoint _xy;
|
||||
QVariant _zoom;
|
||||
RectD _bbox;
|
||||
QString _file;
|
||||
};
|
||||
|
||||
|
||||
TileLoader(const QString &dir, QObject *parent = 0);
|
||||
|
||||
void setUrl(const QString &url, UrlType type) {_url = url; _urlType = type;}
|
||||
void setHeaders(const QList<HTTPHeader> &headers) {_headers = headers;}
|
||||
void setScaledSize(int size);
|
||||
|
||||
void loadTilesAsync(QVector<FetchTile> &list);
|
||||
void loadTilesSync(QVector<FetchTile> &list);
|
||||
void loadTilesAsync(QVector<Tile> &list);
|
||||
void loadTilesSync(QVector<Tile> &list);
|
||||
void clearCache();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
QUrl tileUrl(const FetchTile &tile) const;
|
||||
QString tileFile(const FetchTile &tile) const;
|
||||
QUrl tileUrl(const Tile &tile) const;
|
||||
QString tileFile(const Tile &tile) const;
|
||||
|
||||
Downloader *_downloader;
|
||||
QString _url;
|
||||
UrlType _urlType;
|
||||
QString _dir;
|
||||
QList<HTTPHeader> _headers;
|
||||
int _scaledSize;
|
||||
};
|
||||
|
||||
#endif // TILELOADER_H
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include <QtCore>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
#include <QPixmapCache>
|
||||
#include <QtConcurrent>
|
||||
#include "common/wgs84.h"
|
||||
#include "common/rectc.h"
|
||||
#include "common/programpaths.h"
|
||||
#include "tile.h"
|
||||
#include "tileloader.h"
|
||||
#include "wmsmap.h"
|
||||
|
||||
@ -111,6 +114,7 @@ void WMSMap::load(const Projection &in, const Projection &out,
|
||||
void WMSMap::clearCache()
|
||||
{
|
||||
_tileLoader->clearCache();
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
QRectF WMSMap::bounds()
|
||||
@ -183,8 +187,8 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
QPoint br = QPoint(qCeil(rect.right() / tileSize()),
|
||||
qCeil(rect.bottom() / tileSize()));
|
||||
|
||||
QVector<FetchTile> tiles;
|
||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
QVector<TileLoader::Tile> fetchTiles;
|
||||
fetchTiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
for (int i = tl.x(); i < br.x(); i++) {
|
||||
for (int j = tl.y(); j < br.y(); j++) {
|
||||
PointD ttl(_transform.img2proj(QPointF(i * _tileSize,
|
||||
@ -195,21 +199,47 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
? RectD(PointD(tbr.y(), tbr.x()), PointD(ttl.y(), ttl.x()))
|
||||
: RectD(ttl, tbr);
|
||||
|
||||
tiles.append(FetchTile(QPoint(i, j), _zoom, bbox));
|
||||
fetchTiles.append(TileLoader::Tile(QPoint(i, j), _zoom, bbox));
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(tiles);
|
||||
_tileLoader->loadTilesSync(fetchTiles);
|
||||
else
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
_tileLoader->loadTilesAsync(fetchTiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
|
||||
if (!t.pixmap().isNull()) {
|
||||
t.pixmap().setDevicePixelRatio(_mapRatio);
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
}
|
||||
QList<FileTile> renderTiles;
|
||||
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||
if (t.file().isNull())
|
||||
continue;
|
||||
|
||||
QPixmap pm;
|
||||
if (QPixmapCache::find(t.file(), &pm)) {
|
||||
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
renderTiles.append(FileTile(t.xy(), t.file()));
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(renderTiles, &FileTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < renderTiles.size(); i++) {
|
||||
const FileTile &mt = renderTiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
||||
QPixmapCache::insert(mt.file(), pm);
|
||||
|
||||
QPointF tp(mt.xy().x() * tileSize(), mt.xy().y() * tileSize());
|
||||
drawTile(painter, pm, tp);
|
||||
}
|
||||
}
|
||||
|
||||
void WMSMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||
{
|
||||
pixmap.setDevicePixelRatio(_mapRatio);
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ private:
|
||||
void updateTransform();
|
||||
qreal tileSize() const;
|
||||
void init();
|
||||
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||
|
||||
QString _name;
|
||||
WMS *_wms;
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include <QtCore>
|
||||
#include <QPainter>
|
||||
#include <QDir>
|
||||
#include <QPixmapCache>
|
||||
#include <QtConcurrent>
|
||||
#include "common/rectc.h"
|
||||
#include "common/wgs84.h"
|
||||
#include "common/programpaths.h"
|
||||
#include "transform.h"
|
||||
#include "tileloader.h"
|
||||
#include "tile.h"
|
||||
#include "wmts.h"
|
||||
#include "wmtsmap.h"
|
||||
|
||||
@ -56,6 +59,7 @@ void WMTSMap::load(const Projection &in, const Projection &out,
|
||||
void WMTSMap::clearCache()
|
||||
{
|
||||
_tileLoader->clearCache();
|
||||
QPixmapCache::clear();
|
||||
}
|
||||
|
||||
double WMTSMap::sd2res(double scaleDenominator) const
|
||||
@ -189,25 +193,51 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
|
||||
QPoint br = QPoint(qCeil(rect.right() / ts.width()),
|
||||
qCeil(rect.bottom() / ts.height()));
|
||||
|
||||
QVector<FetchTile> tiles;
|
||||
tiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
QVector<TileLoader::Tile> fetchTiles;
|
||||
fetchTiles.reserve((br.x() - tl.x()) * (br.y() - tl.y()));
|
||||
for (int i = tl.x(); i < br.x(); i++)
|
||||
for (int j = tl.y(); j < br.y(); j++)
|
||||
tiles.append(FetchTile(QPoint(i, j), z.id()));
|
||||
fetchTiles.append(TileLoader::Tile(QPoint(i, j), z.id()));
|
||||
|
||||
if (flags & Map::Block)
|
||||
_tileLoader->loadTilesSync(tiles);
|
||||
_tileLoader->loadTilesSync(fetchTiles);
|
||||
else
|
||||
_tileLoader->loadTilesAsync(tiles);
|
||||
_tileLoader->loadTilesAsync(fetchTiles);
|
||||
|
||||
for (int i = 0; i < tiles.count(); i++) {
|
||||
FetchTile &t = tiles[i];
|
||||
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
|
||||
if (!t.pixmap().isNull()) {
|
||||
t.pixmap().setDevicePixelRatio(imageRatio());
|
||||
painter->drawPixmap(tp, t.pixmap());
|
||||
}
|
||||
QList<FileTile> renderTiles;
|
||||
for (int i = 0; i < fetchTiles.count(); i++) {
|
||||
const TileLoader::Tile &t = fetchTiles.at(i);
|
||||
if (t.file().isNull())
|
||||
continue;
|
||||
|
||||
QPixmap pm;
|
||||
if (QPixmapCache::find(t.file(), &pm)) {
|
||||
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
|
||||
drawTile(painter, pm, tp);
|
||||
} else
|
||||
renderTiles.append(FileTile(t.xy(), t.file()));
|
||||
}
|
||||
|
||||
QFuture<void> future = QtConcurrent::map(renderTiles, &FileTile::load);
|
||||
future.waitForFinished();
|
||||
|
||||
for (int i = 0; i < renderTiles.size(); i++) {
|
||||
const FileTile &mt = renderTiles.at(i);
|
||||
QPixmap pm(mt.pixmap());
|
||||
if (pm.isNull())
|
||||
continue;
|
||||
|
||||
QPixmapCache::insert(mt.file(), pm);
|
||||
|
||||
QPointF tp(mt.xy().x() * ts.width(), mt.xy().y() * ts.height());
|
||||
drawTile(painter, pm, tp);
|
||||
}
|
||||
}
|
||||
|
||||
void WMTSMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
|
||||
{
|
||||
pixmap.setDevicePixelRatio(imageRatio());
|
||||
painter->drawPixmap(tp, pixmap);
|
||||
}
|
||||
|
||||
QPointF WMTSMap::ll2xy(const Coordinates &c)
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
qreal coordinatesRatio() const;
|
||||
qreal imageRatio() const;
|
||||
void init();
|
||||
void drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp);
|
||||
|
||||
QString _name;
|
||||
WMTS *_wmts;
|
||||
|
Reference in New Issue
Block a user