QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsvectortilerenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortilerenderer.h
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
16#ifndef QGSVECTORTILERENDERER_H
17#define QGSVECTORTILERENDERER_H
18
19#include "qgis_core.h"
20#include "qgsfeature.h"
21#include "qgstiles.h"
22
25class QgsProject;
26
28typedef QMap<QString, QVector<QgsFeature> > QgsVectorTileFeatures SIP_SKIP;
29
38{
39 public:
42 : mId( id )
43 , mRenderZoomLevel( id.zoomLevel() )
44 {}
45
47 QgsTileXYZ id() const { return mId; }
48
50 void setTilePolygon( QPolygon polygon ) { mTilePolygon = polygon; }
52 QPolygon tilePolygon() const { return mTilePolygon; }
53
63 void setRenderZoomLevel( int level ) { mRenderZoomLevel = level; }
64
74 int renderZoomLevel() const { return mRenderZoomLevel; }
75
77 void setFields( const QMap<QString, QgsFields> &fields ) { mFields = fields; }
79 QMap<QString, QgsFields> fields() const { return mFields; }
80
84 QgsVectorTileFeatures features() const SIP_SKIP { return mFeatures; }
86 QStringList layers() const { return mFeatures.keys(); }
88 QVector<QgsFeature> layerFeatures( const QString &layerName ) const { return mFeatures[layerName]; }
89
90 private:
92 QgsTileXYZ mId;
93
98 int mRenderZoomLevel = -1;
99
101 QMap<QString, QgsFields> mFields;
103 QgsVectorTileFeatures mFeatures;
105 QPolygon mTilePolygon;
106};
107
120class CORE_EXPORT QgsVectorTileRenderer
121{
122
123#ifdef SIP_RUN
125
126 const QString type = sipCpp->type();
127
128 if ( type == QLatin1String( "basic" ) )
129 sipType = sipType_QgsVectorTileBasicRenderer;
130 else
131 sipType = 0;
132 SIP_END
133#endif
134
135 public:
136 virtual ~QgsVectorTileRenderer() = default;
137
139 virtual QString type() const = 0;
140
143
145 virtual void startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange ) = 0;
146
148 virtual QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext & ) SIP_SKIP { return QMap<QString, QSet<QString> >(); }
149
150 //TODO QGIS 4.0 -- make pure virtual
151
161 virtual QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const { Q_UNUSED( context ); Q_UNUSED( tileZoom ); return QSet< QString >() << QString(); }
162
164 virtual void stopRender( QgsRenderContext &context ) = 0;
165
167 virtual void renderBackground( QgsRenderContext &context ) = 0;
168
170 virtual void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) = 0;
171
177 virtual bool willRenderFeature( const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context ) = 0;
178
186 virtual void renderSelectedFeatures( const QList< QgsFeature > &selection, QgsRenderContext &context ) = 0;
187
189 virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const = 0;
191 virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) = 0;
193 virtual void resolveReferences( const QgsProject &project ) { Q_UNUSED( project ) }
194
195};
196
197#endif // QGSVECTORTILERENDERER_H
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
A range of tiles in a tile matrix.
Definition qgstiles.h:114
Stores coordinates of a tile in a tile matrix set.
Definition qgstiles.h:39
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
void setFields(const QMap< QString, QgsFields > &fields)
Sets per-layer fields.
QPolygon tilePolygon() const
Returns polygon (made out of four corners of the tile) in screen coordinates calculated from render c...
QgsVectorTileRendererData(QgsTileXYZ id)
Constructs the object.
QMap< QString, QgsFields > fields() const
Returns per-layer fields.
void setTilePolygon(QPolygon polygon)
Sets polygon of the tile.
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
void setRenderZoomLevel(int level)
Sets the zoom level corresponding to the target render.
QVector< QgsFeature > layerFeatures(const QString &layerName) const
Returns list of all features within a single sub-layer.
int renderZoomLevel() const
Returns the zoom level corresponding to the target render.
QStringList layers() const
Returns list of layer names present in the tile.
void setFeatures(const QgsVectorTileFeatures &features)
Sets features of the tile.
QgsTileXYZ id() const
Returns coordinates of the tile.
Abstract base class for all vector tile renderer implementations.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml().
virtual void renderSelectedFeatures(const QList< QgsFeature > &selection, QgsRenderContext &context)=0
Renders the specified features in a selected state.
virtual QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const
Returns a list of the layers required for rendering.
virtual void renderBackground(QgsRenderContext &context)=0
Renders the background if defined.
virtual QString type() const =0
Returns unique type name of the renderer implementation.
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
virtual void renderTile(const QgsVectorTileRendererData &tile, QgsRenderContext &context)=0
Renders given vector tile. Must be called between startRender/stopRender.
virtual QgsVectorTileRenderer * clone() const =0
Returns a clone of the renderer.
virtual QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &)
Returns field names of sub-layers that will be used for rendering. Must be called between startRender...
virtual void stopRender(QgsRenderContext &context)=0
Finishes rendering and cleans up any resources.
virtual ~QgsVectorTileRenderer()=default
virtual void startRender(QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange)=0
Initializes rendering. It should be paired with a stopRender() call.
virtual bool willRenderFeature(const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context)=0
Returns true if the specified feature will be rendered in the given render context.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map).