mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[composer] Correctly draw overview frame when map item CRS differs
This commit is contained in:
parent
83ac0e584d
commit
345ce734c4
@ -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.
After Width: | Height: | Size: 6.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
x
Reference in New Issue
Block a user