Skip to content
Permalink
Browse files

[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.
  • Loading branch information
rldhont committed Jan 2, 2015
1 parent ddb37e2 commit 102cfedcba5a092f64e7bd076f6e86cceb21a774
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/mapserver/qgswmsserver.cpp
@@ -656,11 +656,20 @@ QImage* QgsWMSServer::getLegendGraphics()
}
}

// Create the layer tree root
QgsLayerTreeGroup rootGroup;
// Store layers' name to reset them
QMap<QString, QString> layerNameMap;
// Create tree layer node for each layer
foreach ( QString layerId, layerIds )
{
// get layer
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
// create tree layer node
QgsLayerTreeLayer *layer = rootGroup.addLayer( ml );
// store the layer's name
layerNameMap.insert( layerId, ml->name() );
// set layer name with layer's title to have it in legend
if ( !ml->title().isEmpty() )
layer->setLayerName( ml->title() );
}
@@ -792,6 +801,13 @@ QImage* QgsWMSServer::getLegendGraphics()

p.end();

// reset layers' name
foreach ( QString layerId, layerIds )
{
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
ml->setLayerName( layerNameMap[ layerId ] );
}
// clear map layer registry
QgsMapLayerRegistry::instance()->removeAllMapLayers();
return paintImage;
}

0 comments on commit 102cfed

Please sign in to comment.
You can’t perform that action at this time.