Skip to content

Commit a18e396

Browse files
committed
Fix extent to determine center point for angle calculation
1 parent 3d380c6 commit a18e396

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/app/qgsdecorationnortharrow.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
203203

204204
bool goodDirn = false;
205205

206-
if ( mapCanvas->layerCount() > 0 )
206+
// Get the shown extent...
207+
QgsRectangle canvasExtent = mapCanvas->extent();
208+
// ... and all layers extent, ...
209+
QgsRectangle fullExtent = mapCanvas->fullExtent();
210+
// ... and combine
211+
QgsRectangle extent = canvasExtent.intersect( & fullExtent );
212+
213+
// If no layers are added or shown, we can't get any direction
214+
if ( mapCanvas->layerCount() > 0 && ! extent.isEmpty() )
207215
{
208216
QgsCoordinateReferenceSystem outputCRS = mapCanvas->mapRenderer()->destinationCrs();
209217

@@ -216,7 +224,6 @@ bool QgsDecorationNorthArrow::calculateNorthDirection()
216224

217225
QgsCoordinateTransform transform( outputCRS, ourCRS );
218226

219-
QgsRectangle extent = mapCanvas->extent();
220227
QgsPoint p1( extent.center() );
221228
// A point a bit above p1. XXX assumes that y increases up!!
222229
// May need to involve the maptopixel transform if this proves

0 commit comments

Comments
 (0)