Skip to content

Commit b106f82

Browse files
committed
Fix calculation of atlas map extent when set to fixed scale mode
Credit to m-kuhn for discovering the fix
1 parent 7ef5092 commit b106f82

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/core/composer/qgsatlascomposition.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,8 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
514514
double ya1 = mTransformedFeatureBounds.yMinimum();
515515
double ya2 = mTransformedFeatureBounds.yMaximum();
516516
QgsRectangle newExtent = mTransformedFeatureBounds;
517-
QgsRectangle mOrigExtent( map->extent() );
517+
QgsRectangle originalExtent( map->extent() );
518+
QgsRectangle currentExtent( *map->currentMapExtent() );
518519

519520
//sanity check - only allow fixed scale mode for point layers
520521
bool isPointLayer = false;
@@ -536,19 +537,19 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
536537
QgsScaleCalculator calc;
537538
calc.setMapUnits( composition()->mapSettings().mapUnits() );
538539
calc.setDpi( 25.4 );
539-
double originalScale = calc.calculate( mOrigExtent, map->rect().width() );
540+
double originalScale = calc.calculate( currentExtent, map->rect().width() );
540541
double geomCenterX = ( xa1 + xa2 ) / 2.0;
541542
double geomCenterY = ( ya1 + ya2 ) / 2.0;
542543

543544
if ( map->atlasScalingMode() == QgsComposerMap::Fixed || isPointLayer )
544545
{
545546
// only translate, keep the original scale (i.e. width x height)
546-
double xMin = geomCenterX - mOrigExtent.width() / 2.0;
547-
double yMin = geomCenterY - mOrigExtent.height() / 2.0;
547+
double xMin = geomCenterX - currentExtent.width() / 2.0;
548+
double yMin = geomCenterY - currentExtent.height() / 2.0;
548549
newExtent = QgsRectangle( xMin,
549550
yMin,
550-
xMin + mOrigExtent.width(),
551-
yMin + mOrigExtent.height() );
551+
xMin + currentExtent.width(),
552+
yMin + currentExtent.height() );
552553

553554
//scale newExtent to match original scale of map
554555
//this is required for geographic coordinate systems, where the scale varies by extent
@@ -558,14 +559,14 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
558559
else if ( map->atlasScalingMode() == QgsComposerMap::Predefined )
559560
{
560561
// choose one of the predefined scales
561-
double newWidth = mOrigExtent.width();
562-
double newHeight = mOrigExtent.height();
562+
double newWidth = currentExtent.width();
563+
double newHeight = currentExtent.height();
563564
const QVector<qreal>& scales = mPredefinedScales;
564565
for ( int i = 0; i < scales.size(); i++ )
565566
{
566567
double ratio = scales[i] / originalScale;
567-
newWidth = mOrigExtent.width() * ratio;
568-
newHeight = mOrigExtent.height() * ratio;
568+
newWidth = currentExtent.width() * ratio;
569+
newHeight = currentExtent.height() * ratio;
569570

570571
// compute new extent, centered on feature
571572
double xMin = geomCenterX - newWidth / 2.0;
@@ -593,20 +594,20 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
593594
// auto scale
594595

595596
double geomRatio = mTransformedFeatureBounds.width() / mTransformedFeatureBounds.height();
596-
double mapRatio = mOrigExtent.width() / mOrigExtent.height();
597+
double mapRatio = originalExtent.width() / originalExtent.height();
597598

598599
// geometry height is too big
599600
if ( geomRatio < mapRatio )
600601
{
601-
// extent the bbox's width
602+
//extend the bbox's width
602603
double adjWidth = ( mapRatio * mTransformedFeatureBounds.height() - mTransformedFeatureBounds.width() ) / 2.0;
603604
xa1 -= adjWidth;
604605
xa2 += adjWidth;
605606
}
606607
// geometry width is too big
607608
else if ( geomRatio > mapRatio )
608609
{
609-
// extent the bbox's height
610+
//extend the bbox's height
610611
double adjHeight = ( mTransformedFeatureBounds.width() / mapRatio - mTransformedFeatureBounds.height() ) / 2.0;
611612
ya1 -= adjHeight;
612613
ya2 += adjHeight;

0 commit comments

Comments
 (0)