Skip to content

Commit e148d4b

Browse files
committedSep 24, 2018
Fix identification in 3D if CRS of 2D and 3D canvas are different
1 parent 88ccb88 commit e148d4b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎src/app/3d/qgs3dmaptoolidentify.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsterrainentity_p.h"
2222

2323
#include "qgisapp.h"
24+
#include "qgsmapcanvas.h"
2425
#include "qgsmaptoolidentifyaction.h"
2526

2627
#include <Qt3DRender/QObjectPicker>
@@ -93,8 +94,7 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )
9394
return;
9495

9596
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() );
9898

9999
// estimate search radius
100100
Qgs3DMapScene *scene = mCanvas->scene();
@@ -104,8 +104,16 @@ void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event )
104104
double searchRadiusMapUnits = scene->worldSpaceError( searchRadiusPx, event->distance() );
105105

106106
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 );
107115

108-
identifyTool2D->identifyAndShowResults( geom, searchRadiusMapUnits );
116+
identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), searchRadiusCanvas2D );
109117
}
110118

111119
void Qgs3DMapToolIdentify::onTerrainEntityChanged()

0 commit comments

Comments
 (0)
Please sign in to comment.