Skip to content
Permalink
Browse files

reproject canvas extent on crs change with OTFR enabled

  • Loading branch information
jef-n committed Jan 28, 2012
1 parent 33ab487 commit 65f32bc137993485cf6d1c88a4df6d5ad0c04908
@@ -494,11 +494,11 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle re
bb_rect.combineExtentWith( x[i], y[i] );
}

QgsDebugMsg( "Projected extent: " + QString(( bb_rect.toString() ).toLocal8Bit().data() ) );
QgsDebugMsg( "Projected extent: " + bb_rect.toString() );

if ( bb_rect.isEmpty() )
{
QgsMessageLog::logMessage( tr( "Reprojected extent is empty. Original extent: %1" ).arg( rect.toString() ), tr( "CRS" ) );
QgsDebugMsg( "Original extent: " + rect.toString() );
}

return bb_rect;
@@ -666,6 +666,7 @@ void QgsMapRenderer::setProjectionsEnabled( bool enabled )
QgsDebugMsg( "Adjusting DistArea projection on/off" );
mDistArea->setProjectionsEnabled( enabled );
updateFullExtent();
mLastExtent.setMinimal();
emit hasCrsTransformEnabled( enabled );
}
}
@@ -681,11 +682,24 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
if ( *mDestCRS != crs )
{
QgsRectangle rect;
if ( hasCrsTransformEnabled() && !mExtent.isEmpty() )
{
QgsCoordinateTransform transform( *mDestCRS, crs );
rect = transform.transformBoundingBox( mExtent );
}

invalidateCachedLayerCrs();
QgsDebugMsg( "Setting DistArea CRS to " + QString::number( crs.srsid() ) );
mDistArea->setSourceCrs( crs.srsid() );
*mDestCRS = crs;
updateFullExtent();

if ( !rect.isEmpty() )
{
setExtent( rect );
}

emit destinationSrsChanged();
}
}
@@ -656,7 +656,7 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
catch ( QgsCsException &cs )
{
QgsMessageLog::logMessage( tr( "Could not reproject view extent: %1" ).arg( cs.what() ), tr( "Raster" ) );
myProjectedViewExtent = rendererContext.extent();
myProjectedViewExtent.setMinimal();
}

try
@@ -666,7 +666,7 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
catch ( QgsCsException &cs )
{
QgsMessageLog::logMessage( tr( "Could not reproject layer extent: %1" ).arg( cs.what() ), tr( "Raster" ) );
myProjectedLayerExtent = mLayerExtent;
myProjectedViewExtent.setMinimal();
}
}
else
@@ -123,8 +123,10 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )

moveCanvasContents( true );

//connect(mMapRenderer, SIGNAL(updateMap()), this, SLOT(updateMap()));
connect( mMapRenderer, SIGNAL( drawError( QgsMapLayer* ) ), this, SLOT( showError( QgsMapLayer* ) ) );
connect( mMapRenderer, SIGNAL( hasCrsTransformEnabled( bool ) ), this, SLOT( crsTransformEnabled( bool ) ) );

crsTransformEnabled( hasCrsTransformEnabled() );

// project handling
connect( QgsProject::instance(), SIGNAL( readProject( const QDomDocument & ) ),
@@ -1491,7 +1493,6 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
{
QgsDebugMsg( "Couldn't read mapcanvas information from project" );
}

}

void QgsMapCanvas::writeProject( QDomDocument & doc )
@@ -1509,8 +1510,6 @@ void QgsMapCanvas::writeProject( QDomDocument & doc )
QDomElement mapcanvasNode = doc.createElement( "mapcanvas" );
qgisNode.appendChild( mapcanvasNode );
mMapRenderer->writeXML( mapcanvasNode, doc );


}

void QgsMapCanvas::zoomByFactor( double scaleFactor )
@@ -1541,3 +1540,15 @@ void QgsMapCanvas::dragEnterEvent( QDragEnterEvent * e )
// parent (e.g. QgisApp) to handle drops of map layers etc.
e->ignore();
}

void QgsMapCanvas::crsTransformEnabled( bool enabled )
{
if ( enabled )
{
QgsDebugMsg( "refreshing after reprojection was enabled" );
refresh();
connect( mMapRenderer, SIGNAL( destinationSrsChanged() ), this, SLOT( refresh() ) );
}
else
disconnect( mMapRenderer, SIGNAL( destinationSrsChanged() ), this, SLOT( refresh() ) );
}
@@ -395,6 +395,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/// Handle pattern for implementation object
std::auto_ptr<CanvasProperties> mCanvasProperties;

private slots:
void crsTransformEnabled( bool );

private:
/// this class is non-copyable
/**

0 comments on commit 65f32bc

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