QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
43 bool QgsVectorTileLayer::loadDataSource()
48 mSourceType = dsUri.
param( QStringLiteral(
"type" ) );
49 mSourcePath = dsUri.
param( QStringLiteral(
"url" ) );
50 if ( mSourceType == QStringLiteral(
"xyz" ) )
54 QgsDebugMsg( QStringLiteral(
"Invalid format of URL for XYZ source: " ) + mSourcePath );
62 if ( dsUri.
hasParam( QStringLiteral(
"zmin" ) ) )
63 mSourceMinZoom = dsUri.
param( QStringLiteral(
"zmin" ) ).toInt();
64 if ( dsUri.
hasParam( QStringLiteral(
"zmax" ) ) )
65 mSourceMaxZoom = dsUri.
param( QStringLiteral(
"zmax" ) ).toInt();
67 setExtent(
QgsRectangle( -20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892 ) );
69 else if ( mSourceType == QStringLiteral(
"mbtiles" ) )
74 QgsDebugMsg( QStringLiteral(
"failed to open MBTiles file: " ) + mSourcePath );
78 QString format = reader.metadataValue( QStringLiteral(
"format" ) );
79 if ( format != QStringLiteral(
"pbf" ) )
81 QgsDebugMsg( QStringLiteral(
"Cannot open MBTiles for vector tiles. Format = " ) + format );
85 QgsDebugMsgLevel( QStringLiteral(
"name: " ) + reader.metadataValue( QStringLiteral(
"name" ) ), 2 );
86 bool minZoomOk, maxZoomOk;
87 int minZoom = reader.metadataValue( QStringLiteral(
"minzoom" ) ).toInt( &minZoomOk );
88 int maxZoom = reader.metadataValue( QStringLiteral(
"maxzoom" ) ).toInt( &maxZoomOk );
90 mSourceMinZoom = minZoom;
92 mSourceMaxZoom = maxZoom;
93 QgsDebugMsgLevel( QStringLiteral(
"zoom range: %1 - %2" ).arg( mSourceMinZoom ).arg( mSourceMaxZoom ), 2 );
98 r = ct.transformBoundingBox( r );
103 QgsDebugMsg( QStringLiteral(
"Unknown source type: " ) + mSourceType );
128 mValid = loadDataSource();
140 QDomElement mapLayerNode = layerNode.toElement();
141 mapLayerNode.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"vector-tile" ) );
151 QDomElement elem = node.toElement();
155 QDomElement elemRenderer = elem.firstChildElement( QStringLiteral(
"renderer" ) );
156 if ( elemRenderer.isNull() )
158 errorMessage = tr(
"Missing <renderer> tag" );
161 QString rendererType = elemRenderer.attribute( QStringLiteral(
"type" ) );
163 if ( rendererType == QStringLiteral(
"basic" ) )
167 errorMessage = tr(
"Unknown renderer type: " ) + rendererType;
171 r->
readXml( elemRenderer, context );
175 QDomElement elemLabeling = elem.firstChildElement( QStringLiteral(
"labeling" ) );
176 if ( !elemLabeling.isNull() )
178 QString labelingType = elemLabeling.attribute( QStringLiteral(
"type" ) );
180 if ( labelingType == QStringLiteral(
"basic" ) )
184 errorMessage = tr(
"Unknown labeling type: " ) + rendererType;
199 Q_UNUSED( errorMessage )
200 QDomElement elem = node.toElement();
206 QDomElement elemRenderer = doc.createElement( QStringLiteral(
"renderer" ) );
207 elemRenderer.setAttribute( QStringLiteral(
"type" ), mRenderer->type() );
208 mRenderer->writeXml( elemRenderer, context );
209 elem.appendChild( elemRenderer );
214 QDomElement elemLabeling = doc.createElement( QStringLiteral(
"labeling" ) );
215 elemLabeling.setAttribute( QStringLiteral(
"type" ), mLabeling->type() );
216 mLabeling->writeXml( elemLabeling, context );
217 elem.appendChild( elemLabeling );
238 if ( sourceUrl.isLocalFile() )
243 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( relSrcUrl ).toString() );
247 else if (
sourceType == QStringLiteral(
"mbtiles" ) )
270 if ( sourceUrl.isLocalFile() )
274 dsUri.
setParam( QStringLiteral(
"url" ), QUrl::fromLocalFile( absSrcUrl ).toString() );
278 else if (
sourceType == QStringLiteral(
"mbtiles" ) )
294 if ( rawTiles.isEmpty() )
296 return rawTiles.first().data;
301 mRenderer.reset( r );
307 return mRenderer.get();
318 return mLabeling.get();
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QgsVectorTileLayer(const QString &path=QString(), const QString &baseName=QString())
Constructs a new vector tile layer.
QString sourceType() const
Returns type of the data source.
#define QgsDebugMsgLevel(str, level)
void setRenderer(QgsVectorTileRenderer *r)
Sets renderer for the map layer.
~QgsVectorTileLayer() override
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
QgsVectorTileLayer * clone() const override
Returns a new instance equivalent to this one except for the id which is still unique.
QString encodedSource(const QString &source, const QgsReadWriteContext &context) const FINAL
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString sourcePath() const
Returns URL/path of the data source (syntax different to each data source type)
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext) override
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
static bool checkXYZUrlTemplate(const QString &url)
Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)
bool mValid
Indicates if the layer is valid and can be drawn.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
QgsVectorTileRenderer * renderer() const
Returns currently assigned renderer.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
static QList< QgsVectorTileRawData > blockingFetchTileRawData(const QString &sourceType, const QString &sourcePath, const QgsTileMatrix &tileMatrix, const QPointF &viewCenter, const QgsTileRange &range)
Returns raw tile data for the specified range of tiles. Blocks the caller until all tiles are fetched...
void setLabeling(QgsVectorTileLabeling *labeling)
Sets labeling for the map layer.
QString mDataSource
Data source description string, varies by layer type.
int removeParam(const QString &key)
Removes a generic parameter by key.
virtual bool writeXml(QDomNode &layerNode, QDomDocument &doc, const QgsReadWriteContext &context) const override
Called by writeLayerXML(), used by children to write state specific to them to project files.
int zoomLevel() const
Returns tile's zoom level (Z)
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
QString source() const
Returns the source for the layer.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) override
Read the symbology for the current layer from the DOM node supplied.
QgsVectorTileLabeling * labeling() const
Returns currently assigned labeling.
int row() const
Returns tile's row index (Y)
@ VectorTileLayer
Added in 3.14.
QByteArray getRawTile(QgsTileXYZ tileID)
Fetches raw tile data for the give tile coordinates.
QString decodedSource(const QString &source, const QString &provider, const QgsReadWriteContext &context) const FINAL
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
static QgsTileMatrix fromWebMercator(int mZoomLevel)
Returns a tile matrix for the usual web mercator.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext) override
Sets the coordinate transform context to transformContext.
virtual bool readXml(const QDomNode &layerNode, QgsReadWriteContext &context) override
Called by readLayerXML(), used by children to read state specific to them from project files.
static QList< QgsVectorTileBasicRendererStyle > simpleStyleWithRandomColors()
Returns a list of styles to render all layers, using random colors.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads labeling properties from given XML element.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const override
Write the style for the layer into the docment provided.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
int column() const
Returns tile's column index (X)