Skip to content
Permalink
Browse files

Merge pull request #33952 from m-kuhn/server_wms_equal_layer_name

[server] do not drop layers with duplicate names
  • Loading branch information
m-kuhn committed Feb 8, 2020
2 parents c76c390 + 5eb92b5 commit 577e7210db5d57066a5e51a3212f867478bb7cf9
@@ -296,7 +296,7 @@ void QgsWmsRenderContext::initNicknameLayers()
{
for ( QgsMapLayer *ml : mProject->mapLayers() )
{
mNicknameLayers[ layerNickname( *ml ) ] = ml;
mNicknameLayers.insert( layerNickname( *ml ), ml );
}

// init groups
@@ -412,14 +412,15 @@ void QgsWmsRenderContext::searchLayersToRender()

if ( mFlags & AddQueryLayers )
{
const auto constLayers { flattenedQueryLayers() };
for ( const QString &layer : constLayers )
const QStringList queryLayerNames { flattenedQueryLayers() };
for ( const QString &layerName : queryLayerNames )
{
if ( mNicknameLayers.contains( layer )
&& !mLayersToRender.contains( mNicknameLayers[layer] ) )
{
mLayersToRender.append( mNicknameLayers[layer] );
}
const QList<QgsMapLayer *> layers = mNicknameLayers.values( layerName );
for ( QgsMapLayer *lyr : layers )
if ( !mLayersToRender.contains( lyr ) )
{
mLayersToRender.append( lyr );
}
}
}
}
@@ -455,7 +456,7 @@ void QgsWmsRenderContext::searchLayersToRenderSld()
if ( mNicknameLayers.contains( lname ) )
{
mSlds[lname] = namedElem;
mLayersToRender.append( mNicknameLayers[ lname ] );
mLayersToRender.append( mNicknameLayers.values( lname ) );
}
else if ( mLayerGroups.contains( lname ) )
{
@@ -491,7 +492,7 @@ void QgsWmsRenderContext::searchLayersToRenderStyle()
mStyles[nickname] = style;
}

mLayersToRender.append( mNicknameLayers[ nickname ] );
mLayersToRender.append( mNicknameLayers.values( nickname ) );
}
else if ( mLayerGroups.contains( nickname ) )
{
@@ -509,7 +510,7 @@ void QgsWmsRenderContext::searchLayersToRenderStyle()

for ( const auto &name : layersFromGroup )
{
mLayersToRender.append( mNicknameLayers[ name ] );
mLayersToRender.append( mNicknameLayers.values( name ) );
}
}
else
@@ -531,13 +532,16 @@ bool QgsWmsRenderContext::layerScaleVisibility( const QString &name ) const
return visible;
}

const QgsMapLayer *layer = mNicknameLayers[ name ];
bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );

if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
const QList<QgsMapLayer *>layers = mNicknameLayers.values( name );
for ( QgsMapLayer *layer : layers )
{
visible = true;
bool scaleBasedVisibility = layer->hasScaleBasedVisibility();
bool useScaleConstraint = ( scaleDenominator() > 0 && scaleBasedVisibility );

if ( !useScaleConstraint || layer->isInScaleRange( scaleDenominator() ) )
{
visible = true;
}
}

return visible;
@@ -259,7 +259,7 @@ namespace QgsWms
double mScaleDenominator = -1.0;

// nickname of all layers defined within the project
QMap<QString, QgsMapLayer *> mNicknameLayers;
QMultiMap<QString, QgsMapLayer *> mNicknameLayers;

// map of layers to use for rendering
QList<QgsMapLayer *> mLayersToRender;
@@ -1730,6 +1730,28 @@ def test_mode8bit_with_transparency(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Mode_8bit_with_transparency")

def test_multiple_layers_with_equal_name(self):

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(os.path.join(self.testdata_path, 'test_project_wms_duplicate_names.qgz')),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"BBOX": "613402.5658687877003,5809005.018114360981,619594.408781287726,5813869.006602735259",
"CRS": "EPSG:25832",
"WIDTH": "429",
"HEIGHT": "337",
"LAYERS": "layer",
"STYLES": ",",
"FORMAT": "image/png",
"DPI": "200",
"MAP_RESOLUTION": "200",
"FORMAT_OPTIONS": "dpi:200"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_DuplicateNames")


if __name__ == '__main__':
unittest.main()
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 577e721

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