Skip to content

Commit

Permalink
[Fix #11841] Revert "Fix calculation of atlas map extent when set to …
Browse files Browse the repository at this point in the history
…fixed scale mode"

This reverts commit b106f82 and fixes the setting of the atlas feature in composer.

According to Nyall original commit b106f82 was introduced to fix a test.
He will look to fix the test, but in the mean time we rather need working features rather than passing tests.
One might wants to disable the test?
  • Loading branch information
3nids committed Dec 11, 2014
1 parent c8b9018 commit 7f8006f
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -514,8 +514,7 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
double ya1 = mTransformedFeatureBounds.yMinimum();
double ya2 = mTransformedFeatureBounds.yMaximum();
QgsRectangle newExtent = mTransformedFeatureBounds;
QgsRectangle originalExtent( map->extent() );
QgsRectangle currentExtent( *map->currentMapExtent() );
QgsRectangle mOrigExtent( map->extent() );

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

if ( map->atlasScalingMode() == QgsComposerMap::Fixed || isPointLayer )
{
// only translate, keep the original scale (i.e. width x height)
double xMin = geomCenterX - currentExtent.width() / 2.0;
double yMin = geomCenterY - currentExtent.height() / 2.0;
double xMin = geomCenterX - mOrigExtent.width() / 2.0;
double yMin = geomCenterY - mOrigExtent.height() / 2.0;
newExtent = QgsRectangle( xMin,
yMin,
xMin + currentExtent.width(),
yMin + currentExtent.height() );
xMin + mOrigExtent.width(),
yMin + mOrigExtent.height() );

//scale newExtent to match original scale of map
//this is required for geographic coordinate systems, where the scale varies by extent
Expand All @@ -559,14 +558,14 @@ void QgsAtlasComposition::prepareMap( QgsComposerMap* map )
else if ( map->atlasScalingMode() == QgsComposerMap::Predefined )
{
// choose one of the predefined scales
double newWidth = currentExtent.width();
double newHeight = currentExtent.height();
double newWidth = mOrigExtent.width();
double newHeight = mOrigExtent.height();
const QVector<qreal>& scales = mPredefinedScales;
for ( int i = 0; i < scales.size(); i++ )
{
double ratio = scales[i] / originalScale;
newWidth = currentExtent.width() * ratio;
newHeight = currentExtent.height() * ratio;
newWidth = mOrigExtent.width() * ratio;
newHeight = mOrigExtent.height() * ratio;

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

double geomRatio = mTransformedFeatureBounds.width() / mTransformedFeatureBounds.height();
double mapRatio = originalExtent.width() / originalExtent.height();
double mapRatio = mOrigExtent.width() / mOrigExtent.height();

// geometry height is too big
if ( geomRatio < mapRatio )
{
//extend the bbox's width
// extent the bbox's width
double adjWidth = ( mapRatio * mTransformedFeatureBounds.height() - mTransformedFeatureBounds.width() ) / 2.0;
xa1 -= adjWidth;
xa2 += adjWidth;
}
// geometry width is too big
else if ( geomRatio > mapRatio )
{
//extend the bbox's height
// extent the bbox's height
double adjHeight = ( mTransformedFeatureBounds.width() / mapRatio - mTransformedFeatureBounds.height() ) / 2.0;
ya1 -= adjHeight;
ya2 += adjHeight;
Expand Down

0 comments on commit 7f8006f

Please sign in to comment.