File indexing completed on 2024-07-14 03:50:08

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2016 Dennis Nienhüser <nienhueser@kde.org>
0004 //
0005 
0006 #ifndef MARBLE_TILEDIRECTORY_H
0007 #define MARBLE_TILEDIRECTORY_H
0008 
0009 #include "VectorClipper.h"
0010 #include "TagsFilter.h"
0011 #include <TileId.h>
0012 #include <GeoDataLinearRing.h>
0013 #include <ParsingRunnerManager.h>
0014 #include <GeoSceneMercatorTileProjection.h>
0015 
0016 #include <QNetworkAccessManager>
0017 #include <QSharedPointer>
0018 #include <QObject>
0019 #include <QFile>
0020 
0021 class QNetworkReply;
0022 
0023 namespace Marble {
0024 
0025 class Download : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     QString target;
0031     QNetworkReply* reply;
0032     qint64 received;
0033     qint64 total;
0034 
0035 public Q_SLOTS:
0036     void updateProgress(qint64 received, qint64 total);
0037 
0038 private:
0039     QFile m_file;
0040 };
0041 
0042 class TileDirectory : public QObject
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047 
0048     enum TileType
0049     {
0050         Landmass,
0051         OpenStreetMap
0052     };
0053 
0054     enum InputType
0055     {
0056         OsmxInput,
0057         RawInput
0058     };
0059 
0060     TileDirectory(TileType tileType, const QString &cacheDir, ParsingRunnerManager &manager, int maxZoomLevel);
0061     /** Create a tile directory for loading data from an OSMX file.
0062      *  @param maxZoomLevel The output zoom level.
0063      *  @param loadZoomLevel The zoom level at which the input data should be loaded.
0064      *  This must be smaller or equal to maxZoomLevel. Using a smaller value can be more efficient when
0065      *  generating a larger batch of tiles that fall within a lower zoom level tile, but comes at a greater
0066      *  cost for memory and clipping operations.
0067      *  @param inputType specifies whether to query from an OSMX file or whether to load the input file entirely.
0068      *  The latter is used for automated testing.
0069      */
0070     TileDirectory(const QString &cacheDir, const QString &osmxFile, ParsingRunnerManager &manager, int maxZoomLevel, int loadZoomLevel, InputType inputType);
0071 
0072     QSharedPointer<GeoDataDocument> load(int zoomLevel, int tileX, int tileY);
0073     void setInputFile(const QString &filename);
0074 
0075     TileId tileFor(int zoomLevel, int tileX, int tileY) const;
0076     GeoDataDocument *clip(int zoomLevel, int tileX, int tileY);
0077     QString name() const;
0078 
0079     static QSharedPointer<GeoDataDocument> open(const QString &filename, ParsingRunnerManager &manager);
0080     GeoDataLatLonBox boundingBox(const QString &filename) const;
0081     GeoDataLatLonBox boundingBox() const;
0082     void setBoundingBox(const GeoDataLatLonBox &boundingBox);
0083     void setBoundingPolygon(const QString &filename);
0084     void createTiles();
0085     void createOsmTiles() const;
0086     int innerNodes(const TileId &tile) const;
0087 
0088     static void printProgress(double progress, int barWidth=40);
0089 
0090 private Q_SLOTS:
0091     void updateProgress();
0092     void handleFinishedDownload(const QString &filename, const QString &id);
0093 
0094 private:
0095     TagsFilter::Tags tagsFilteredIn(int zoomLevel) const;
0096     void setTagZoomLevel(int zoomLevel);
0097     void download(const QString &url, const QString &target);
0098     QString osmFileFor(const TileId &tileId) const;
0099 
0100     QString m_cacheDir;
0101     QString m_baseDir;
0102     QString m_osmxFile;
0103     ParsingRunnerManager &m_manager;
0104     QSharedPointer<GeoDataDocument> m_landmass;
0105     int m_zoomLevel = -1;
0106     int m_tileX = -1;
0107     int m_tileY = -1;
0108     int m_tagZoomLevel = -1;
0109     QSharedPointer<VectorClipper> m_clipper;
0110     QSharedPointer<TagsFilter> m_tagsFilter;
0111     TileType m_tileType;
0112     InputType m_inputType = OsmxInput;
0113     QString m_inputFile;
0114     GeoDataLatLonBox m_boundingBox;
0115     QVector<GeoDataLinearRing> m_boundingPolygon;
0116     QNetworkAccessManager m_downloadManager;
0117     GeoSceneMercatorTileProjection m_tileProjection;
0118     QString m_landmassFile;
0119     QSharedPointer<Download> m_download;
0120     int m_maxZoomLevel;
0121     static QMap<int, TagsFilter::Tags> m_tags;
0122 };
0123 
0124 }
0125 
0126 #endif