29#include <QNetworkRequest>
33QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY = QStringLiteral(
"xyzvectortiles" );
34QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION = QObject::tr(
"XYZ Vector Tiles data provider" );
40QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase(
const QString &uri,
const ProviderOptions &providerOptions, ReadFlags flags )
49QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase(
const QgsXyzVectorTileDataProviderBase &other )
52 mAuthCfg = other.mAuthCfg;
53 mHeaders = other.mHeaders;
56bool QgsXyzVectorTileDataProviderBase::supportsAsync()
const
68 QList<QgsVectorTileRawData> rawTiles;
69 rawTiles.reserve( tiles.size() );
70 const QString source = sourcePath();
76 const QByteArray rawData = loadFromNetwork(
id, set.
tileMatrix(
id.zoomLevel() ), source, mAuthCfg, mHeaders, feedback, usage );
77 if ( !rawData.isEmpty() )
87 QString urlTemplate = sourcePath();
89 if ( urlTemplate.contains( QLatin1String(
"{usage}" ) ) )
94 urlTemplate.replace( QLatin1String(
"{usage}" ), QLatin1String(
"view" ) );
97 urlTemplate.replace( QLatin1String(
"{usage}" ), QLatin1String(
"export" ) );
100 urlTemplate.replace( QLatin1String(
"{usage}" ), QString() );
107 QNetworkRequest request( url );
111 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 1 ),
id.column() );
112 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 2 ),
id.row() );
113 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 3 ),
id.zoomLevel() );
115 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
116 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute,
true );
118 mHeaders.updateNetworkRequest( request );
132 if ( url.contains( QLatin1String(
"{usage}" ) ) )
137 url.replace( QLatin1String(
"{usage}" ), QLatin1String(
"view" ) );
140 url.replace( QLatin1String(
"{usage}" ), QLatin1String(
"export" ) );
143 url.replace( QLatin1String(
"{usage}" ), QString() );
149 nr.setUrl( QUrl( url ) );
173QgsXyzVectorTileDataProviderMetadata::QgsXyzVectorTileDataProviderMetadata()
174 :
QgsProviderMetadata( QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY, QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION )
180 return new QgsXyzVectorTileDataProvider( uri, options, flags );
183QIcon QgsXyzVectorTileDataProviderMetadata::icon()
const
190 return FileBasedUris;
193QVariantMap QgsXyzVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
198 QVariantMap uriComponents;
199 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
201 if ( uriComponents[ QStringLiteral(
"type" ) ] == QLatin1String(
"mbtiles" ) ||
202 ( uriComponents[ QStringLiteral(
"type" ) ] == QLatin1String(
"xyz" ) &&
203 !dsUri.
param( QStringLiteral(
"url" ) ).startsWith( QLatin1String(
"http" ) ) ) )
205 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
209 uriComponents.insert( QStringLiteral(
"url" ), dsUri.
param( QStringLiteral(
"url" ) ) );
212 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
213 uriComponents.insert( QStringLiteral(
"zmin" ), dsUri.
param( QStringLiteral(
"zmin" ) ) );
214 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
215 uriComponents.insert( QStringLiteral(
"zmax" ), dsUri.
param( QStringLiteral(
"zmax" ) ) );
219 if ( dsUri.
hasParam( QStringLiteral(
"styleUrl" ) ) )
220 uriComponents.insert( QStringLiteral(
"styleUrl" ), dsUri.
param( QStringLiteral(
"styleUrl" ) ) );
223 if ( !authcfg.isEmpty() )
224 uriComponents.insert( QStringLiteral(
"authcfg" ), authcfg );
226 return uriComponents;
229QString QgsXyzVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
232 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
233 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
235 if ( parts.contains( QStringLiteral(
"zmin" ) ) )
236 dsUri.
setParam( QStringLiteral(
"zmin" ), parts[ QStringLiteral(
"zmin" ) ].toString() );
237 if ( parts.contains( QStringLiteral(
"zmax" ) ) )
238 dsUri.
setParam( QStringLiteral(
"zmax" ), parts[ QStringLiteral(
"zmax" ) ].toString() );
242 if ( parts.contains( QStringLiteral(
"styleUrl" ) ) )
243 dsUri.
setParam( QStringLiteral(
"styleUrl" ), parts[ QStringLiteral(
"styleUrl" ) ].toString() );
245 if ( parts.contains( QStringLiteral(
"authcfg" ) ) )
246 dsUri.
setAuthConfigId( parts[ QStringLiteral(
"authcfg" ) ].toString() );
251QString QgsXyzVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
256 QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
258 const QUrl sourceUrl( sourcePath );
259 if ( sourceUrl.isLocalFile() )
264 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
271QString QgsXyzVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
276 QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
278 const QUrl sourceUrl( sourcePath );
279 if ( sourceUrl.isLocalFile() )
283 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
290QList<Qgis::LayerType> QgsXyzVectorTileDataProviderMetadata::supportedLayerTypes()
const
300QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider(
const QString &uri,
const ProviderOptions &providerOptions, ReadFlags flags )
301 : QgsXyzVectorTileDataProviderBase( uri, providerOptions, flags )
306 const QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
309 QgsDebugError( QStringLiteral(
"Invalid format of URL for XYZ source: " ) + sourcePath );
315 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
316 zMin = dsUri.
param( QStringLiteral(
"zmin" ) ).toInt();
319 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
320 zMax = dsUri.
param( QStringLiteral(
"zmax" ) ).toInt();
323 mExtent =
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 );
328QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider(
const QgsXyzVectorTileDataProvider &other )
329 : QgsXyzVectorTileDataProviderBase( other )
331 mIsValid = other.mIsValid;
332 mExtent = other.mExtent;
333 mMatrixSet = other.mMatrixSet;
341QString QgsXyzVectorTileDataProvider::name()
const
345 return XYZ_DATA_PROVIDER_KEY;
348QString QgsXyzVectorTileDataProvider::description()
const
352 return XYZ_DATA_PROVIDER_DESCRIPTION;
359 return new QgsXyzVectorTileDataProvider( *
this );
362bool QgsXyzVectorTileDataProvider::isValid()
const
369QgsRectangle QgsXyzVectorTileDataProvider::extent()
const
390QString QgsXyzVectorTileDataProvider::sourcePath()
const
396 return dsUri.param( QStringLiteral(
"url" ) );
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
@ FastExtent2D
Provider's 2D extent retrieval via QgsDataProvider::extent() is always guaranteed to be trivial/fast ...
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
RendererUsage
Usage of the renderer.
@ Export
Renderer used for printing or exporting to a file.
@ View
Renderer used for displaying on screen.
@ Unknown
Renderer used for unknown usage.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
ErrorCode get(QNetworkRequest &request, bool forceRefresh=false, QgsFeedback *feedback=nullptr)
Performs a "get" operation on the specified request.
void setAuthCfg(const QString &authCfg)
Sets the authentication config id which should be used during the request.
@ NoError
No error was encountered.
QgsNetworkReplyContent reply() const
Returns the content of the network reply, after a get(), post(), head() or put() request has been mad...
This class represents a coordinate reference system (CRS).
QFlags< ReadFlag > ReadFlags
Class for storing the component parts of a RDBMS data source URI (e.g.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
int removeParam(const QString &key)
Removes a generic parameter by key.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
QgsHttpHeaders httpHeaders() const
Returns http headers.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Encapsulates a network reply within a container which is inexpensive to copy and safe to pass between...
QByteArray content() const
Returns the reply content.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
The class is used as a container of context for various read/write operations on other objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
Defines a set of tile matrices for multiple zoom levels.
QgsTileMatrix tileMatrix(int zoom) const
Returns the tile matrix corresponding to the specified zoom.
Defines a matrix of tiles for a single zoom level: it is defined by its size (width *.
Stores coordinates of a tile in a tile matrix set.
Base class for vector tile layer data providers.
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
static QgsVectorTileMatrixSet fromWebMercator(int minimumZoom=0, int maximumZoom=14)
Returns a vector tile structure corresponding to the standard web mercator/GoogleCRS84Quad setup.
Keeps track of raw tile data that need to be decoded.
static bool checkXYZUrlTemplate(const QString &url)
Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)
static QString formatXYZUrlTemplate(const QString &url, QgsTileXYZ tile, const QgsTileMatrix &tileMatrix)
Returns formatted tile URL string replacing {x}, {y}, {z} placeholders (or {-y} instead of {y} for TM...
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
#define QgsSetRequestInitiatorClass(request, _class)
#define QgsSetRequestInitiatorId(request, str)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.