Skip to content
Permalink
Browse files

Merge pull request #5396 from mhugent/server_wms_print_layers

Server wms print layers
  • Loading branch information
mhugent committed Oct 24, 2017
2 parents bb21395 + c993888 commit 628a60be273d72b69eefe6fc91ed5c143e8d2fa7
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgswmsparameters.h"
#include "qgsdatasourceuri.h"
#include "qgsmessagelog.h"
#include <iostream>

@@ -512,6 +513,16 @@ namespace QgsWms
raiseError( name );
}
}
else //maybe an external wms parameter?
{
int separator = key.indexOf( ":" );
if ( separator >= 1 )
{
QString id = key.left( separator );
QString param = key.right( key.length() - separator - 1 );
mExternalWMSParameters[id].insert( param, parameters[key] );
}
}
}
}
}
@@ -1880,6 +1891,23 @@ namespace QgsWms
return param;
}

QString QgsWmsParameters::externalWMSUri( const QString &id ) const
{
if ( !mExternalWMSParameters.contains( id ) )
{
return QString();
}

QgsDataSourceUri wmsUri;
const QMap<QString, QString> &paramMap = mExternalWMSParameters[ id ];
QMap<QString, QString>::const_iterator paramIt = paramMap.constBegin();
for ( ; paramIt != paramMap.constEnd(); ++paramIt )
{
wmsUri.setParam( paramIt.key().toLower(), paramIt.value() );
}
return wmsUri.encodedUri();
}

QString QgsWmsParameters::name( ParameterName name ) const
{
const QMetaEnum metaEnum( QMetaEnum::fromType<ParameterName>() );
@@ -909,6 +909,13 @@ namespace QgsWms
*/
QgsWmsParametersComposerMap composerMapParameters( int mapId ) const;

/**
* @brief externalWMSUri
* @param id the id of the external wms
* @return uri string or an empty string if the external wms id does not exist
*/
QString externalWMSUri( const QString &id ) const;

private:
QString name( ParameterName name ) const;
void raiseError( ParameterName name ) const;
@@ -955,6 +962,7 @@ namespace QgsWms
QgsServerRequest::Parameters mRequestParameters;
QMap<ParameterName, Parameter> mParameters;
QMap<int, QMap<ParameterName, Parameter>> mComposerParameters;
QMap<QString, QMap<QString, QString> > mExternalWMSParameters;
QList<QgsProjectVersion> mVersions;
};
}
@@ -132,6 +132,11 @@ namespace QgsWms
initNicknameLayers();
}

QgsRenderer::~QgsRenderer()
{
removeTemporaryLayers();
}


QImage *QgsRenderer::getLegendGraphics()
{
@@ -2557,6 +2562,7 @@ namespace QgsWms
}
}

mTemporaryLayers.append( highlightLayers );
return highlightLayers;
}

@@ -2602,15 +2608,27 @@ namespace QgsWms
return layers;
}

QList<QgsMapLayer *> QgsRenderer::stylizedLayers( const QList<QgsWmsParametersLayer> &params ) const
QList<QgsMapLayer *> QgsRenderer::stylizedLayers( const QList<QgsWmsParametersLayer> &params )
{
QList<QgsMapLayer *> layers;

Q_FOREACH ( QgsWmsParametersLayer param, params )
{
QString nickname = param.mNickname;
QString style = param.mStyle;
if ( mNicknameLayers.contains( nickname ) && !mRestrictedLayers.contains( nickname ) )
if ( nickname.startsWith( "EXTERNAL_WMS:" ) )
{
QString externalLayerId = nickname;
externalLayerId.remove( 0, 13 );
QgsMapLayer *externalWMSLayer = createExternalWMSLayer( externalLayerId );
if ( externalWMSLayer )
{
layers.append( externalWMSLayer );
mNicknameLayers[nickname] = externalWMSLayer; //might be used later in GetPrint request
mTemporaryLayers.append( externalWMSLayer );
}
}
else if ( mNicknameLayers.contains( nickname ) && !mRestrictedLayers.contains( nickname ) )
{
if ( !style.isEmpty() )
{
@@ -2633,6 +2651,25 @@ namespace QgsWms
return layers;
}

QgsMapLayer *QgsRenderer::createExternalWMSLayer( const QString &externalLayerId ) const
{
QString wmsUri = mWmsParameters.externalWMSUri( externalLayerId.toUpper() );
QgsMapLayer *wmsLayer = new QgsRasterLayer( wmsUri, externalLayerId, QStringLiteral( "wms" ) );
if ( !wmsLayer->isValid() )
{
delete wmsLayer;
return 0;
}

return wmsLayer;
}

void QgsRenderer::removeTemporaryLayers()
{
qDeleteAll( mTemporaryLayers );
mTemporaryLayers.clear();
}

QPainter *QgsRenderer::layersRendering( const QgsMapSettings &mapSettings, QImage &image, HitTest *hitTest ) const
{
QPainter *painter = nullptr;
@@ -84,6 +84,8 @@ namespace QgsWms
const QgsProject *project,
const QgsServerRequest::Parameters &parameters );

~QgsRenderer();

/**
* Returns the map legend as an image (or a null pointer in case of error). The caller takes ownership
of the image object*/
@@ -154,7 +156,7 @@ namespace QgsWms
void annotationsRendering( QPainter *painter ) const;

// Return a list of layers stylized with LAYERS/STYLES parameters
QList<QgsMapLayer *> stylizedLayers( const QList<QgsWmsParametersLayer> &params ) const;
QList<QgsMapLayer *> stylizedLayers( const QList<QgsWmsParametersLayer> &params );

// Return a list of layers stylized with SLD parameter
QList<QgsMapLayer *> sldStylizedLayers( const QString &sld ) const;
@@ -274,6 +276,11 @@ namespace QgsWms
//! configure the composition for the GetPrint request
bool configureComposition( QgsComposition *c, const QgsMapSettings &mapSettings );

//! Creates external WMS layer. Caller takes ownership
QgsMapLayer *createExternalWMSLayer( const QString &externalLayerId ) const;

void removeTemporaryLayers();

private:

const QgsServerRequest::Parameters &mParameters;
@@ -286,6 +293,7 @@ namespace QgsWms
QgsWmsParameters mWmsParameters;
QStringList mRestrictedLayers;
QMap<QString, QgsMapLayer *> mNicknameLayers;
QList<QgsMapLayer *> mTemporaryLayers;

public:

0 comments on commit 628a60b

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