Skip to content
Permalink
Browse files

Fix zoom and scale of MapCanvas when DestinationCrs changes

  • Loading branch information
ahuarte47 committed Jun 30, 2016
1 parent bf07d2b commit 5b17456393a6dc6407074a4879e5905e42ed3e37
Showing with 20 additions and 18 deletions.
  1. +20 −18 src/gui/qgsmapcanvas.cpp
@@ -558,32 +558,34 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
if ( mSettings.destinationCrs() == crs )
return;

if ( mSettings.hasCrsTransformEnabled() )
// try to reproject current extent to the new one
QgsRectangle rect;
if ( !mSettings.visibleExtent().isEmpty() )
{
// try to reproject current extent to the new one
QgsRectangle rect;
if ( !mSettings.visibleExtent().isEmpty() )
QgsCoordinateTransform transform( mSettings.destinationCrs(), crs );
try
{
QgsCoordinateTransform transform( mSettings.destinationCrs(), crs );
try
{
rect = transform.transformBoundingBox( mSettings.visibleExtent() );
}
catch ( QgsCsException &e )
{
Q_UNUSED( e );
QgsDebugMsg( QString( "Transform error caught: %1" ).arg( e.what() ) );
}
rect = transform.transformBoundingBox( mSettings.visibleExtent() );
}
if ( !rect.isEmpty() )
catch ( QgsCsException &e )
{
setExtent( rect );
Q_UNUSED( e );
QgsDebugMsg( QString( "Transform error caught: %1" ).arg( e.what() ) );
}
}

QgsDebugMsg( "refreshing after destination CRS changed" );
refresh();
if ( !mSettings.hasCrsTransformEnabled() )
{
mSettings.setMapUnits( crs.mapUnits() );
}
if ( !rect.isEmpty() )
{
setExtent( rect );
}

QgsDebugMsg( "refreshing after destination CRS changed" );
refresh();

mSettings.setDestinationCrs( crs );

updateDatumTransformEntries();

0 comments on commit 5b17456

Please sign in to comment.
You can’t perform that action at this time.