Skip to content

Commit b264cfb

Browse files
uclarosnyalldawson
authored andcommitted
Tidy up tiled scene layer 3d identify results
1 parent 7bdc228 commit b264cfb

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

src/3d/qgstiledscenechunkloader_p.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ QVector<QgsRayCastingUtils::RayHit> QgsTiledSceneLayerChunkedEntity::rayIntersec
412412
QVariantMap vm;
413413
QgsTiledSceneTile tile = mIndex.getTile( minNode->tileId().uniqueId );
414414
// at this point this is mostly for debugging - we may want to change/rename what's returned here
415-
vm["node_id"] = tile.id();
416-
vm["node_error"] = tile.geometricError();
417-
vm["node_content"] = tile.resources().value( QStringLiteral( "content" ) );
418-
vm["triangle_index"] = minTriangleIndex;
415+
vm[ QStringLiteral( "node_id" ) ] = tile.id();
416+
vm[ QStringLiteral( "node_error" ) ] = tile.geometricError();
417+
vm[ QStringLiteral( "node_content" ) ] = tile.resources().value( QStringLiteral( "content" ) );
418+
vm[ QStringLiteral( "triangle_index" ) ] = minTriangleIndex;
419419
QgsRayCastingUtils::RayHit hit( minDist, intersectionPoint, FID_NULL, vm );
420420
result.append( hit );
421421
}

src/app/3d/qgs3dmaptoolidentify.cpp

+32-28
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "qgisapp.h"
2727
#include "qgsmapcanvas.h"
28+
#include "qgscoordinateutils.h"
2829
#include "qgsmaptoolidentifyaction.h"
2930

3031
#include "qgspointcloudlayer.h"
@@ -64,9 +65,8 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
6465
QHash<QgsMapLayer *, QVector<QgsRayCastingUtils::RayHit>> allHits = Qgs3DUtils::castRay( mCanvas->scene(), ray, QgsRayCastingUtils::RayCastContext( false, mCanvas->size(), mCanvas->cameraController()->camera()->farPlane() ) );
6566

6667
QHash<QgsPointCloudLayer *, QVector<QVariantMap>> pointCloudResults;
67-
QHash<QgsTiledSceneLayer *, QVector<QVariantMap>> tiledSceneResults;
6868

69-
QList<QgsMapToolIdentify::IdentifyResult> identifyResults;
69+
QList<QgsMapToolIdentify::IdentifyResult> pointCloudIdentifyResults;
7070
QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool();
7171
identifyTool2D->clearResults();
7272

@@ -83,7 +83,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
8383
identifyTool2D->showResultsForFeature( vlayer, hit.fid, pt );
8484
showTerrainResults = false;
8585
}
86-
// We need to restructure point cloud layer results to display them later
86+
// We need to restructure point cloud layer results to display them later. We may have multiple hits for each layer.
8787
else if ( QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer * >( it->first ) )
8888
{
8989
pointCloudResults[ pclayer ] = QVector<QVariantMap>();
@@ -94,11 +94,34 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
9494
}
9595
else if ( QgsTiledSceneLayer *tslayer = qobject_cast<QgsTiledSceneLayer *>( it->first ) )
9696
{
97-
tiledSceneResults[ tslayer ] = QVector<QVariantMap>();
98-
for ( const QgsRayCastingUtils::RayHit &hit : it->second )
97+
Q_UNUSED( tslayer )
98+
// We are only handling a single hit for each layer
99+
const QgsRayCastingUtils::RayHit hit = it->second.first();
100+
const QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( hit.pos, mCanvas->mapSettings()->origin() );
101+
102+
QMap< QString, QString > derivedAttributes;
103+
QString x;
104+
QString y;
105+
QgsCoordinateUtils::formatCoordinatePartsForProject(
106+
QgsProject::instance(),
107+
QgsPointXY( mapCoords.x(), mapCoords.y() ),
108+
QgsProject::instance()->crs(),
109+
6, x, y
110+
);
111+
112+
derivedAttributes.insert( tr( "(clicked coordinate X)" ), x );
113+
derivedAttributes.insert( tr( "(clicked coordinate Y)" ), y );
114+
derivedAttributes.insert( tr( "(clicked coordinate Z)" ), QLocale().toString( mapCoords.z(), 'f' ) );
115+
116+
const QList<QString> keys = hit.attributes.keys();
117+
for ( const QString &key : keys )
99118
{
100-
tiledSceneResults[ tslayer ].append( hit.attributes );
119+
derivedAttributes[key] = hit.attributes[key].toString();
101120
}
121+
QString nodeId = derivedAttributes[ QStringLiteral( "node_id" ) ];
122+
// only derived attributes are supported for now, so attributes is empty
123+
QgsMapToolIdentify::IdentifyResult res( it->first, nodeId, {}, derivedAttributes );
124+
identifyTool2D->showIdentifyResults( { res } );
102125
}
103126
}
104127

@@ -140,32 +163,13 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
140163
}
141164

142165
// Finally add all point cloud layers' results
166+
// We add those last as the list can be quite big.
143167
for ( auto it = pointCloudResults.constKeyValueBegin(); it != pointCloudResults.constKeyValueEnd(); ++it )
144168
{
145169
QgsMapToolIdentify identifyTool( nullptr );
146-
identifyTool.fromPointCloudIdentificationToIdentifyResults( it->first, it->second, identifyResults );
147-
identifyTool2D->showIdentifyResults( identifyResults );
170+
identifyTool.fromPointCloudIdentificationToIdentifyResults( it->first, it->second, pointCloudIdentifyResults );
171+
identifyTool2D->showIdentifyResults( pointCloudIdentifyResults );
148172
}
149-
150-
for ( auto it = tiledSceneResults.constKeyValueBegin(); it != tiledSceneResults.constKeyValueEnd(); ++it )
151-
{
152-
// for the whole layer
153-
for ( const QVariantMap &hitAttributes : it->second )
154-
{
155-
QMap<QString, QString> derivedAttributes;
156-
const QList<QString> keys = hitAttributes.keys();
157-
for ( const QString &key : keys )
158-
{
159-
derivedAttributes[key] = hitAttributes[key].toString();
160-
}
161-
QString nodeId = hitAttributes["node_id"].toString();
162-
QgsMapToolIdentify::IdentifyResult res( it->first, nodeId, QMap<QString, QString>(), derivedAttributes );
163-
identifyResults.append( res );
164-
}
165-
166-
identifyTool2D->showIdentifyResults( identifyResults );
167-
}
168-
169173
}
170174

171175
void Qgs3DMapToolIdentify::activate()

0 commit comments

Comments
 (0)