28 : mEventLoop( new QEventLoop )
29 , mFeedback( feedback )
33 connect( feedback, &
QgsFeedback::canceled,
this, &QgsVectorTileLoader::canceled, Qt::QueuedConnection );
42 QVector<QgsTileXYZ> tiles = tileMatrixSet.
tilesInRange( range, zoomLevel );
46 loadFromNetworkAsync(
id, tileMatrixSet, provider, usage );
54 if ( !mReplies.isEmpty() )
66 QgsDebugMsgLevel( QStringLiteral(
"downloadBlocking - not staring event loop - canceled" ), 2 );
70 int repliesCount = std::accumulate( mReplies.constBegin(), mReplies.constEnd(), 0, [](
int count, QList<QgsTileDownloadManagerReply *> replies ) {return count + replies.count();} );
71 Q_UNUSED( repliesCount )
72 QgsDebugMsgLevel( QStringLiteral(
"Starting event loop with %1 requests" ).arg( repliesCount ), 2 );
74 mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );
78 Q_ASSERT( mReplies.isEmpty() );
83 const QList<QNetworkRequest> requests = provider->
tileRequests( tileMatrixSet,
id, usage );
85 for (
const QNetworkRequest &request : requests )
89 mReplies[id].append( reply );
93void QgsVectorTileLoader::tileReplyFinished()
104 if ( reply->
error() == QNetworkReply::NoError )
108 QgsDebugMsgLevel( QStringLiteral(
"Tile download successful: " ) + tileID.toString(), 2 );
109 QByteArray rawData = reply->
data();
110 mReplies[tileID].removeOne( reply );
111 mPendingRawData[tileID][sourceId] = rawData;
112 reply->deleteLater();
114 if ( mReplies[tileID].count() == 0 )
116 mReplies.remove( tileID );
122 if ( reply->
error() == QNetworkReply::ContentAccessDenied )
124 if ( reply->
data().isEmpty() )
125 mError = tr(
"Access denied" );
127 mError = tr(
"Access denied: %1" ).arg( QString( reply->
data() ) );
131 mReplies[tileID].removeOne( reply );
132 reply->deleteLater();
134 if ( mReplies[tileID].count() == 0 )
136 mReplies.remove( tileID );
141 if ( mReplies.isEmpty() )
144 QMetaObject::invokeMethod( mEventLoop.get(),
"quit", Qt::QueuedConnection );
148void QgsVectorTileLoader::canceled()
150 int repliesCount = std::accumulate( mReplies.constBegin(), mReplies.constEnd(), 0, [](
int count, QList<QgsTileDownloadManagerReply *> replies ) {return count + replies.count();} );
151 Q_UNUSED( repliesCount )
152 QgsDebugMsgLevel( QStringLiteral(
"Canceling %1 pending requests" ).arg( repliesCount ), 2 );
153 QHash<QgsTileXYZ, QList<QgsTileDownloadManagerReply *>>::iterator it = mReplies.begin();
154 for ( ; it != mReplies.end(); ++it )
155 qDeleteAll( it.value() );
175 QVector<QgsTileXYZ> tiles = tileMatrixSet.
tilesInRange( range, zoomLevel );
178 if ( tiles.size() < 10000 )
181 return provider->
readTiles( tileMatrixSet, tiles, feedback, usage );
RendererUsage
Usage of the renderer.
static QgsTileDownloadManager * tileDownloadManager()
Returns the application's tile download manager, used for download of map tiles when rendering.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
void canceled()
Internal routines can connect to this signal if they use event loop.
Reply object for tile download manager requests returned from calls to QgsTileDownloadManager::get().
QString errorString() const
Returns error string (only valid when already finished)
QNetworkRequest request() const
Returns the original request for this reply object.
QByteArray data() const
Returns binary data returned in the reply (only valid when already finished)
QNetworkReply::NetworkError error() const
Returns error code (only valid when already finished)
void finished()
Emitted when the reply has finished (either with a success or with a failure)
QgsTileDownloadManagerReply * get(const QNetworkRequest &request)
Starts a request.
Defines a set of tile matrices for multiple zoom levels.
QVector< QgsTileXYZ > tilesInRange(QgsTileRange range, int zoomLevel) const
Returns a list of tiles in the given tile range.
Range of tiles in a tile matrix to be rendered.
Stores coordinates of a tile in a tile matrix set.
Base class for vector tile layer data providers.
virtual QList< QgsVectorTileRawData > readTiles(const QgsTileMatrixSet &tileMatrixSet, const QVector< QgsTileXYZ > &tiles, QgsFeedback *feedback=nullptr, Qgis::RendererUsage usage=Qgis::RendererUsage::Unknown) const =0
Returns raw tile data for a range of tiles.
static int DATA_ZOOM
Role to set zoom attribute in the request so it can be retrieved later.
static int DATA_ROW
Role to set row attribute in the request so it can be retrieved later.
virtual QList< QNetworkRequest > tileRequests(const QgsTileMatrixSet &tileMatrixSet, const QgsTileXYZ &id, Qgis::RendererUsage usage) const
Returns a network request for a tile.
static int DATA_SOURCE_ID
Role to set source ID attribute in the request so it can be retrieved later.
static int DATA_COLUMN
Role to set column attribute in the request so it can be retrieved later.
void tileRequestFinished(const QgsVectorTileRawData &rawTile)
Emitted when a tile request has finished. If a tile request has failed, the returned raw tile byte ar...
QString error() const
Returns a eventual error that occurred during loading, void if no error.
void downloadBlocking()
Blocks the caller until all asynchronous requests are finished (with a success or a failure)
static QList< QgsVectorTileRawData > blockingFetchTileRawData(const QgsVectorTileDataProvider *provider, const QgsTileMatrixSet &tileMatrixSet, const QPointF &viewCenter, const QgsTileRange &range, int zoomLevel, QgsFeedback *feedback=nullptr, Qgis::RendererUsage usage=Qgis::RendererUsage::Unknown)
Returns raw tile data for the specified range of tiles. Blocks the caller until all tiles are fetched...
QgsVectorTileLoader(const QgsVectorTileDataProvider *provider, const QgsTileMatrixSet &tileMatrixSet, const QgsTileRange &range, int zoomLevel, const QPointF &viewCenter, QgsFeedback *feedback, Qgis::RendererUsage usage)
Constructs tile loader for doing asynchronous requests and starts network requests.
Keeps track of raw tile data from one or more sources that need to be decoded.
static void sortTilesByDistanceFromCenter(QVector< QgsTileXYZ > &tiles, QPointF center)
Orders tile requests according to the distance from view center (given in tile matrix coords)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)