17#include "moc_qgsvtpkvectortiledataprovider.cpp"
32QString QgsVtpkVectorTileDataProvider::DATA_PROVIDER_KEY = QStringLiteral(
"vtpkvectortiles" );
33QString QgsVtpkVectorTileDataProvider::DATA_PROVIDER_DESCRIPTION = QObject::tr(
"VTPK Vector Tiles data provider" );
36QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider(
const QString &uri,
const ProviderOptions &providerOptions,
Qgis::DataProviderReadFlags flags )
41 const QString sourcePath = dsUri.
param( QStringLiteral(
"url" ) );
46 QgsDebugError( QStringLiteral(
"failed to open VTPK file: " ) + sourcePath );
51 const QVariantMap metadata = reader.metadata();
52 const QString format = metadata.value( QStringLiteral(
"tileInfo" ) ).toMap().value( QStringLiteral(
"format" ) ).toString();
53 if ( format != QLatin1String(
"pbf" ) )
55 QgsDebugError( QStringLiteral(
"Cannot open VTPK for vector tiles. Format = " ) + format );
60 mMatrixSet = reader.matrixSet();
61 mCrs = mMatrixSet.crs();
62 mExtent = reader.extent( transformContext() );
63 mLayerMetadata = reader.layerMetadata();
64 mStyleDefinition = reader.styleDefinition();
65 mSpriteDefinition = reader.spriteDefinition();
66 if ( !mSpriteDefinition.isEmpty() )
68 mSpriteImage = reader.spriteImage();
74QgsVtpkVectorTileDataProvider::QgsVtpkVectorTileDataProvider(
const QgsVtpkVectorTileDataProvider &other )
77 mIsValid = other.mIsValid;
79 mExtent = other.mExtent;
80 mMatrixSet = other.mMatrixSet;
81 mLayerMetadata = other.mLayerMetadata;
82 mStyleDefinition = other.mStyleDefinition;
83 mSpriteDefinition = other.mSpriteDefinition;
84 mSpriteImage = other.mSpriteImage;
102QString QgsVtpkVectorTileDataProvider::name()
const
106 return DATA_PROVIDER_KEY;
109QString QgsVtpkVectorTileDataProvider::description()
const
113 return DATA_PROVIDER_DESCRIPTION;
119 return new QgsVtpkVectorTileDataProvider( *
this );
122QString QgsVtpkVectorTileDataProvider::sourcePath()
const
128 return dsUri.param( QStringLiteral(
"url" ) );
131bool QgsVtpkVectorTileDataProvider::isValid()
const
145QgsRectangle QgsVtpkVectorTileDataProvider::extent()
const
154 return mLayerMetadata;
164QVariantMap QgsVtpkVectorTileDataProvider::styleDefinition()
const
168 return mStyleDefinition;
171QVariantMap QgsVtpkVectorTileDataProvider::spriteDefinition()
const
175 return mSpriteDefinition;
178QImage QgsVtpkVectorTileDataProvider::spriteImage()
const
190 if ( mShared->getCachedTileData( data,
id ) )
198 mShared->storeCachedTileData( rawData );
210 std::unique_ptr< QgsVtpkTiles > reader;
212 QList<QgsVectorTileRawData> rawTiles;
213 QSet< QgsTileXYZ > fetchedTiles;
214 rawTiles.reserve( tiles.size() );
215 fetchedTiles.reserve( tiles.size() );
216 for (
QgsTileXYZ id : std::as_const( tiles ) )
221 if ( fetchedTiles.contains(
id ) )
225 if ( mShared->getCachedTileData( data,
id ) )
227 rawTiles.append( data );
228 fetchedTiles.insert( data.
id );
234 reader = std::make_unique< QgsVtpkTiles >( dsUri.param( QStringLiteral(
"url" ) ) );
238 if ( !rawData.
data.isEmpty() && !fetchedTiles.contains( rawData.
id ) )
240 rawTiles.append( rawData );
241 fetchedTiles.insert( rawData.
id );
242 mShared->storeCachedTileData( rawData );
249QString QgsVtpkVectorTileDataProvider::htmlMetadata()
const
258 if ( !reader.rootTileMap().isEmpty() )
259 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"VTPK storage" ) % QStringLiteral(
"</td><td>" ) % tr(
"Indexed VTPK (tilemap is present)" ) % QStringLiteral(
"</td></tr>\n" );
261 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"VTPK storage" ) % QStringLiteral(
"</td><td>" ) % tr(
"Flat VTPK (no tilemap)" ) % QStringLiteral(
"</td></tr>\n" );
263 if ( reader.metadata().contains( QStringLiteral(
"minLOD" ) ) )
265 metadata += QStringLiteral(
"<tr><td class=\"highlight\">" ) % tr(
"Tile detail levels" ) % QStringLiteral(
"</td><td>" ) % QStringLiteral(
"%1 - %2" ).arg( reader.metadata().value( QStringLiteral(
"minLOD" ) ).toInt() ).arg( reader.metadata().value( QStringLiteral(
"maxLOD" ) ).toInt() ) % QStringLiteral(
"</td></tr>\n" );
284 if ( tileData.isNull() )
288 res.tileGeometryId = requestedTile;
297QgsVtpkVectorTileDataProviderMetadata::QgsVtpkVectorTileDataProviderMetadata()
298 :
QgsProviderMetadata( QgsVtpkVectorTileDataProvider::DATA_PROVIDER_KEY, QgsVtpkVectorTileDataProvider::DATA_PROVIDER_DESCRIPTION )
304 return ProviderMetadataCapability::LayerTypesForUri
305 | ProviderMetadataCapability::PriorityForUri
306 | ProviderMetadataCapability::QuerySublayers;
311 return new QgsVtpkVectorTileDataProvider( uri, options, flags );
314QIcon QgsVtpkVectorTileDataProviderMetadata::icon()
const
321 return FileBasedUris;
337 return QObject::tr(
"VTPK Vector Tiles" ) + QStringLiteral(
" (*.vtpk *.VTPK)" );
345 const QFileInfo fi( uri );
352 const QVariantMap parts = decodeUri( uri );
353 fileName = parts.value( QStringLiteral(
"path" ) ).toString();
356 if ( fileName.isEmpty() )
359 if ( QFileInfo( fileName ).suffix().compare( QLatin1String(
"vtpk" ), Qt::CaseInsensitive ) == 0 )
362 parts.insert( QStringLiteral(
"path" ), fileName );
365 details.
setUri( encodeUri( parts ) );
377int QgsVtpkVectorTileDataProviderMetadata::priorityForUri(
const QString &uri )
const
385QList<Qgis::LayerType> QgsVtpkVectorTileDataProviderMetadata::validLayerTypesForUri(
const QString &uri )
const
387 const QFileInfo fi( uri );
388 if ( fi.isFile() && fi.suffix().compare( QLatin1String(
"vtpk" ), Qt::CaseInsensitive ) == 0 )
393 const QVariantMap parts = decodeUri( uri );
394 if ( parts.value( QStringLiteral(
"path" ) ).toString().endsWith(
".vtpk", Qt::CaseSensitivity::CaseInsensitive ) )
400QVariantMap QgsVtpkVectorTileDataProviderMetadata::decodeUri(
const QString &uri )
const
405 QVariantMap uriComponents;
406 uriComponents.insert( QStringLiteral(
"type" ), QStringLiteral(
"vtpk" ) );
407 uriComponents.insert( QStringLiteral(
"path" ), dsUri.
param( QStringLiteral(
"url" ) ) );
409 return uriComponents;
412QString QgsVtpkVectorTileDataProviderMetadata::encodeUri(
const QVariantMap &parts )
const
415 dsUri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"vtpk" ) );
416 dsUri.
setParam( QStringLiteral(
"url" ), parts.value( parts.contains( QStringLiteral(
"path" ) ) ? QStringLiteral(
"path" ) : QStringLiteral(
"url" ) ).toString() );
420QString QgsVtpkVectorTileDataProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
422 QVariantMap parts = decodeUri( uri );
424 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
427 return encodeUri( parts );
430QString QgsVtpkVectorTileDataProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
432 QVariantMap parts = decodeUri( uri );
434 const QString originalPath = parts.value( QStringLiteral(
"path" ) ).toString();
437 return encodeUri( parts );
440QList<Qgis::LayerType> QgsVtpkVectorTileDataProviderMetadata::supportedLayerTypes()
const
@ ReadLayerMetadata
Provider can read layer metadata from data store. See QgsDataProvider::layerMetadata()
@ AlwaysUseTileMatrixSetFromProvider
Vector tile layer must always use the tile matrix set from the data provider, and should never store,...
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
FileFilterType
Type of file filters.
@ TiledScene
Tiled scene layers.
@ VectorTile
Vector tile layers.
@ MeshDataset
Mesh datasets.
@ PointCloud
Point clouds.
@ FastExtent2D
Provider's 2D extent retrieval via QgsDataProvider::extent() is always guaranteed to be trivial/fast ...
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
QFlags< VectorTileProviderCapability > VectorTileProviderCapabilities
Vector tile data provider capabilities.
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
RendererUsage
Usage of the renderer.
QFlags< VectorTileProviderFlag > VectorTileProviderFlags
Vector tile data provider flags.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
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.
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.
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.
Contains details about a sub layer available from a dataset.
void setUri(const QString &uri)
Sets the layer's uri.
void setType(Qgis::LayerType type)
Sets the layer type.
void setName(const QString &name)
Sets the layer's name.
void setProviderKey(const QString &key)
Sets the associated data provider key.
static QString suggestLayerNameFromFilePath(const QString &path)
Suggests a suitable layer name given only a file 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.
int minimumZoom() const
Returns the minimum zoom level for tiles present in the set.
Stores coordinates of a tile in a tile matrix set.
int zoomLevel() const
Returns tile's zoom level (Z)
int column() const
Returns tile's column index (X)
int row() const
Returns tile's row index (Y)
Base class for vector tile layer data providers.
Encapsulates properties of a vector tile matrix set, including tile origins and scaling information.
Keeps track of raw tile data from one or more sources that need to be decoded.
QMap< QString, QByteArray > data
Raw tile data by source ID.
QgsTileXYZ id
Tile position in tile matrix set.
Utility class for reading and writing ESRI VTPK files.
QByteArray tileData(int z, int x, int y)
Returns the raw tile data for the matching tile.
QgsVectorTileMatrixSet matrixSet() const
Returns the vector tile matrix set representing the tiles.
#define QgsDebugError(str)
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Setting options for creating vector data providers.