Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
reproject canvas extent on crs change with OTFR enabled
  • Loading branch information
jef-n committed Jan 28, 2012
1 parent 33ab487 commit 65f32bc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsmaprenderer.cpp
Expand Up @@ -666,6 +666,7 @@ void QgsMapRenderer::setProjectionsEnabled( bool enabled )
QgsDebugMsg( "Adjusting DistArea projection on/off" );
mDistArea->setProjectionsEnabled( enabled );
updateFullExtent();
mLastExtent.setMinimal();
emit hasCrsTransformEnabled( enabled );
}
}
Expand All @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 15 additions & 4 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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 & ) ),
Expand Down Expand Up @@ -1491,7 +1493,6 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
{
QgsDebugMsg( "Couldn't read mapcanvas information from project" );
}

}

void QgsMapCanvas::writeProject( QDomDocument & doc )
Expand All @@ -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 )
Expand Down Expand Up @@ -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() ) );
}
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -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
/**
Expand Down

0 comments on commit 65f32bc

Please sign in to comment.