Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9888 from elpaso/bugfix-21917-server-root-layer-o…
…rder-3_6

Respect custom layer order for groups in GetMap
  • Loading branch information
elpaso committed Apr 27, 2019
2 parents 1e3b83e + 9ddbae6 commit db5bfdc
Show file tree
Hide file tree
Showing 4 changed files with 1,027 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -2790,9 +2790,33 @@ namespace QgsWms
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 );
}
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions tests/src/python/test_qgsserver_wms_getmap.py
Expand Up @@ -1450,6 +1450,50 @@ def test_wms_getmap_datasource_error(self):

self.assertTrue('ServerException' in str(r))

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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit db5bfdc

Please sign in to comment.