21
21
#include " qgsterrainentity_p.h"
22
22
23
23
#include " qgisapp.h"
24
+ #include " qgsmapcanvas.h"
24
25
#include " qgsmaptoolidentifyaction.h"
25
26
26
27
#include < Qt3DRender/QObjectPicker>
@@ -93,8 +94,7 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )
93
94
return ;
94
95
95
96
QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates ( event->worldIntersection (), mCanvas ->map ()->origin () );
96
-
97
- QgsGeometry geom = QgsGeometry::fromPointXY ( QgsPointXY ( mapCoords.x (), mapCoords.y () ) );
97
+ QgsPointXY mapPoint ( mapCoords.x (), mapCoords.y () );
98
98
99
99
// estimate search radius
100
100
Qgs3DMapScene *scene = mCanvas ->scene ();
@@ -104,8 +104,16 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )
104
104
double searchRadiusMapUnits = scene->worldSpaceError ( searchRadiusPx, event->distance () );
105
105
106
106
QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance ()->identifyMapTool ();
107
+ QgsMapCanvas *canvas2D = identifyTool2D->canvas ();
108
+
109
+ // transform the point and search radius to CRS of the map canvas (if they are different)
110
+ QgsCoordinateTransform ct ( mCanvas ->map ()->crs (), canvas2D->mapSettings ().destinationCrs (), canvas2D->mapSettings ().transformContext () );
111
+ QgsPointXY mapPointCanvas2D = ct.transform ( mapPoint );
112
+ QgsPointXY mapPointSearchRadius ( mapPoint.x () + searchRadiusMapUnits, mapPoint.y () );
113
+ QgsPointXY mapPointSearchRadiusCanvas2D = ct.transform ( mapPointSearchRadius );
114
+ double searchRadiusCanvas2D = mapPointCanvas2D.distance ( mapPointSearchRadiusCanvas2D );
107
115
108
- identifyTool2D->identifyAndShowResults ( geom, searchRadiusMapUnits );
116
+ identifyTool2D->identifyAndShowResults ( QgsGeometry::fromPointXY ( mapPointCanvas2D ), searchRadiusCanvas2D );
109
117
}
110
118
111
119
void Qgs3DMapToolIdentify::onTerrainEntityChanged ()
0 commit comments