Branch data Line data Source code
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 : : 21 : : #include "qgsfeature.h" 22 : : 23 : : #include "qgstiles.h" 24 : : 25 : : class QgsRenderContext; 26 : : 27 : : //! Features of a vector tile, grouped by sub-layer names (key of the map) 28 : : typedef QMap<QString, QVector<QgsFeature> > QgsVectorTileFeatures SIP_SKIP; 29 : : 30 : : /** 31 : : * \ingroup core 32 : : * \brief Contains decoded features of a single vector tile and any other data necessary 33 : : * for rendering of it. 34 : : * 35 : : * \since QGIS 3.14 36 : : */ 37 : 0 : class CORE_EXPORT QgsVectorTileRendererData 38 : : { 39 : : public: 40 : : //! Constructs the object 41 : 0 : explicit QgsVectorTileRendererData( QgsTileXYZ id ): mId( id ) {} 42 : : 43 : : //! Returns coordinates of the tile 44 : 0 : QgsTileXYZ id() const { return mId; } 45 : : 46 : : //! Sets polygon of the tile 47 : 0 : void setTilePolygon( QPolygon polygon ) { mTilePolygon = polygon; } 48 : : //! Returns polygon (made out of four corners of the tile) in screen coordinates calculated from render context 49 : 0 : QPolygon tilePolygon() const { return mTilePolygon; } 50 : : 51 : : //! Sets per-layer fields 52 : 0 : void setFields( const QMap<QString, QgsFields> &fields ) { mFields = fields; } 53 : : //! Returns per-layer fields 54 : 0 : QMap<QString, QgsFields> fields() const { return mFields; } 55 : : 56 : : //! Sets features of the tile 57 : 0 : void setFeatures( const QgsVectorTileFeatures &features ) SIP_SKIP { mFeatures = features; } 58 : : //! Returns features of the tile grouped by sub-layer names 59 : 0 : QgsVectorTileFeatures features() const SIP_SKIP { return mFeatures; } 60 : : //! Returns list of layer names present in the tile 61 : : QStringList layers() const { return mFeatures.keys(); } 62 : : //! Returns list of all features within a single sub-layer 63 : : QVector<QgsFeature> layerFeatures( const QString &layerName ) const { return mFeatures[layerName]; } 64 : : 65 : : private: 66 : : //! Position of the tile in the tile matrix set 67 : : QgsTileXYZ mId; 68 : : //! Per-layer fields 69 : : QMap<QString, QgsFields> mFields; 70 : : //! Features of the tile grouped into sub-layers 71 : : QgsVectorTileFeatures mFeatures; 72 : : //! Polygon (made out of four corners of the tile) in screen coordinates calculated from render context 73 : : QPolygon mTilePolygon; 74 : : }; 75 : : 76 : : /** 77 : : * \ingroup core 78 : : * \brief Abstract base class for all vector tile renderer implementations. 79 : : * 80 : : * For rendering it is expected that client code calls: 81 : : * 82 : : * # startRender() to prepare renderer 83 : : * # renderTile() for each tile 84 : : * # stopRender() to clean up renderer and free resources 85 : : * 86 : : * \since QGIS 3.14 87 : : */ 88 : 0 : class CORE_EXPORT QgsVectorTileRenderer 89 : : { 90 : : 91 : : #ifdef SIP_RUN 92 : : SIP_CONVERT_TO_SUBCLASS_CODE 93 : : 94 : : const QString type = sipCpp->type(); 95 : : 96 : : if ( type == QLatin1String( "basic" ) ) 97 : : sipType = sipType_QgsVectorTileBasicRenderer; 98 : : else 99 : : sipType = 0; 100 : : SIP_END 101 : : #endif 102 : : 103 : : public: 104 : 0 : virtual ~QgsVectorTileRenderer() = default; 105 : : 106 : : //! Returns unique type name of the renderer implementation 107 : : virtual QString type() const = 0; 108 : : 109 : : //! Returns a clone of the renderer 110 : : virtual QgsVectorTileRenderer *clone() const = 0 SIP_FACTORY; 111 : : 112 : : //! Initializes rendering. It should be paired with a stopRender() call. 113 : : virtual void startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange ) = 0; 114 : : 115 : : //! Returns field names of sub-layers that will be used for rendering. Must be called between startRender/stopRender. 116 : 0 : virtual QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext & ) SIP_SKIP { return QMap<QString, QSet<QString> >(); } 117 : : 118 : : //TODO QGIS 4.0 -- make pure virtual 119 : : 120 : : /** 121 : : * Returns a list of the layers required for rendering. 122 : : * 123 : : * Only layers which are visible at the specified \a tileZoom should be included in this list. 124 : : * 125 : : * An empty string present in the list indicates that all layer in the tiles are required. 126 : : * 127 : : * \since QGIS 3.16 128 : : */ 129 : 0 : virtual QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const { Q_UNUSED( context ); Q_UNUSED( tileZoom ); return QSet< QString >() << QString(); } 130 : : 131 : : //! Finishes rendering and cleans up any resources 132 : : virtual void stopRender( QgsRenderContext &context ) = 0; 133 : : 134 : : //! Renders given vector tile. Must be called between startRender/stopRender. 135 : : virtual void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) = 0; 136 : : 137 : : //! Writes renderer's properties to given XML element 138 : : virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const = 0; 139 : : //! Reads renderer's properties from given XML element 140 : : virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) = 0; 141 : : //! Resolves references to other objects - second phase of loading - after readXml() 142 : 0 : virtual void resolveReferences( const QgsProject &project ) { Q_UNUSED( project ) } 143 : : 144 : : }; 145 : : 146 : : #endif // QGSVECTORTILERENDERER_H