Skip to content

Commit 4aa6061

Browse files
author
rblazek
committedMar 31, 2011
zoom to best scale with reprojection
git-svn-id: http://svn.osgeo.org/qgis/trunk@15649 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5a27a81 commit 4aa6061

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎src/app/legend/qgslegend.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,24 @@ void QgsLegend::legendLayerZoomNative()
17961796
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
17971797

17981798
layer->setCacheImage( NULL );
1799-
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
1799+
if ( mMapCanvas->hasCrsTransformEnabled() )
1800+
{
1801+
// get legth of central canvas pixel width in source raster crs
1802+
QgsRectangle e = mMapCanvas->extent();
1803+
QgsMapRenderer* r = mMapCanvas->mapRenderer();
1804+
QgsPoint p1( e.center().x(), e.center().y() );
1805+
QgsPoint p2( e.center().x() + e.width() / r->width(), e.center().y() + e.height() / r->height() );
1806+
QgsCoordinateTransform ct( r->destinationCrs(), layer->crs() );
1807+
p1 = ct.transform( p1 );
1808+
p2 = ct.transform( p2 );
1809+
double width = sqrt( p1.sqrDist( p2 ) ); // width of reprojected pixel
1810+
// This is not perfect of course, we use the resolution in just one direction
1811+
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / width ) );
1812+
}
1813+
else
1814+
{
1815+
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
1816+
}
18001817
mMapCanvas->refresh();
18011818
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
18021819
}

0 commit comments

Comments
 (0)
Please sign in to comment.