From 40201b2ef5cd6a1df55fc266566b734ce54c0702 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Tue, 17 Oct 2017 12:00:04 +0200 Subject: [PATCH] Support external WMS layers in GetPrint and GetMap requests --- src/server/services/wms/qgswmsrenderer.cpp | 41 +++++++++++++++++++++- src/server/services/wms/qgswmsrenderer.h | 3 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index 14a13171f80..50151aecc31 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -2610,7 +2610,17 @@ namespace QgsWms { 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 ); + } + } + else if ( mNicknameLayers.contains( nickname ) && !mRestrictedLayers.contains( nickname ) ) { if ( !style.isEmpty() ) { @@ -2633,6 +2643,35 @@ namespace QgsWms return layers; } + QgsMapLayer *QgsRenderer::createExternalWMSLayer( const QString &externalLayerId ) const + { + QgsMapLayer *wmsLayer = 0; + QgsDataSourceUri wmsUri; + + QgsServerRequest::Parameters::const_iterator it = mParameters.lowerBound( externalLayerId.toUpper() + ":" ); + while ( it != mParameters.constEnd() ) + { + if ( !it.key().startsWith( externalLayerId.toUpper() + ":" ) ) + { + break; + } + + QString paramKey = it.key(); + paramKey.remove( 0, externalLayerId.size() + 1 ); + wmsUri.setParam( paramKey.toLower(), it.value() ); + ++it; + } + + wmsLayer = new QgsRasterLayer( wmsUri.encodedUri(), externalLayerId, QStringLiteral( "wms" ) ); + if ( !wmsLayer->isValid() ) + { + delete wmsLayer; + return 0; + } + + return wmsLayer; + } + QPainter *QgsRenderer::layersRendering( const QgsMapSettings &mapSettings, QImage &image, HitTest *hitTest ) const { QPainter *painter = nullptr; diff --git a/src/server/services/wms/qgswmsrenderer.h b/src/server/services/wms/qgswmsrenderer.h index afedb9a76a2..da414f889b4 100644 --- a/src/server/services/wms/qgswmsrenderer.h +++ b/src/server/services/wms/qgswmsrenderer.h @@ -274,6 +274,9 @@ 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; + private: const QgsServerRequest::Parameters &mParameters;