Skip to content

Commit

Permalink
[QGIS-Server][BUGFIX] GetLegendGraphics set layername
Browse files Browse the repository at this point in the history
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 49d864f commit 2f75c3c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/server/qgswmsserver.cpp
Expand Up @@ -672,11 +672,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() );
}
Expand Down Expand Up @@ -808,6 +817,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;
}
Expand Down

0 comments on commit 2f75c3c

Please sign in to comment.