Skip to content

Commit d84252c

Browse files
committedAug 27, 2018
Fix project defaults to EPSG:4326 when a non-spatial layer is first
layer added Fixes #19690
1 parent 1b56055 commit d84252c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
 

‎src/gui/layertree/qgslayertreemapcanvasbridge.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
6363
else
6464
setCanvasLayers( mRoot, canvasLayers, overviewLayers, allLayerOrder );
6565

66-
QList<QgsLayerTreeLayer *> layerNodes = mRoot->findLayers();
67-
int currentLayerCount = layerNodes.count();
68-
bool firstLayers = mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentLayerCount != 0;
66+
const QList<QgsLayerTreeLayer *> layerNodes = mRoot->findLayers();
67+
int currentSpatialLayerCount = 0;
68+
for ( QgsLayerTreeLayer *layerNode : layerNodes )
69+
{
70+
if ( layerNode->layer() && layerNode->layer()->isSpatial() )
71+
currentSpatialLayerCount++;
72+
}
73+
74+
bool firstLayers = mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentSpatialLayerCount != 0;
6975

7076
mCanvas->setLayers( canvasLayers );
7177
if ( mOverviewCanvas )
@@ -95,8 +101,8 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
95101
QgsProject::instance()->setCrs( mFirstCRS );
96102
}
97103

98-
mLastLayerCount = currentLayerCount;
99-
if ( currentLayerCount == 0 )
104+
mLastLayerCount = currentSpatialLayerCount;
105+
if ( currentSpatialLayerCount == 0 )
100106
mFirstCRS = QgsCoordinateReferenceSystem();
101107

102108
mPendingCanvasUpdate = false;
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.