Skip to content
Permalink
Browse files
fix legendLayerZoomNative to use diagonal of source raster pixel
to match the use of the diagonal of mapCanvas pixel.
Also fix spelling in a comment.

(fixes #3609)
  • Loading branch information
stevenmizuno authored and jef-n committed Oct 16, 2015
1 parent 872d5b3 commit 7f731ae309bc49861cd3c13b6f75fa37db68f521
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/app/qgisapp.cpp
@@ -7675,17 +7675,16 @@ void QgisApp::legendLayerZoomNative()

if ( mMapCanvas->hasCrsTransformEnabled() )
{
// get legth of central canvas pixel width in source raster crs
// get length of central canvas pixel width in source raster crs
QgsRectangle e = mMapCanvas->extent();
QSize s = mMapCanvas->mapSettings().outputSize();
QgsPoint p1( e.center().x(), e.center().y() );
QgsPoint p2( e.center().x() + e.width() / s.width(), e.center().y() + e.height() / s.height() );
QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), layer->crs() );
p1 = ct.transform( p1 );
p2 = ct.transform( p2 );
double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
// This is not perfect of course, we use the resolution in just one direction
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixelX() / width ) );
double width = sqrt( p1.sqrDist( p2 ) ); // width (actually the diagonal) of reprojected pixel
mMapCanvas->zoomByFactor( sqrt( layer->rasterUnitsPerPixelX() * layer->rasterUnitsPerPixelX() + layer->rasterUnitsPerPixelY() * layer->rasterUnitsPerPixelY() ) / width );
}
else
{

0 comments on commit 7f731ae

Please sign in to comment.