QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
18#include "qgsthreadingutils.h"
19#include "qgsvectortileloader.h"
20
21#include <QImage>
22#include <QNetworkRequest>
23
24#include "moc_qgsvectortiledataprovider.cpp"
25
26int QgsVectorTileDataProvider::DATA_COLUMN = QNetworkRequest::User + 1;
27int QgsVectorTileDataProvider::DATA_ROW = QNetworkRequest::User + 2;
28int QgsVectorTileDataProvider::DATA_ZOOM = QNetworkRequest::User + 3;
29int QgsVectorTileDataProvider::DATA_SOURCE_ID = QNetworkRequest::User + 4;
30
38
45
50
55
62
64{
66
67 // Vector tiles by design are very CPU light to render, so we are much more permissive here compared
68 // with other layer types. (Generally if a vector tile layer has taken more than a few milliseconds to render it's
69 // a result of network requests, and the tile manager class handles these gracefully for us)
70 return context.lastRenderingTimeMs <= 1000;
71}
72
79
81{
83
84 return QList<QNetworkRequest>();
85}
86
88{
90
91 return QVariantMap();
92}
93
95{
97
98 return QString();
99}
100
102{
104
105 return QVariantMap();
106}
107
109{
111
112 return QImage();
113}
114
115
116
121
123{
124 QMutexLocker locker( &mMutex );
125 if ( QgsVectorTileRawData *cachedData = mTileCache.object( tile ) )
126 {
127 data = *cachedData;
128 return true;
129 }
130
131 return false;
132}
133
135{
136 QMutexLocker locker( &mMutex );
137 mTileCache.insert( data.id, new QgsVectorTileRawData( data ) );
138}
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
Definition qgis.h:5598
RendererUsage
Usage of the renderer.
Definition qgis.h:3445
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
Definition qgis.h:5580
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
virtual Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
QgsDataSourceUri uri() const
Gets the data source specification.
Qgis::DataProviderReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when needed.
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:274
Stores coordinates of a tile in a tile matrix set.
Definition qgstiles.h:39
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.
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.
std::shared_ptr< QgsVectorTileDataProviderSharedData > mShared
Mutable data shared between provider instances.
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.