QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsvectortileloader.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortileloader.h
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORTILELOADER_H
17 #define QGSVECTORTILELOADER_H
18 
19 #define SIP_NO_FILE
20 
21 class QByteArray;
22 
23 #include "qgsvectortilerenderer.h"
24 #include "qgshttpheaders.h"
25 
33 {
34  public:
36  QgsVectorTileRawData( QgsTileXYZ tileID = QgsTileXYZ(), const QByteArray &raw = QByteArray() )
37  : id( tileID ), data( raw ) {}
38 
42  QByteArray data;
43 };
44 
45 
46 class QNetworkReply;
47 class QEventLoop;
48 
49 class QgsMbTiles;
50 
52 
59 class QgsVectorTileLoader : public QObject
60 {
61  Q_OBJECT
62  public:
63 
65  static QList<QgsVectorTileRawData> blockingFetchTileRawData( const QString &sourceType,
66  const QString &sourcePath,
67  const QgsTileMatrix &tileMatrix,
68  const QPointF &viewCenter,
69  const QgsTileRange &range,
70  const QString &authid,
71  const QgsHttpHeaders &headers,
72  QgsFeedback *feedback = nullptr );
73 
75  static QByteArray loadFromNetwork( const QgsTileXYZ &id,
76  const QgsTileMatrix &tileMatrix,
77  const QString &requestUrl,
78  const QString &authid,
79  const QgsHttpHeaders &headers,
80  QgsFeedback *feedback = nullptr );
82  static QByteArray loadFromMBTiles( const QgsTileXYZ &id, QgsMbTiles &mbTileReader, QgsFeedback *feedback = nullptr );
83 
84  //
85  // non-static stuff
86  //
87 
89  QgsVectorTileLoader( const QString &uri, const QgsTileMatrix &tileMatrix, const QgsTileRange &range, const QPointF &viewCenter,
90  const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback );
92 
94  void downloadBlocking();
95 
97  QString error() const;
98 
99  private:
100  void loadFromNetworkAsync( const QgsTileXYZ &id, const QgsTileMatrix &tileMatrix, const QString &requestUrl );
101 
102  private slots:
103  void tileReplyFinished();
104  void canceled();
105 
106  signals:
109 
110  private:
112  std::unique_ptr<QEventLoop> mEventLoop;
114  QgsFeedback *mFeedback;
115 
116  QString mAuthCfg;
117  QgsHttpHeaders mHeaders;
118 
120  QList<QgsTileDownloadManagerReply *> mReplies;
121 
122  QString mError;
123 
124 };
125 
126 #endif // QGSVECTORTILELOADER_H
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
This class implements simple http header management.
Utility class for reading and writing MBTiles files (which are SQLite3 databases).
Definition: qgsmbtiles.h:39
Reply object for tile download manager requests returned from calls to QgsTileDownloadManager::get().
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Definition: qgstiles.h:108
Range of tiles in a tile matrix to be rendered.
Definition: qgstiles.h:71
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:38
The loader class takes care of loading raw vector tile data from a tile source.
void tileRequestFinished(const QgsVectorTileRawData &rawTile)
Emitted when a tile request has finished. If a tile request has failed, the returned raw tile byte ar...
static QList< QgsVectorTileRawData > blockingFetchTileRawData(const QString &sourceType, const QString &sourcePath, const QgsTileMatrix &tileMatrix, const QPointF &viewCenter, const QgsTileRange &range, const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback=nullptr)
Returns raw tile data for the specified range of tiles. Blocks the caller until all tiles are fetched...
QString error() const
Returns a eventual error that occurred during loading, void if no error.
static QByteArray loadFromNetwork(const QgsTileXYZ &id, const QgsTileMatrix &tileMatrix, const QString &requestUrl, const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback=nullptr)
Returns raw tile data for a single tile, doing a HTTP request. Block the caller until tile data are d...
static QByteArray loadFromMBTiles(const QgsTileXYZ &id, QgsMbTiles &mbTileReader, QgsFeedback *feedback=nullptr)
Returns raw tile data for a single tile loaded from MBTiles file.
void downloadBlocking()
Blocks the caller until all asynchronous requests are finished (with a success or a failure)
QgsVectorTileLoader(const QString &uri, const QgsTileMatrix &tileMatrix, const QgsTileRange &range, const QPointF &viewCenter, const QString &authid, const QgsHttpHeaders &headers, QgsFeedback *feedback)
Constructs tile loader for doing asynchronous requests and starts network requests.
Keeps track of raw tile data that need to be decoded.
QgsVectorTileRawData(QgsTileXYZ tileID=QgsTileXYZ(), const QByteArray &raw=QByteArray())
Constructs a raw tile object.
QByteArray data
Raw tile data.
QgsTileXYZ id
Tile position in tile matrix set.