Skip to content
Permalink
Browse files
[composer] Correctly draw overview frame when map item CRS differs
  • Loading branch information
nyalldawson committed Mar 25, 2017
1 parent 83ac0e5 commit 345ce734c4578b001a6290cc7c409b2880edc2a7
@@ -23,6 +23,7 @@
#include "qgsmapsettings.h"
#include "qgspainting.h"
#include "qgscomposerutils.h"
#include "qgscsexception.h"

#include <QPainter>

@@ -82,6 +83,25 @@ void QgsComposerMapOverview::draw( QPainter *painter )

//get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
if ( overviewFrameMap->crs() !=
mComposerMap->crs() )
{
QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );

// reproject extent
QgsCoordinateTransform ct( overviewFrameMap->crs(),
mComposerMap->crs() );
g = g.densifyByCount( 20 );
try
{
g.transform( ct );
}
catch ( QgsCsException & )
{
}

otherExtent = g.asQPolygonF();
}

//get current map's extent as a QPolygonF
QPolygonF thisExtent = mComposerMap->visibleExtentPolygon();
@@ -50,6 +50,7 @@ class TestQgsComposerMapOverview : public QObject
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
void overviewMapCenter(); //test if centering of overview map frame works
void overviewReprojected(); //test that overview frame is reprojected

private:
QgsComposition *mComposition = nullptr;
@@ -217,5 +218,27 @@ void TestQgsComposerMapOverview::overviewMapCenter()
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewReprojected()
{
QgsComposerMap *overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
//overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
mComposition->addComposerMap( overviewMap );

mComposerMap->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
overviewMap->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 54030 ) );

mComposerMap->setNewExtent( QgsRectangle( 93, -64.245, 120.6, -45 ) );
overviewMap->setNewExtent( QgsRectangle( 4712502, -7620278, 10872777, -2531356 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );

QgsCompositionChecker checker( QStringLiteral( "composermap_overview_reprojected" ), mComposition );
checker.setControlPathPrefix( QStringLiteral( "composer_mapoverview" ) );

bool testResult = checker.testComposition( mReport, 0, 0 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

QGSTEST_MAIN( TestQgsComposerMapOverview )
#include "testqgscomposermapoverview.moc"
Binary file not shown.
Binary file not shown.

1 comment on commit 345ce73

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn commented on 345ce73 Mar 25, 2017

Brilliant.

Please sign in to comment.