28#include <QNetworkRequest>
32QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY = QStringLiteral(
"xyzvectortiles" );
33QString QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION = QObject::tr(
"XYZ Vector Tiles data provider" );
39QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase(
const QString &uri,
const ProviderOptions &providerOptions, ReadFlags flags )
48QgsXyzVectorTileDataProviderBase::QgsXyzVectorTileDataProviderBase(
const QgsXyzVectorTileDataProviderBase &other )
51 mAuthCfg = other.mAuthCfg;
52 mHeaders = other.mHeaders;
55bool QgsXyzVectorTileDataProviderBase::supportsAsync()
const
65QList<QgsVectorTileRawData> QgsXyzVectorTileDataProviderBase::readTiles(
const QgsTileMatrixSet &set,
const QVector<QgsTileXYZ> &tiles,
QgsFeedback *feedback )
const
67 QList<QgsVectorTileRawData> rawTiles;
68 rawTiles.reserve( tiles.size() );
69 const QString source = sourcePath();
75 const QByteArray rawData = loadFromNetwork(
id, set.
tileMatrix(
id.zoomLevel() ), source, mAuthCfg, mHeaders, feedback );
76 if ( !rawData.isEmpty() )
86 QString urlTemplate = sourcePath();
88 if ( urlTemplate.contains( QLatin1String(
"{usage}" ) ) )
93 urlTemplate.replace( QLatin1String(
"{usage}" ), QLatin1String(
"view" ) );
96 urlTemplate.replace( QLatin1String(
"{usage}" ), QLatin1String(
"export" ) );
99 urlTemplate.replace( QLatin1String(
"{usage}" ), QString() );
106 QNetworkRequest request( url );
110 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 1 ),
id.column() );
111 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 2 ),
id.row() );
112 request.setAttribute(
static_cast<QNetworkRequest::Attribute
>( QNetworkRequest::User + 3 ),
id.zoomLevel() );
114 request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
115 request.setAttribute( QNetworkRequest::CacheSaveControlAttribute,
true );
117 mHeaders.updateNetworkRequest( request );
131 nr.setUrl( QUrl( url ) );
155QgsXyzVectorTileDataProviderMetadata::QgsXyzVectorTileDataProviderMetadata()
156 :
QgsProviderMetadata( QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_KEY, QgsXyzVectorTileDataProvider::XYZ_DATA_PROVIDER_DESCRIPTION )
160QgsXyzVectorTileDataProvider *QgsXyzVectorTileDataProviderMetadata::createProvider(
const QString &uri,
const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
162 return new QgsXyzVectorTileDataProvider( uri, options, flags );
165QIcon QgsXyzVectorTileDataProviderMetadata::icon()
const
170QgsProviderMetadata::ProviderCapabilities QgsXyzVectorTileDataProviderMetadata::providerCapabilities()
const
172 return FileBasedUris;
175QVariantMap QgsXyzVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
180 QVariantMap uriComponents;
181 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
183 if ( uriComponents[ QStringLiteral(
"type" ) ] == QLatin1String(
"mbtiles" ) ||
184 ( uriComponents[ QStringLiteral(
"type" ) ] == QLatin1String(
"xyz" ) &&
185 !dsUri.
param( QStringLiteral(
"url" ) ).startsWith( QLatin1String(
"http" ) ) ) )
187 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
191 uriComponents.insert( QStringLiteral(
"url" ), dsUri.
param( QStringLiteral(
"url" ) ) );
194 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
195 uriComponents.insert( QStringLiteral(
"zmin" ), dsUri.
param( QStringLiteral(
"zmin" ) ) );
196 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
197 uriComponents.insert( QStringLiteral(
"zmax" ), dsUri.
param( QStringLiteral(
"zmax" ) ) );
201 if ( dsUri.
hasParam( QStringLiteral(
"styleUrl" ) ) )
202 uriComponents.insert( QStringLiteral(
"styleUrl" ), dsUri.
param( QStringLiteral(
"styleUrl" ) ) );
205 if ( !authcfg.isEmpty() )
206 uriComponents.insert( QStringLiteral(
"authcfg" ), authcfg );
208 return uriComponents;
211QString QgsXyzVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
214 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
215 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
217 if ( parts.contains( QStringLiteral(
"zmin" ) ) )
218 dsUri.
setParam( QStringLiteral(
"zmin" ), parts[ QStringLiteral(
"zmin" ) ].toString() );
219 if ( parts.contains( QStringLiteral(
"zmax" ) ) )
220 dsUri.
setParam( QStringLiteral(
"zmax" ), parts[ QStringLiteral(
"zmax" ) ].toString() );
224 if ( parts.contains( QStringLiteral(
"styleUrl" ) ) )
225 dsUri.
setParam( QStringLiteral(
"styleUrl" ), parts[ QStringLiteral(
"styleUrl" ) ].toString() );
227 if ( parts.contains( QStringLiteral(
"authcfg" ) ) )
228 dsUri.
setAuthConfigId( parts[ QStringLiteral(
"authcfg" ) ].toString() );
233QString QgsXyzVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
238 QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
240 const QUrl sourceUrl( sourcePath );
241 if ( sourceUrl.isLocalFile() )
246 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
253QString QgsXyzVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
258 QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
260 const QUrl sourceUrl( sourcePath );
261 if ( sourceUrl.isLocalFile() )
265 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
272QList<Qgis::LayerType> QgsXyzVectorTileDataProviderMetadata::supportedLayerTypes()
const
274 return { Qgis::LayerType::VectorTile };
282QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider(
const QString &uri,
const ProviderOptions &providerOptions, ReadFlags flags )
283 : QgsXyzVectorTileDataProviderBase( uri, providerOptions, flags )
288 const QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
291 QgsDebugError( QStringLiteral(
"Invalid format of URL for XYZ source: " ) + sourcePath );
297 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
298 zMin = dsUri.
param( QStringLiteral(
"zmin" ) ).toInt();
301 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
302 zMax = dsUri.
param( QStringLiteral(
"zmax" ) ).toInt();
305 mExtent =
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 );
310QgsXyzVectorTileDataProvider::QgsXyzVectorTileDataProvider(
const QgsXyzVectorTileDataProvider &other )
311 : QgsXyzVectorTileDataProviderBase( other )
313 mIsValid = other.mIsValid;
314 mExtent = other.mExtent;
315 mMatrixSet = other.mMatrixSet;
318QString QgsXyzVectorTileDataProvider::name()
const
322 return XYZ_DATA_PROVIDER_KEY;
325QString QgsXyzVectorTileDataProvider::description()
const
329 return XYZ_DATA_PROVIDER_DESCRIPTION;
336 return new QgsXyzVectorTileDataProvider( *
this );
339bool QgsXyzVectorTileDataProvider::isValid()
const
346QgsRectangle QgsXyzVectorTileDataProvider::extent()
const
367QString QgsXyzVectorTileDataProvider::sourcePath()
const
373 return dsUri.param( QStringLiteral(
"url" ) );
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).
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 SIP_HOLDGIL
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.