Skip to content
Permalink
Browse files

Update getMap with render context

  • Loading branch information
pblottiere committed Mar 25, 2019
1 parent ec06223 commit 47b4d05283930e147ccac4c7ed791419048b7605
Showing with 21 additions and 58 deletions.
  1. +17 −7 src/server/services/wms/qgswmsgetmap.cpp
  2. +4 −51 src/server/services/wms/qgswmsrenderer.cpp
@@ -28,20 +28,30 @@ namespace QgsWms
{

void writeGetMap( QgsServerInterface *serverIface, const QgsProject *project,
const QString &version, const QgsServerRequest &request,
const QString &, const QgsServerRequest &request,
QgsServerResponse &response )
{
Q_UNUSED( version );
// get wms parameters from query
const QgsWmsParameters parameters( QUrlQuery( request.url() ) );

QgsServerRequest::Parameters params = request.parameters();

QgsWmsParameters wmsParameters( QUrlQuery( request.url() ) );
QgsRenderer renderer( serverIface, project, wmsParameters );
// prepare render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UpdateExtent );
context.setFlag( QgsWmsRenderContext::UseOpacity );
context.setFlag( QgsWmsRenderContext::UseFilter );
context.setFlag( QgsWmsRenderContext::UseSelection );
context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
context.setFlag( QgsWmsRenderContext::AddExternalLayers );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setParameters( parameters );

// rendering
QgsRenderer renderer( context );
std::unique_ptr<QImage> result( renderer.getMap() );

if ( result )
{
QString format = params.value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.imageQuality() );
}
else
@@ -825,59 +825,13 @@ namespace QgsWms
QStringLiteral( "The requested map size is too large" ) );
}

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

// init layer restorer before doing anything
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mNicknameLayers.values() ) );
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

// init stylized layers according to LAYERS/STYLES or SLD
QString sld = mWmsParameters.sldBody();
if ( !sld.isEmpty() )
{
layers = sldStylizedLayers( sld );
}
else
{
layers = stylizedLayers( params );
}

// remove unwanted layers (restricted layers, ...)
removeUnwantedLayers( layers );

// configure each layer with opacity, selection filter, ...
bool updateMapExtent = mWmsParameters.bbox().isEmpty();
for ( QgsMapLayer *layer : layers )
{
checkLayerReadPermissions( layer );

for ( const QgsWmsParametersLayer &param : params )
{
if ( param.mNickname == layerNickname( *layer ) )
{
setLayerOpacity( layer, param.mOpacity );

setLayerFilter( layer, param.mFilter );

setLayerSelection( layer, param.mSelection );

if ( updateMapExtent )
updateExtent( layer, mapSettings );

break;
}
}

setLayerAccessControlFilter( layer );
}

// add external layers
layers = layers << externalLayers( mWmsParameters.externalLayersParameters() );

// add highlight layers above others
layers = layers << highlightLayers( mWmsParameters.highlightLayersParameters() );
// configure layers
QList<QgsMapLayer *> layers = mContext.layersToRender();
configureLayers( layers, &mapSettings );

// create the output image and the painter
std::unique_ptr<QPainter> painter;
@@ -887,7 +841,6 @@ namespace QgsWms
configureMapSettings( image.get(), mapSettings );

// add layers to map settings (revert order for the rendering)
std::reverse( layers.begin(), layers.end() );
mapSettings.setLayers( layers );

// rendering step for layers

0 comments on commit 47b4d05

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