Skip to content

Commit

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

Respect custom layer order for groups in GetMap
  • Loading branch information
elpaso authored Apr 29, 2019
2 parents b5741c2 + aa714d3 commit 8131f8c
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
Original file line number Diff line number Diff line change
Expand Up @@ -2496,9 +2496,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
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,50 @@ def test_wms_getmap_group_regression_20810(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_GroupedLayersDown")

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

0 comments on commit 8131f8c

Please sign in to comment.