QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsvectortiledataprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortiledataprovider.cpp
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
17#include "moc_qgsvectortiledataprovider.cpp"
18#include "qgsthreadingutils.h"
19#include "qgsvectortileloader.h"
20
21#include <QNetworkRequest>
22#include <QImage>
23
24
25int QgsVectorTileDataProvider::DATA_COLUMN = QNetworkRequest::User + 1;
26int QgsVectorTileDataProvider::DATA_ROW = QNetworkRequest::User + 2;
27int QgsVectorTileDataProvider::DATA_ZOOM = QNetworkRequest::User + 3;
28int QgsVectorTileDataProvider::DATA_SOURCE_ID = QNetworkRequest::User + 4;
29
31 const QString &uri,
32 const ProviderOptions &options,
34 : QgsDataProvider( uri, options, flags )
36{}
37
39 : QgsDataProvider( other.dataSourceUri( false ), ProviderOptions(), other.mReadFlags )
40 , mShared( other.mShared )
41{
43}
44
49
54
61
63{
65
66 // Vector tiles by design are very CPU light to render, so we are much more permissive here compared
67 // with other layer types. (Generally if a vector tile layer has taken more than a few milliseconds to render it's
68 // a result of network requests, and the tile manager class handles these gracefully for us)
69 return context.lastRenderingTimeMs <= 1000;
70}
71
78
80{
82
83 return QList<QNetworkRequest>();
84}
85
87{
89
90 return QVariantMap();
91}
92
94{
96
97 return QString();
98}
99
101{
103
104 return QVariantMap();
105}
106
108{
110
111 return QImage();
112}
113
114
115
120
122{
123 QMutexLocker locker( &mMutex );
124 if ( QgsVectorTileRawData *cachedData = mTileCache.object( tile ) )
125 {
126 data = *cachedData;
127 return true;
128 }
129
130 return false;
131}
132
134{
135 QMutexLocker locker( &mMutex );
136 mTileCache.insert( data.id, new QgsVectorTileRawData( data ) );
137}
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
Definition qgis.h:5259
RendererUsage
Usage of the renderer.
Definition qgis.h:3259
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
Definition qgis.h:5241
Abstract base class for spatial data provider implementations.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
A rectangle specified with double values.
Defines a set of tile matrices for multiple zoom levels.
Definition qgstiles.h:252
Stores coordinates of a tile in a tile matrix set.
Definition qgstiles.h:40
Shared data class for vector tile layer data providers.
void storeCachedTileData(const QgsVectorTileRawData &data)
Stores raw tile data in the shared cache.
QCache< QgsTileXYZ, QgsVectorTileRawData > mTileCache
bool getCachedTileData(QgsVectorTileRawData &data, QgsTileXYZ id)
Retrieves previously cached raw tile data for a tile with matching id.
QMutex mMutex
Access to all data members is guarded by the mutex.
Base class for vector tile layer data providers.
QgsRectangle extent() const override
Returns the extent of the layer.
static int DATA_ZOOM
Role to set zoom attribute in the request so it can be retrieved later.
virtual Qgis::VectorTileProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
virtual QString styleUrl() const
Returns the URL for the provider style, if available.
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.
QgsVectorTileDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, Qgis::DataProviderReadFlags flags)
Constructor for QgsVectorTileDataProvider, with the specified uri.
virtual Qgis::VectorTileProviderFlags providerFlags() const
Returns flags reflecting the behavior of the data provider.
static int DATA_COLUMN
Role to set column attribute in the request so it can be retrieved later.
virtual bool supportsAsync() const
Returns true if the provider supports async tile reading.
virtual QVariantMap spriteDefinition() const
Returns the sprite definition for the provider, if available.
virtual QVariantMap styleDefinition() const
Returns the style definition for the provider, if available.
bool renderInPreview(const QgsDataProvider::PreviewContext &context) override
Returns whether the layer must be rendered in preview jobs.
virtual QImage spriteImage() const
Returns the sprite image for the provider, if available.
Keeps track of raw tile data from one or more sources that need to be decoded.
QgsTileXYZ id
Tile position in tile matrix set.
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Stores settings related to the context in which a preview job runs.
double lastRenderingTimeMs
Previous rendering time for the layer, in ms.
Setting options for creating vector data providers.