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 QgsDebugMsgLevel( QStringLiteral(
"Starting event loop with %1 requests" ).arg( mReplies.count() ), 2 );
72 mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );
76 Q_ASSERT( mReplies.isEmpty() );
81 QNetworkRequest request = provider->
tileRequest( tileMatrixSet,
id, usage );
88void QgsVectorTileLoader::tileReplyFinished()
92 int reqX = reply->
request().attribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 1 ) ).toInt();
93 int reqY = reply->
request().attribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 2 ) ).toInt();
94 int reqZ = reply->
request().attribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 3 ) ).toInt();
97 if ( reply->
error() == QNetworkReply::NoError )
101 QgsDebugMsgLevel( QStringLiteral(
"Tile download successful: " ) + tileID.toString(), 2 );
102 QByteArray rawData = reply->
data();
103 mReplies.removeOne( reply );
104 reply->deleteLater();
110 if ( reply->
error() == QNetworkReply::ContentAccessDenied )
112 if ( reply->
data().isEmpty() )
113 mError = tr(
"Access denied" );
115 mError = tr(
"Access denied: %1" ).arg( QString( reply->
data() ) );
119 mReplies.removeOne( reply );
120 reply->deleteLater();
125 if ( mReplies.isEmpty() )
128 QMetaObject::invokeMethod( mEventLoop.get(),
"quit", Qt::QueuedConnection );
132void QgsVectorTileLoader::canceled()
134 QgsDebugMsgLevel( QStringLiteral(
"Canceling %1 pending requests" ).arg( mReplies.count() ), 2 );
135 qDeleteAll( mReplies );
155 QVector<QgsTileXYZ> tiles = tileMatrixSet.
tilesInRange( range, zoomLevel );
158 if ( tiles.size() < 10000 )
161 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.
virtual QNetworkRequest tileRequest(const QgsTileMatrixSet &tileMatrixSet, const QgsTileXYZ &id, Qgis::RendererUsage usage) const
Returns a network request for a tile.
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 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)