Skip to content

Commit

Permalink
Fix identification in 3D if CRS of 2D and 3D canvas are different
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 24, 2018
1 parent 88ccb88 commit e148d4b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/app/3d/qgs3dmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgsterrainentity_p.h"

#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include "qgsmaptoolidentifyaction.h"

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

QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( event->worldIntersection(), mCanvas->map()->origin() );

QgsGeometry geom = QgsGeometry::fromPointXY( QgsPointXY( mapCoords.x(), mapCoords.y() ) );
QgsPointXY mapPoint( mapCoords.x(), mapCoords.y() );

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

QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool();
QgsMapCanvas *canvas2D = identifyTool2D->canvas();

// transform the point and search radius to CRS of the map canvas (if they are different)
QgsCoordinateTransform ct( mCanvas->map()->crs(), canvas2D->mapSettings().destinationCrs(), canvas2D->mapSettings().transformContext() );
QgsPointXY mapPointCanvas2D = ct.transform( mapPoint );
QgsPointXY mapPointSearchRadius( mapPoint.x() + searchRadiusMapUnits, mapPoint.y() );
QgsPointXY mapPointSearchRadiusCanvas2D = ct.transform( mapPointSearchRadius );
double searchRadiusCanvas2D = mapPointCanvas2D.distance( mapPointSearchRadiusCanvas2D );

identifyTool2D->identifyAndShowResults( geom, searchRadiusMapUnits );
identifyTool2D->identifyAndShowResults( QgsGeometry::fromPointXY( mapPointCanvas2D ), searchRadiusCanvas2D );
}

void Qgs3DMapToolIdentify::onTerrainEntityChanged()
Expand Down

0 comments on commit e148d4b

Please sign in to comment.