QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsvectortilebasicrenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortilebasicrenderer.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
18#include "qgsapplication.h"
21#include "qgsfillsymbol.h"
22#include "qgsfillsymbollayer.h"
23#include "qgslinesymbol.h"
24#include "qgslinesymbollayer.h"
25#include "qgsmarkersymbol.h"
27#include "qgssymbollayerutils.h"
28
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
33QgsVectorTileBasicRendererStyle::QgsVectorTileBasicRendererStyle( const QString &stName, const QString &laName, Qgis::GeometryType geomType )
34 : mStyleName( stName )
35 , mLayerName( laName )
36 , mGeometryType( geomType )
37{}
38
43
45{
46 if ( &other == this )
47 return *this;
48
49 mStyleName = other.mStyleName;
50 mLayerName = other.mLayerName;
51 mGeometryType = other.mGeometryType;
52 mSymbol.reset( other.mSymbol ? other.mSymbol->clone() : nullptr );
53 mEnabled = other.mEnabled;
54 mExpression = other.mExpression;
55 mMinZoomLevel = other.mMinZoomLevel;
56 mMaxZoomLevel = other.mMaxZoomLevel;
57 return *this;
58}
59
61
63{
64 mSymbol.reset( sym );
65}
66
67void QgsVectorTileBasicRendererStyle::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
68{
69 elem.setAttribute( u"name"_s, mStyleName );
70 elem.setAttribute( u"layer"_s, mLayerName );
71 elem.setAttribute( u"geometry"_s, static_cast<int>( mGeometryType ) );
72 elem.setAttribute( u"enabled"_s, mEnabled ? u"1"_s : u"0"_s );
73 elem.setAttribute( u"expression"_s, mExpression );
74 elem.setAttribute( u"min-zoom"_s, mMinZoomLevel );
75 elem.setAttribute( u"max-zoom"_s, mMaxZoomLevel );
76
77 QDomDocument doc = elem.ownerDocument();
78 QgsSymbolMap symbols;
79 symbols[u"0"_s] = mSymbol.get();
80 QDomElement symbolsElem = QgsSymbolLayerUtils::saveSymbols( symbols, u"symbols"_s, doc, context );
81 elem.appendChild( symbolsElem );
82}
83
84void QgsVectorTileBasicRendererStyle::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
85{
86 mStyleName = elem.attribute( u"name"_s );
87 mLayerName = elem.attribute( u"layer"_s );
88 mGeometryType = static_cast<Qgis::GeometryType>( elem.attribute( u"geometry"_s ).toInt() );
89 mEnabled = elem.attribute( u"enabled"_s ).toInt();
90 mExpression = elem.attribute( u"expression"_s );
91 mMinZoomLevel = elem.attribute( u"min-zoom"_s ).toInt();
92 mMaxZoomLevel = elem.attribute( u"max-zoom"_s ).toInt();
93
94 mSymbol.reset();
95 QDomElement symbolsElem = elem.firstChildElement( u"symbols"_s );
96 if ( !symbolsElem.isNull() )
97 {
98 QgsSymbolMap symbolMap = QgsSymbolLayerUtils::loadSymbols( symbolsElem, context );
99 if ( symbolMap.contains( u"0"_s ) )
100 {
101 mSymbol.reset( symbolMap.take( u"0"_s ) );
102 }
103 }
104}
105
107
108
111
113{
114 return u"basic"_s;
115}
116
118{
120 r->mStyles = mStyles;
121 r->mStyles.detach(); // make a deep copy to make sure symbols get cloned
122 return r;
123}
124
125void QgsVectorTileBasicRenderer::startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange )
126{
127 Q_UNUSED( context )
128 Q_UNUSED( tileRange )
129 // figure out required fields for different layers
130 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
131 {
132 if ( layerStyle.isActive( tileZoom ) )
133 {
134 if ( !layerStyle.filterExpression().isEmpty() )
135 {
136 QgsExpression expr( layerStyle.filterExpression() );
137 mRequiredFields[layerStyle.layerName()].unite( expr.referencedColumns() );
138 }
139 if ( auto *lSymbol = layerStyle.symbol() )
140 {
141 mRequiredFields[layerStyle.layerName()].unite( lSymbol->usedAttributes( context ) );
142 }
143 }
144 }
145}
146
147QMap<QString, QSet<QString> > QgsVectorTileBasicRenderer::usedAttributes( const QgsRenderContext & )
148{
149 return mRequiredFields;
150}
151
153{
154 QSet< QString > res;
155 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
156 {
157 if ( layerStyle.isActive( tileZoom ) )
158 {
159 res.insert( layerStyle.layerName() );
160 }
161 }
162 return res;
163}
164
166{
167 Q_UNUSED( context )
168}
169
171{
172 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
173 {
174 if ( !layerStyle.symbol() || layerStyle.layerName() != "background"_L1 )
175 continue;
176
177 if ( layerStyle.isEnabled() )
178 {
179 QgsSymbol *sym = layerStyle.symbol();
180 sym->startRender( context, QgsFields() );
181
182 QgsFillSymbol *fillSym = dynamic_cast<QgsFillSymbol *>( sym );
183 if ( fillSym )
184 {
185 QPolygon polygon;
186 polygon << QPoint( 0, 0 );
187 polygon << QPoint( 0, context.outputSize().height() );
188 polygon << QPoint( context.outputSize().width(), context.outputSize().height() );
189 polygon << QPoint( context.outputSize().width(), 0 );
190 fillSym->renderPolygon( polygon, nullptr, nullptr, context );
191 }
192 sym->stopRender( context );
193 }
194 break;
195 }
196}
197
199{
200 const QgsVectorTileFeatures tileData = tile.features();
201 const int zoomLevel = tile.renderZoomLevel();
202
203 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
204 {
205 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() || layerStyle.layerName() == "background"_L1 )
206 continue;
207
208 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
209 scope->setFields( tile.fields()[layerStyle.layerName()] );
210 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
211
212 QgsExpression filterExpression( layerStyle.filterExpression() );
213 filterExpression.prepare( &context.expressionContext() );
214
215 QgsSymbol *sym = layerStyle.symbol();
216 sym->startRender( context, QgsFields() );
217 if ( layerStyle.layerName().isEmpty() )
218 {
219 // matching all layers
220 for ( const auto &features : tileData )
221 {
222 for ( const QgsFeature &f : features )
223 {
224 scope->setFeature( f );
225 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
226 continue;
227
228 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
229 if ( featureType == layerStyle.geometryType() )
230 {
231 sym->renderFeature( f, context );
232 }
233 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
234 {
235 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
236 // to render the polygon borders only
237 QgsFeature exterior = f;
238 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
239 sym->renderFeature( exterior, context );
240 }
241 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
242 {
243 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
244 // to render the polygon center
245 QgsFeature centroid = f;
246 const QgsRectangle boundingBox = f.geometry().boundingBox();
247 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
248 sym->renderFeature( centroid, context );
249 }
250 }
251 }
252 }
253 else if ( tileData.contains( layerStyle.layerName() ) )
254 {
255 // matching one particular layer
256 for ( const QgsFeature &f : tileData[layerStyle.layerName()] )
257 {
258 scope->setFeature( f );
259 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
260 continue;
261
262 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
263 if ( featureType == layerStyle.geometryType() )
264 {
265 sym->renderFeature( f, context );
266 }
267 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
268 {
269 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
270 // to render the polygon borders only
271 QgsFeature exterior = f;
272 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
273 sym->renderFeature( exterior, context );
274 }
275 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
276 {
277 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
278 // to render the polygon center
279 QgsFeature centroid = f;
280 const QgsRectangle boundingBox = f.geometry().boundingBox();
281 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
282 sym->renderFeature( centroid, context );
283 }
284 }
285 }
286 sym->stopRender( context );
287 }
288}
289
290void QgsVectorTileBasicRenderer::renderSelectedFeatures( const QList<QgsFeature> &selection, QgsRenderContext &context )
291{
292 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
293 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
294
295 for ( const QgsFeature &feature : selection )
296 {
297 bool ok = false;
298 int featureTileZoom = feature.attribute( u"tile_zoom"_s ).toInt( &ok );
299 if ( !ok )
300 featureTileZoom = -1;
301 const QString featureTileLayer = feature.attribute( u"tile_layer"_s ).toString();
302
303 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
304 {
305 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) ) || !layerStyle.symbol() || layerStyle.layerName() == "background"_L1 )
306 continue;
307
308 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
309 continue;
310
311 scope->setFields( feature.fields() );
312
313 QgsExpression filterExpression( layerStyle.filterExpression() );
314 filterExpression.prepare( &context.expressionContext() );
315
316 scope->setFeature( feature );
317 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
318 continue;
319
320 QgsSymbol *sym = layerStyle.symbol();
321 sym->startRender( context, feature.fields() );
322
323 const Qgis::GeometryType featureType = feature.geometry().type();
324 bool renderedFeature = false;
325 if ( featureType == layerStyle.geometryType() )
326 {
327 sym->renderFeature( feature, context, -1, true );
328 renderedFeature = true;
329 }
330 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
331 {
332 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
333 // to render the polygon borders only
334 QgsFeature exterior = feature;
335 exterior.setGeometry( QgsGeometry( feature.geometry().constGet()->boundary() ) );
336 sym->renderFeature( exterior, context, -1, true );
337 renderedFeature = true;
338 }
339 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
340 {
341 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
342 // to render the polygon center
343 QgsFeature centroid = feature;
344 const QgsRectangle boundingBox = feature.geometry().boundingBox();
345 centroid.setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
346 sym->renderFeature( centroid, context, -1, true );
347 renderedFeature = true;
348 }
349 sym->stopRender( context );
350
351 if ( renderedFeature )
352 break;
353 }
354 }
355}
356
357bool QgsVectorTileBasicRenderer::willRenderFeature( const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context )
358{
359 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
360 scope->setFields( feature.fields() );
361 scope->setFeature( feature );
362 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
363
364 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
365 {
366 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
367 continue;
368
369 if ( layerStyle.layerName() == "background"_L1 )
370 continue;
371
372 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
373 continue;
374
375 QgsExpression filterExpression( layerStyle.filterExpression() );
376 filterExpression.prepare( &context.expressionContext() );
377
378 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
379 continue;
380
381 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( feature.geometry().wkbType() );
382 if ( featureType == layerStyle.geometryType() )
383 {
384 return true;
385 }
386 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
387 {
388 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
389 // to render the polygon borders only
390 return true;
391 }
392 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
393 {
394 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
395 // to render the polygon center
396 return true;
397 }
398 }
399 return false;
400}
401
402void QgsVectorTileBasicRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
403{
404 QDomDocument doc = elem.ownerDocument();
405 QDomElement elemStyles = doc.createElement( u"styles"_s );
406 for ( const QgsVectorTileBasicRendererStyle &layerStyle : mStyles )
407 {
408 QDomElement elemStyle = doc.createElement( u"style"_s );
409 layerStyle.writeXml( elemStyle, context );
410 elemStyles.appendChild( elemStyle );
411 }
412 elem.appendChild( elemStyles );
413}
414
415void QgsVectorTileBasicRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
416{
417 mStyles.clear();
418
419 QDomElement elemStyles = elem.firstChildElement( u"styles"_s );
420 QDomElement elemStyle = elemStyles.firstChildElement( u"style"_s );
421 while ( !elemStyle.isNull() )
422 {
424 layerStyle.readXml( elemStyle, context );
425 mStyles.append( layerStyle );
426 elemStyle = elemStyle.nextSiblingElement( u"style"_s );
427 }
428}
429
430void QgsVectorTileBasicRenderer::setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles )
431{
432 mStyles = styles;
433}
434
435QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() const
436{
437 return mStyles;
438}
439
440QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyleWithRandomColors()
441{
442 QColor polygonFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
443 QColor polygonStrokeColor = polygonFillColor;
444 polygonFillColor.setAlpha( 100 );
445 double polygonStrokeWidth = Qgis::DEFAULT_LINE_WIDTH;
446
448 double lineStrokeWidth = Qgis::DEFAULT_LINE_WIDTH;
449
451 QColor pointStrokeColor = pointFillColor;
452 pointFillColor.setAlpha( 100 );
453 double pointSize = Qgis::DEFAULT_POINT_SIZE;
454
455 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth, lineStrokeColor, lineStrokeWidth, pointFillColor, pointStrokeColor, pointSize );
456}
457
458QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
459 const QColor &polygonFillColor,
460 const QColor &polygonStrokeColor,
461 double polygonStrokeWidth,
462 const QColor &lineStrokeColor,
463 double lineStrokeWidth,
464 const QColor &pointFillColor,
465 const QColor &pointStrokeColor,
466 double pointSize
467)
468{
469 QgsSimpleFillSymbolLayer *fillSymbolLayer = new QgsSimpleFillSymbolLayer();
470 fillSymbolLayer->setFillColor( polygonFillColor );
471 fillSymbolLayer->setStrokeColor( polygonStrokeColor );
472 fillSymbolLayer->setStrokeWidth( polygonStrokeWidth );
473 QgsFillSymbol *fillSymbol = new QgsFillSymbol( QgsSymbolLayerList() << fillSymbolLayer );
474
476 lineSymbolLayer->setColor( lineStrokeColor );
477 lineSymbolLayer->setWidth( lineStrokeWidth );
478 QgsLineSymbol *lineSymbol = new QgsLineSymbol( QgsSymbolLayerList() << lineSymbolLayer );
479
481 markerSymbolLayer->setFillColor( pointFillColor );
482 markerSymbolLayer->setStrokeColor( pointStrokeColor );
483 markerSymbolLayer->setSize( pointSize );
484 QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );
485
486 QgsVectorTileBasicRendererStyle st1( u"Polygons"_s, QString(), Qgis::GeometryType::Polygon );
487 st1.setFilterExpression( u"geometry_type(@geometry)='Polygon'"_s );
488 st1.setSymbol( fillSymbol );
489
490 QgsVectorTileBasicRendererStyle st2( u"Lines"_s, QString(), Qgis::GeometryType::Line );
491 st2.setFilterExpression( u"geometry_type(@geometry)='Line'"_s );
492 st2.setSymbol( lineSymbol );
493
494 QgsVectorTileBasicRendererStyle st3( u"Points"_s, QString(), Qgis::GeometryType::Point );
495 st3.setFilterExpression( u"geometry_type(@geometry)='Point'"_s );
496 st3.setSymbol( markerSymbol );
497
498 QList<QgsVectorTileBasicRendererStyle> lst;
499 lst << st1 << st2 << st3;
500 return lst;
501}
static const double DEFAULT_LINE_WIDTH
The default width (in millimeters) for line symbols.
Definition qgis.h:6612
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
static const double DEFAULT_POINT_SIZE
The default size (in millimeters) for point marker symbols.
Definition qgis.h:6609
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
QColor fetchRandomStyleColor() const
Returns a random color for use with a new symbol style (e.g.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QVariant evaluate()
Evaluate the feature and return the result.
bool isValid() const
Checks if this expression is valid.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFields fields
Definition qgsfeature.h:70
QgsGeometry geometry
Definition qgsfeature.h:71
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
Definition qgsfields.h:46
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol using the given render context.
A geometry is the spatial representation of a feature.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
virtual void setWidth(double width)
Sets the width of the line symbol layer.
A line symbol type, for rendering LineString and MultiLineString geometries.
virtual void setSize(double size)
Sets the symbol size.
A marker symbol type, for rendering Point and MultiPoint geometries.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
Renders polygons using a single fill and stroke color.
void setStrokeWidth(double strokeWidth)
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeColor(const QColor &strokeColor) override
Sets the stroke color for the symbol layer.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeColor(const QColor &color) override
Sets the marker's stroke color.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, Qgis::VertexMarkerType currentVertexMarkerType=Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize=0.0)
Render a feature.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
A range of tiles in a tile matrix.
Definition qgstiles.h:123
Definition of map rendering of a subset of vector tile data.
QgsVectorTileBasicRendererStyle(const QString &stName=QString(), const QString &laName=QString(), Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Constructs a style object.
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
QgsVectorTileBasicRendererStyle & operator=(const QgsVectorTileBasicRendererStyle &other)
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
void renderTile(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Renders given vector tile. Must be called between startRender/stopRender.
QList< QgsVectorTileBasicRendererStyle > styles() const
Returns list of styles of the renderer.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &) override
Returns field names of sub-layers that will be used for rendering. Must be called between startRender...
QgsVectorTileBasicRenderer()
Constructs renderer with no styles.
void renderSelectedFeatures(const QList< QgsFeature > &selection, QgsRenderContext &context) override
Renders the specified features in a selected state.
void setStyles(const QList< QgsVectorTileBasicRendererStyle > &styles)
Sets list of styles of the renderer.
void startRender(QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange) override
Initializes rendering. It should be paired with a stopRender() call.
QString type() const override
Returns unique type name of the renderer implementation.
static QList< QgsVectorTileBasicRendererStyle > simpleStyle(const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth, const QColor &lineStrokeColor, double lineStrokeWidth, const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize)
Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and ma...
bool willRenderFeature(const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context) override
Returns true if the specified feature will be rendered in the given render context.
QgsVectorTileBasicRenderer * clone() const override
Returns a clone of the renderer.
static QList< QgsVectorTileBasicRendererStyle > simpleStyleWithRandomColors()
Returns a list of styles to render all layers, using random colors.
QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const override
Returns a list of the layers required for rendering.
void renderBackground(QgsRenderContext &context) override
Renders the background if defined.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
void stopRender(QgsRenderContext &context) override
Finishes rendering and cleans up any resources.
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
QMap< QString, QgsFields > fields() const
Returns per-layer fields.
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
int renderZoomLevel() const
Returns the zoom level corresponding to the target render.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:52
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map).