Skip to content

Commit 2f75c3c

Browse files
committed
[QGIS-Server][BUGFIX] GetLegendGraphics set layername
To have title instead of name in server getlegendgraphic response, the commit bb95a0f update getlegendgraphic to set the tree layer name. This update set the layer name with layer title. To fix it, I just store the layers name and reset them at the end of GetLegendGraphic request.
1 parent 49d864f commit 2f75c3c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/server/qgswmsserver.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,20 @@ QImage* QgsWMSServer::getLegendGraphics()
672672
}
673673
}
674674

675+
// Create the layer tree root
675676
QgsLayerTreeGroup rootGroup;
677+
// Store layers' name to reset them
678+
QMap<QString, QString> layerNameMap;
679+
// Create tree layer node for each layer
676680
foreach ( QString layerId, layerIds )
677681
{
682+
// get layer
678683
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
684+
// create tree layer node
679685
QgsLayerTreeLayer *layer = rootGroup.addLayer( ml );
686+
// store the layer's name
687+
layerNameMap.insert( layerId, ml->name() );
688+
// set layer name with layer's title to have it in legend
680689
if ( !ml->title().isEmpty() )
681690
layer->setLayerName( ml->title() );
682691
}
@@ -808,6 +817,13 @@ QImage* QgsWMSServer::getLegendGraphics()
808817

809818
p.end();
810819

820+
// reset layers' name
821+
foreach ( QString layerId, layerIds )
822+
{
823+
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
824+
ml->setLayerName( layerNameMap[ layerId ] );
825+
}
826+
// clear map layer registry
811827
QgsMapLayerRegistry::instance()->removeAllMapLayers();
812828
return paintImage;
813829
}

0 commit comments

Comments
 (0)