34 #include <QtConcurrent>
35 #include <Qt3DCore/QTransform>
40 QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader(
const QgsVectorLayerChunkLoaderFactory *factory, QgsChunkNode *node )
41 : QgsChunkLoader( node )
43 , mContext( factory->mMap )
46 if ( node->level() < mFactory->mLeafLevel )
48 QTimer::singleShot( 0,
this, &QgsVectorLayerChunkLoader::finished );
58 QgsDebugMsg( QStringLiteral(
"Unknown 3D symbol type for vector layer: " ) + mFactory->mSymbol->type() );
61 mHandler.reset( handler );
64 exprContext.setFields( layer->
fields() );
65 mContext.setExpressionContext( exprContext );
67 QSet<QString> attributeNames;
68 if ( !mHandler->prepare( mContext, attributeNames ) )
70 QgsDebugMsg( QStringLiteral(
"Failed to prepare 3D feature handler!" ) );
86 mFutureWatcher =
new QFutureWatcher<void>(
this );
87 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
89 const QFuture<void> future = QtConcurrent::run( [req,
this]
91 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"VL chunk load" ) );
99 mContext.expressionContext().setFeature( f );
100 mHandler->processFeature( f, mContext );
105 mFutureWatcher->setFuture( future );
108 QgsVectorLayerChunkLoader::~QgsVectorLayerChunkLoader()
110 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
112 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
113 mFutureWatcher->waitForFinished();
117 void QgsVectorLayerChunkLoader::cancel()
122 Qt3DCore::QEntity *QgsVectorLayerChunkLoader::createEntity( Qt3DCore::QEntity *parent )
124 if ( mNode->level() < mFactory->mLeafLevel )
126 return new Qt3DCore::QEntity( parent );
129 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
130 mHandler->finalize( entity, mContext );
141 , mSymbol( symbol->clone() )
142 , mLeafLevel( leafLevel )
146 rootBbox.
xMin -= 1.0;
147 rootBbox.
xMax += 1.0;
148 rootBbox.
yMin -= 1.0;
149 rootBbox.
yMax += 1.0;
150 rootBbox.
zMin -= 1.0;
151 rootBbox.
zMax += 1.0;
152 setupQuadtree( rootBbox, -1, leafLevel );
155 QgsChunkLoader *QgsVectorLayerChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
157 return new QgsVectorLayerChunkLoader(
this, node );
165 : QgsChunkedEntity( -1,
166 new QgsVectorLayerChunkLoaderFactory( map, vl, symbol, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
168 mTransform =
new Qt3DCore::QTransform;
170 this->addComponent( mTransform );
177 QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
183 void QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged(
float newOffset )
185 QgsDebugMsgLevel( QStringLiteral(
"QgsVectorLayerChunkedEntity::onTerrainElevationOffsetChanged" ), 2 );
186 mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down)
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QgsFeature3DHandler * createHandlerForSymbol(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol, for the specified vector layer.
static QgsRectangle worldToMapExtent(const QgsAABB &bbox, const QgsVector3D &mapOrigin)
Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates.
static QgsAABB layerToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsCoordinateReferenceSystem &layerCrs, const QgsVector3D &mapOrigin, const QgsCoordinateReferenceSystem &mapCrs, const QgsCoordinateTransformContext &context)
Converts extent (in map layer's CRS) to axis aligned bounding box in 3D world coordinates.
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsCoordinateReferenceSystem crs
A rectangle specified with double values.
bool showBoundingBoxes() const
Returns whether to display bounding boxes of entity's tiles (for debugging)
Partial snapshot of vector layer's state (only the members necessary for access to features)
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsRectangle extent() const FINAL
Returns the extent of the layer.
#define QgsDebugMsgLevel(str, level)