1 // SPDX-License-Identifier: LGPL-2.1-or-later 2 // 3 // SPDX-FileCopyrightText: 2016 Dennis Nienhüser <nienhueser@kde.org> 4 // 5 6 #ifndef MARBLE_TILEDIRECTORY_H 7 #define MARBLE_TILEDIRECTORY_H 8 9 #include "VectorClipper.h" 10 #include "TagsFilter.h" 11 #include <TileId.h> 12 #include <GeoDataLinearRing.h> 13 #include <ParsingRunnerManager.h> 14 #include <GeoSceneMercatorTileProjection.h> 15 16 #include <QNetworkAccessManager> 17 #include <QSharedPointer> 18 #include <QObject> 19 #include <QFile> 20 21 class QNetworkReply; 22 23 namespace Marble { 24 25 class Download : public QObject 26 { 27 Q_OBJECT 28 29 public: 30 QString target; 31 QNetworkReply* reply; 32 qint64 received; 33 qint64 total; 34 35 public Q_SLOTS: 36 void updateProgress(qint64 received, qint64 total); 37 38 private: 39 QFile m_file; 40 }; 41 42 class TileDirectory : public QObject 43 { 44 Q_OBJECT 45 46 public: 47 48 enum TileType 49 { 50 Landmass, 51 OpenStreetMap 52 }; 53 54 TileDirectory(TileType tileType, const QString &cacheDir, ParsingRunnerManager &manager, int maxZoomLevel); 55 /** Create a tile directory for loading data from an OSMX file. 56 * @param maxZoomLevel The output zoom level. 57 * @param loadZoomLevel The zoom level at which the input data should be loaded. 58 * This must be smaller or equal to maxZoomLevel. Using a smaller value can be more efficient when 59 * generating a larger batch of tiles that fall within a lower zoom level tile, but comes at a greater 60 * cost for memory and clipping operations. 61 */ 62 TileDirectory(const QString &cacheDir, const QString &osmxFile, ParsingRunnerManager &manager, int maxZoomLevel, int loadZoomLevel); 63 64 QSharedPointer<GeoDataDocument> load(int zoomLevel, int tileX, int tileY); 65 void setInputFile(const QString &filename); 66 67 TileId tileFor(int zoomLevel, int tileX, int tileY) const; 68 GeoDataDocument *clip(int zoomLevel, int tileX, int tileY); 69 QString name() const; 70 71 static QSharedPointer<GeoDataDocument> open(const QString &filename, ParsingRunnerManager &manager); 72 GeoDataLatLonBox boundingBox(const QString &filename) const; 73 GeoDataLatLonBox boundingBox() const; 74 void setBoundingBox(const GeoDataLatLonBox &boundingBox); 75 void setBoundingPolygon(const QString &filename); 76 void createTiles() const; 77 void createOsmTiles() const; 78 int innerNodes(const TileId &tile) const; 79 80 static void printProgress(double progress, int barWidth=40); 81 82 private Q_SLOTS: 83 void updateProgress(); 84 void handleFinishedDownload(const QString &filename, const QString &id); 85 86 private: 87 TagsFilter::Tags tagsFilteredIn(int zoomLevel) const; 88 void setTagZoomLevel(int zoomLevel); 89 void download(const QString &url, const QString &target); 90 QString osmFileFor(const TileId &tileId) const; 91 92 QString m_cacheDir; 93 QString m_baseDir; 94 QString m_osmxFile; 95 ParsingRunnerManager &m_manager; 96 QSharedPointer<GeoDataDocument> m_landmass; 97 int m_zoomLevel = -1; 98 int m_tileX = -1; 99 int m_tileY = -1; 100 int m_tagZoomLevel = -1; 101 QSharedPointer<VectorClipper> m_clipper; 102 QSharedPointer<TagsFilter> m_tagsFilter; 103 TileType m_tileType; 104 QString m_inputFile; 105 GeoDataLatLonBox m_boundingBox; 106 QVector<GeoDataLinearRing> m_boundingPolygon; 107 QNetworkAccessManager m_downloadManager; 108 GeoSceneMercatorTileProjection m_tileProjection; 109 QString m_landmassFile; 110 QSharedPointer<Download> m_download; 111 int m_maxZoomLevel; 112 static QMap<int, TagsFilter::Tags> m_tags; 113 }; 114 115 } 116 117 #endif 118