Skip to content

Commit

Permalink
[canvas] Fix zoom to selection for single point selection when layer …
Browse files Browse the repository at this point in the history
…is reprojected
  • Loading branch information
nirvn committed Nov 23, 2019
1 parent ed7d13d commit c7d4892
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1029,8 +1029,9 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
if ( layer->geometryType() == QgsWkbTypes::PointGeometry && rect.isEmpty() )
{
int scaleFactor = 5;
QgsPointXY center = mSettings.mapToLayerCoordinates( layer, rect.center() );
QgsRectangle extentRect = mSettings.mapToLayerCoordinates( layer, extent() ).scaled( 1.0 / scaleFactor, &center );
QgsPointXY centerMapCoordinates = rect.center();
QgsPointXY centerLayerCoordinates = mSettings.mapToLayerCoordinates( layer, centerMapCoordinates );
QgsRectangle extentRect = mSettings.mapToLayerCoordinates( layer, extent() ).scaled( 1.0 / scaleFactor, &centerLayerCoordinates );
QgsFeatureRequest req = QgsFeatureRequest().setFilterRect( extentRect ).setLimit( 1000 ).setNoAttributes();
QgsFeatureIterator fit = layer->getFeatures( req );
QgsFeature f;
Expand All @@ -1040,7 +1041,7 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
while ( fit.nextFeature( f ) )
{
QgsPointXY point = f.geometry().asPoint();
double sqrDist = point.sqrDist( center );
double sqrDist = point.sqrDist( centerLayerCoordinates );
if ( sqrDist > closestSquaredDistance || sqrDist < 4 * std::numeric_limits<double>::epsilon() )
continue;
pointFound = true;
Expand All @@ -1051,7 +1052,7 @@ void QgsMapCanvas::zoomToSelected( QgsVectorLayer *layer )
{
// combine selected point with closest point and scale this rect
rect.combineExtentWith( mSettings.layerToMapCoordinates( layer, closestPoint ) );
rect.scale( scaleFactor, &center );
rect.scale( scaleFactor, &centerMapCoordinates );
}
}

Expand Down

0 comments on commit c7d4892

Please sign in to comment.