QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 "qgsreadwritelocker.h"
19#include "qgsvectortileloader.h"
20
21#include <QNetworkRequest>
22#include <QImage>
23
25 const QString &uri,
26 const ProviderOptions &options,
28 : QgsDataProvider( uri, options, flags )
30{}
31
33 : QgsDataProvider( other.dataSourceUri( false ), ProviderOptions(), other.mReadFlags )
34 , mShared( other.mShared )
35{
37}
38
40{
42}
43
45{
47}
48
50{
52
53 return QgsRectangle();
54}
55
57{
59
60 // Vector tiles by design are very CPU light to render, so we are much more permissive here compared
61 // with other layer types. (Generally if a vector tile layer has taken more than a few milliseconds to render it's
62 // a result of network requests, and the tile manager class handles these gracefully for us)
63 return context.lastRenderingTimeMs <= 1000;
64}
65
67{
69
70 return false;
71}
72
74{
76
77 return QNetworkRequest();
78}
79
81{
83
84 return QVariantMap();
85}
86
88{
90
91 return QString();
92}
93
95{
97
98 return QVariantMap();
99}
100
102{
104
105 return QImage();
106}
107
108
109
111{
112 mTileCache.setMaxCost( 200 );
113}
114
116{
117 QMutexLocker locker( &mMutex );
118 if ( QgsVectorTileRawData *cachedData = mTileCache.object( tile ) )
119 {
120 data = *cachedData;
121 return true;
122 }
123
124 return false;
125}
126
128{
129 QMutexLocker locker( &mMutex );
130 mTileCache.insert( data.id, new QgsVectorTileRawData( data ) );
131}
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
Definition: qgis.h:4518
RendererUsage
Usage of the renderer.
Definition: qgis.h:2803
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
Definition: qgis.h:4500
Abstract base class for spatial data provider implementations.
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
QFlags< ReadFlag > ReadFlags
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)
Sets data coordinate transform context to transformContext.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Defines a set of tile matrices for multiple zoom levels.
Definition: qgstiles.h:250
Stores coordinates of a tile in a tile matrix set.
Definition: qgstiles.h:38
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.
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.
QgsVectorTileDataProvider(const QString &uri, const QgsDataProvider::ProviderOptions &providerOptions, QgsDataProvider::ReadFlags flags)
Constructor for QgsVectorTileDataProvider, with the specified uri.
virtual Qgis::VectorTileProviderFlags providerFlags() const
Returns flags reflecting the behavior of the data provider.
virtual QNetworkRequest tileRequest(const QgsTileMatrixSet &tileMatrixSet, const QgsTileXYZ &id, Qgis::RendererUsage usage) const
Returns a network request for a tile.
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 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.