Skip to content

Commit

Permalink
Ensure map is centered when updating map extent (fix #6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 28, 2013
1 parent 969ddf5 commit 5aac8bb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,19 @@ void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()

if ( currentWidthHeightRatio < newWidthHeightRatio )
{
//enlarge height of new extent
//enlarge height of new extent, ensuring the map center stays the same
double newHeight = newExtent.width() / currentWidthHeightRatio;
newExtent.setYMinimum( newExtent.yMaximum() - newHeight );
double deltaHeight = newHeight - newExtent.height();
newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
}
else if ( currentWidthHeightRatio > newWidthHeightRatio )
{
//enlarge width of new extent
//enlarge width of new extent, ensuring the map center stays the same
double newWidth = currentWidthHeightRatio * newExtent.height();
newExtent.setXMaximum( newExtent.xMinimum() + newWidth );
double deltaWidth = newWidth - newExtent.width();
newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
}

//fill text into line edits
Expand Down

0 comments on commit 5aac8bb

Please sign in to comment.