25
25
26
26
#include " qgisapp.h"
27
27
#include " qgsmapcanvas.h"
28
+ #include " qgscoordinateutils.h"
28
29
#include " qgsmaptoolidentifyaction.h"
29
30
30
31
#include " qgspointcloudlayer.h"
@@ -64,9 +65,8 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
64
65
QHash<QgsMapLayer *, QVector<QgsRayCastingUtils::RayHit>> allHits = Qgs3DUtils::castRay ( mCanvas ->scene (), ray, QgsRayCastingUtils::RayCastContext ( false , mCanvas ->size (), mCanvas ->cameraController ()->camera ()->farPlane () ) );
65
66
66
67
QHash<QgsPointCloudLayer *, QVector<QVariantMap>> pointCloudResults;
67
- QHash<QgsTiledSceneLayer *, QVector<QVariantMap>> tiledSceneResults;
68
68
69
- QList<QgsMapToolIdentify::IdentifyResult> identifyResults ;
69
+ QList<QgsMapToolIdentify::IdentifyResult> pointCloudIdentifyResults ;
70
70
QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance ()->identifyMapTool ();
71
71
identifyTool2D->clearResults ();
72
72
@@ -83,7 +83,7 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
83
83
identifyTool2D->showResultsForFeature ( vlayer, hit.fid , pt );
84
84
showTerrainResults = false ;
85
85
}
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.
87
87
else if ( QgsPointCloudLayer *pclayer = qobject_cast<QgsPointCloudLayer * >( it->first ) )
88
88
{
89
89
pointCloudResults[ pclayer ] = QVector<QVariantMap>();
@@ -94,11 +94,34 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
94
94
}
95
95
else if ( QgsTiledSceneLayer *tslayer = qobject_cast<QgsTiledSceneLayer *>( it->first ) )
96
96
{
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 )
99
118
{
100
- tiledSceneResults[ tslayer ]. append ( hit.attributes );
119
+ derivedAttributes[key] = hit.attributes [key]. toString ( );
101
120
}
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 } );
102
125
}
103
126
}
104
127
@@ -140,32 +163,13 @@ void Qgs3DMapToolIdentify::mouseReleaseEvent( QMouseEvent *event )
140
163
}
141
164
142
165
// Finally add all point cloud layers' results
166
+ // We add those last as the list can be quite big.
143
167
for ( auto it = pointCloudResults.constKeyValueBegin (); it != pointCloudResults.constKeyValueEnd (); ++it )
144
168
{
145
169
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 );
148
172
}
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
-
169
173
}
170
174
171
175
void Qgs3DMapToolIdentify::activate ()
0 commit comments