QGIS API Documentation 3.39.0-Master (d85f3c2a281)
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 "qgsthreadingutils.h"
18#include "qgsvectortileloader.h"
19
20#include <QNetworkRequest>
21#include <QImage>
22
23
24int QgsVectorTileDataProvider::DATA_COLUMN = QNetworkRequest::User + 1;
25int QgsVectorTileDataProvider::DATA_ROW = QNetworkRequest::User + 2;
26int QgsVectorTileDataProvider::DATA_ZOOM = QNetworkRequest::User + 3;
27int QgsVectorTileDataProvider::DATA_SOURCE_ID = QNetworkRequest::User + 4;
28
30 const QString &uri,
31 const ProviderOptions &options,
33 : QgsDataProvider( uri, options, flags )
35{}
36
38 : QgsDataProvider( other.dataSourceUri( false ), ProviderOptions(), other.mReadFlags )
39 , mShared( other.mShared )
40{
42}
43
48
53
60
62{
64
65 // Vector tiles by design are very CPU light to render, so we are much more permissive here compared
66 // with other layer types. (Generally if a vector tile layer has taken more than a few milliseconds to render it's
67 // a result of network requests, and the tile manager class handles these gracefully for us)
68 return context.lastRenderingTimeMs <= 1000;
69}
70
77
79{
81
82 return QList<QNetworkRequest>();
83}
84
86{
88
89 return QVariantMap();
90}
91
93{
95
96 return QString();
97}
98
100{
102
103 return QVariantMap();
104}
105
107{
109
110 return QImage();
111}
112
113
114
119
121{
122 QMutexLocker locker( &mMutex );
123 if ( QgsVectorTileRawData *cachedData = mTileCache.object( tile ) )
124 {
125 data = *cachedData;
126 return true;
127 }
128
129 return false;
130}
131
133{
134 QMutexLocker locker( &mMutex );
135 mTileCache.insert( data.id, new QgsVectorTileRawData( data ) );
136}
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
Definition qgis.h:5131
RendererUsage
Usage of the renderer.
Definition qgis.h:3186
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
Definition qgis.h:5113
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.