Skip to content
Permalink
Browse files

Update getLegendGraphics with render context

  • Loading branch information
pblottiere committed Mar 25, 2019
1 parent 47b4d05 commit 8a46e2ffff929d0e4aef9d53aa31f24fea09f7ad
Showing with 15 additions and 38 deletions.
  1. +9 −15 src/server/services/wms/qgswmsgetlegendgraphics.cpp
  2. +6 −23 src/server/services/wms/qgswmsrenderer.cpp
@@ -26,19 +26,20 @@

namespace QgsWms
{

void writeGetLegendGraphics( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );

QgsServerRequest::Parameters params = request.parameters();
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
// get parameters from query
QgsWmsParameters parameters( QUrlQuery( request.url() ) );

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
// init render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UseScaleDenominator );
context.setParameters( parameters );

// Get cached image
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
QgsAccessControl *accessControl = nullptr;
QgsServerCacheManager *cacheManager = nullptr;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -79,8 +80,7 @@ namespace QgsWms
}
}

QgsRenderer renderer( serverIface, project, wmsParameters );

QgsRenderer renderer( context );
std::unique_ptr<QImage> result( renderer.getLegendGraphics() );

if ( result )
@@ -99,10 +99,4 @@ namespace QgsWms
QStringLiteral( "Failed to compute GetLegendGraphics image" ) );
}
}


} // namespace QgsWms




@@ -163,36 +163,19 @@ namespace QgsWms
throw QgsBadRequestException( QStringLiteral( "FormatNotSpecified" ),
QStringLiteral( "FORMAT is mandatory for GetLegendGraphic operation" ) );

double scaleDenominator = -1;
if ( ! mWmsParameters.scale().isEmpty() )
scaleDenominator = mWmsParameters.scaleAsDouble();

QgsLegendSettings legendSettings = mWmsParameters.legendSettings();

// get layers
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mNicknameLayers.values() ) );

QList<QgsMapLayer *> layers;
QList<QgsWmsParametersLayer> params = mWmsParameters.layersParameters();

QString sld = mWmsParameters.sldBody();
if ( !sld.isEmpty() )
layers = sldStylizedLayers( sld );
else
layers = stylizedLayers( params );

removeUnwantedLayers( layers, scaleDenominator );
std::reverse( layers.begin(), layers.end() );
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// check permissions
for ( QgsMapLayer *ml : layers )
checkLayerReadPermissions( ml );
// configure layers
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers );

// build layer tree model for legend
QgsLayerTree rootGroup;
QgsLegendSettings legendSettings = mContext.parameters().legendSettings();
std::unique_ptr<QgsLayerTreeModel> legendModel;
legendModel.reset( buildLegendTreeModel( layers, scaleDenominator, rootGroup ) );
legendModel.reset( buildLegendTreeModel( layers, mContext.scaleDenominator(), rootGroup ) );

// rendering step
qreal dpmm = dotsPerMm();

0 comments on commit 8a46e2f

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