|
14 | 14 | * (at your option) any later version. *
|
15 | 15 | * *
|
16 | 16 | ***************************************************************************/
|
| 17 | +#include <algorithm> |
17 | 18 | #include <stdexcept>
|
18 | 19 | #include <QtAlgorithms>
|
19 | 20 |
|
@@ -438,11 +439,30 @@ void QgsAtlasComposition::computeExtent( QgsComposerMap *map )
|
438 | 439 | // QgsGeometry::boundingBox is expressed in the geometry"s native CRS
|
439 | 440 | // We have to transform the geometry to the destination CRS and ask for the bounding box
|
440 | 441 | // Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
|
441 |
| - QgsGeometry g(currentGeometry( map->crs() )); |
| 442 | + QgsGeometry g = currentGeometry( map->crs() ); |
442 | 443 | // Rotating the geometry, so the bounding box is correct wrt map rotation
|
443 | 444 | if ( map->mapRotation() != 0.0 )
|
444 |
| - g.rotate(map->mapRotation(), g.centroid().asPoint()); |
445 |
| - mTransformedFeatureBounds = g.boundingBox(); |
| 445 | + { |
| 446 | + QgsPointXY prevCenter = g.boundingBox().center(); |
| 447 | + g.rotate( map->mapRotation(), g.boundingBox().center() ); |
| 448 | + // Rotation center will be still the bounding box center of an unrotated geometry. |
| 449 | + // Which means, if the center of bbox moves after rotation, the viewport will |
| 450 | + // also be offset, and part of the geometry will fall out of bounds. |
| 451 | + // Here we compensate for that roughly: by extending the rotated bounds |
| 452 | + // so that its center is the same as the original. |
| 453 | + QgsRectangle bounds = g.boundingBox(); |
| 454 | + double dx = std::max( std::abs( prevCenter.x() - bounds.xMinimum() ), |
| 455 | + std::abs( prevCenter.x() - bounds.xMaximum() ) ); |
| 456 | + double dy = std::max( std::abs( prevCenter.y() - bounds.yMinimum() ), |
| 457 | + std::abs( prevCenter.y() - bounds.yMaximum() ) ); |
| 458 | + QgsPointXY center = g.boundingBox().center(); |
| 459 | + mTransformedFeatureBounds = QgsRectangle( center.x() - dx, center.y() - dy, |
| 460 | + center.x() + dx, center.y() + dy ); |
| 461 | + } |
| 462 | + else |
| 463 | + { |
| 464 | + mTransformedFeatureBounds = g.boundingBox(); |
| 465 | + } |
446 | 466 | }
|
447 | 467 |
|
448 | 468 | void QgsAtlasComposition::prepareMap( QgsComposerMap *map )
|
|
0 commit comments