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 ddb37e2 commit 102cfed
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 102cfed

Please sign in to comment.