Skip to content
Permalink
Browse files

[server] Respect custom layer order for groups in GetMap

Fixes #21917
  • Loading branch information
elpaso committed Apr 26, 2019
1 parent c0105bd commit 956ed06f5222df208d1d37092916c9014c5cb419
@@ -300,9 +300,33 @@ void QgsWmsRenderContext::initLayerGroupsRecursive( const QgsLayerTreeGroup *gro
if ( !groupName.isEmpty() )
{
mLayerGroups[groupName] = QList<QgsMapLayer *>();
for ( QgsLayerTreeLayer *layer : group->findLayers() )
const auto projectLayerTreeRoot { mProject->layerTreeRoot() };
const auto treeGroupLayers { group->findLayers() };
// Fast track if there is no custom layer order,
// otherwise reorder layers.
if ( ! projectLayerTreeRoot->hasCustomLayerOrder() )
{
mLayerGroups[groupName].append( layer->layer() );
for ( const auto &tl : treeGroupLayers )
{
mLayerGroups[groupName].push_back( tl->layer() );
}
}
else
{
const auto projectLayerOrder { projectLayerTreeRoot->layerOrder() };
// Flat list containing the layers from the tree nodes
QList<QgsMapLayer *> groupLayersList;
for ( const auto &tl : treeGroupLayers )
{
groupLayersList << tl->layer();
}
for ( const auto &l : projectLayerOrder )
{
if ( groupLayersList.contains( l ) )
{
mLayerGroups[groupName].push_back( l );
}
}
}
}

@@ -1516,6 +1516,50 @@ def test_wms_getmap_external(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_External", 20000)

def test_wms_getmap_root_custom_layer_order_regression_21917(self):
"""When drawing root layer, custom layer order order should be respected."""

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(os.path.join(self.testdata_path, 'bug_21917_root_layer_order.qgs')),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"BBOX": "44.9014,8.20346,44.9015,8.20355",
"CRS": "EPSG:4326",
"WIDTH": "400",
"HEIGHT": "400",
"LAYERS": "group",
"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_Group_Layer_Order")

# Check with root_layer
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(os.path.join(self.testdata_path, 'bug_21917_root_layer_order.qgs')),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"BBOX": "44.9014,8.20346,44.9015,8.20355",
"CRS": "EPSG:4326",
"WIDTH": "400",
"HEIGHT": "400",
"LAYERS": "root_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_Group_Layer_Order")


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

0 comments on commit 956ed06

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