Skip to content
Permalink
Browse files
zoom to best scale with reprojection
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15649 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 31, 2011
1 parent 1045eda commit 52c277bc1192dc37f55aa256631d3c8597d71575
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/app/legend/qgslegend.cpp
@@ -1796,7 +1796,24 @@ void QgsLegend::legendLayerZoomNative()
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() ) );
}

0 comments on commit 52c277b

Please sign in to comment.