[QGIS Commit] r15649 - trunk/qgis/src/app/legend
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Mar 31 06:13:48 EDT 2011
Author: rblazek
Date: 2011-03-31 03:13:48 -0700 (Thu, 31 Mar 2011)
New Revision: 15649
Modified:
trunk/qgis/src/app/legend/qgslegend.cpp
Log:
zoom to best scale with reprojection
Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp 2011-03-31 09:00:00 UTC (rev 15648)
+++ trunk/qgis/src/app/legend/qgslegend.cpp 2011-03-31 10:13:48 UTC (rev 15649)
@@ -1796,7 +1796,24 @@
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
layer->setCacheImage( NULL );
- mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
+ if ( mMapCanvas->hasCrsTransformEnabled() )
+ {
+ // get legth of central canvas pixel width in source raster crs
+ QgsRectangle e = mMapCanvas->extent();
+ QgsMapRenderer* r = mMapCanvas->mapRenderer();
+ QgsPoint p1( e.center().x(), e.center().y() );
+ QgsPoint p2( e.center().x() + e.width() / r->width(), e.center().y() + e.height() / r->height() );
+ QgsCoordinateTransform ct( r->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->rasterUnitsPerPixel() / width ) );
+ }
+ else
+ {
+ mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
+ }
mMapCanvas->refresh();
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
}
More information about the QGIS-commit
mailing list