Skip to content

Commit 207c15d

Browse files
committedJan 16, 2019
[server] Fix layer order rendering when layers are in groups (#8796)
Cherry-picked from master 1ba6b97
1 parent 5ff59ce commit 207c15d

File tree

10 files changed

+2001
-26
lines changed

10 files changed

+2001
-26
lines changed
 

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,8 @@ namespace QgsWms
27272727
}
27282728
else if ( mLayerGroups.contains( nickname ) )
27292729
{
2730+
// Reverse order of layers from a group
2731+
QList<QgsMapLayer *> layersFromGroup;
27302732
for ( QgsMapLayer *layer : mLayerGroups[nickname] )
27312733
{
27322734
if ( !mRestrictedLayers.contains( layerNickname( *layer ) ) )
@@ -2739,9 +2741,10 @@ namespace QgsWms
27392741
throw QgsMapServiceException( QStringLiteral( "StyleNotDefined" ), QStringLiteral( "Style \"%1\" does not exist for layer \"%2\"" ).arg( style, layerNickname( *layer ) ) );
27402742
}
27412743
}
2742-
layers.insert( 0, layer );
2744+
layersFromGroup.push_front( layer );
27432745
}
27442746
}
2747+
layers.append( layersFromGroup );
27452748
}
27462749
else
27472750
{

‎tests/src/python/test_qgsserver.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
184184
control.setSizeTolerance(max_size_diff.width(), max_size_diff.height())
185185
return control.compareImages(control_image, max_diff), control.report()
186186

187-
def _img_diff_error(self, response, headers, image, max_diff=100, max_size_diff=QSize()):
187+
def _img_diff_error(self, response, headers, image, max_diff=100, max_size_diff=QSize(), unittest_data_path='control_images'):
188+
189+
reference_path = unitTestDataPath(unittest_data_path) + '/qgis_server/' + image + '/' + image + '.png'
190+
self.store_reference(reference_path, response)
191+
188192
self.assertEqual(
189193
headers.get("Content-Type"), "image/png",
190194
"Content type is wrong: %s\n%s" % (headers.get("Content-Type"), response))

‎tests/src/python/test_qgsserver_accesscontrol.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,27 +217,9 @@ def _img_diff(self, image, control_image, max_diff, max_size_diff=QSize()):
217217
return control.compareImages(control_image), control.report()
218218

219219
def _img_diff_error(self, response, headers, image, max_diff=10, max_size_diff=QSize()):
220-
self.assertEqual(
221-
headers.get("Content-Type"), "image/png",
222-
"Content type is wrong: %s" % headers.get("Content-Type"))
223-
224-
test, report = self._img_diff(response, image, max_diff, max_size_diff)
225-
226-
with open(os.path.join(tempfile.gettempdir(), image + "_result.png"), "rb") as rendered_file:
227-
encoded_rendered_file = base64.b64encode(rendered_file.read())
228-
message = "Image is wrong\n%s\nImage:\necho '%s' | base64 -d >%s/%s_result.png" % (
229-
report, encoded_rendered_file.strip().decode('utf8'), tempfile.gettempdir(), image
230-
)
231-
232-
# If the failure is in image sizes the diff file will not exists.
233-
if os.path.exists(os.path.join(tempfile.gettempdir(), image + "_result_diff.png")):
234-
with open(os.path.join(tempfile.gettempdir(), image + "_result_diff.png"), "rb") as diff_file:
235-
encoded_diff_file = base64.b64encode(diff_file.read())
236-
message += "\nDiff:\necho '%s' | base64 -d > %s/%s_result_diff.png" % (
237-
encoded_diff_file.strip().decode('utf8'), tempfile.gettempdir(), image
238-
)
239-
240-
self.assertTrue(test, message)
220+
super()._img_diff_error(response, headers, image, max_diff=max_diff,
221+
max_size_diff=max_size_diff,
222+
unittest_data_path='qgis_server_accesscontrol')
241223

242224
def _geo_img_diff(self, image_1, image_2):
243225
if os.name == 'nt':

‎tests/src/python/test_qgsserver_accesscontrol_wms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_wms_getmap_grp(self):
213213
"SERVICE": "WMS",
214214
"VERSION": "1.1.1",
215215
"REQUEST": "GetMap",
216-
"LAYERS": "Hello_grp,Country_grp",
216+
"LAYERS": "Country_grp,Hello_grp",
217217
"STYLES": "",
218218
"FORMAT": "image/png",
219219
"BBOX": "-16817707,-6318936.5,5696513,16195283.5",

‎tests/src/python/test_qgsserver_wms_getmap.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141

4242

4343
class TestQgsServerWMSGetMap(QgsServerTestBase):
44-
4544
"""QGIS Server WMS Tests for GetMap request"""
4645

46+
#regenerate_reference = True
47+
4748
def test_wms_getmap_basic_mode(self):
4849
# 1 bits
4950
qs = "?" + "&".join(["%s=%s" % i for i in list({
@@ -355,7 +356,7 @@ def test_wms_getmap_invalid_parameters(self):
355356
err = b"cannot be converted into a rectangle" in r
356357
self.assertTrue(err)
357358

358-
# opacities should be a list of int
359+
# opacities should be a list of int
359360
qs = "?" + "&".join(["%s=%s" % i for i in list({
360361
"MAP": urllib.parse.quote(self.projectPath),
361362
"SERVICE": "WMS",
@@ -1330,6 +1331,50 @@ def test_wms_getmap_group(self):
13301331
r_group_sld, _ = self._result(self._execute_request(qs))
13311332
self.assertEqual(r_individual, r_group_sld, 'Individual layers query and SLD group layers query results should be identical')
13321333

1334+
def test_wms_getmap_group_regression_20810(self):
1335+
"""A WMS shall render the requested layers by drawing the leftmost in the list
1336+
bottommost, the next one over that, and so on. Even if the layers are inside groups."""
1337+
1338+
qs = "?" + "&".join(["%s=%s" % i for i in list({
1339+
"MAP": urllib.parse.quote(os.path.join(self.testdata_path, 'test_project_wms_grouped_layers.qgs')),
1340+
"SERVICE": "WMS",
1341+
"VERSION": "1.3.0",
1342+
"REQUEST": "GetMap",
1343+
"BBOX": "613402.5658687877003,5809005.018114360981,619594.408781287726,5813869.006602735259",
1344+
"CRS": "EPSG:25832",
1345+
"WIDTH": "429",
1346+
"HEIGHT": "337",
1347+
"LAYERS": "osm,areas and symbols",
1348+
"STYLES": ",",
1349+
"FORMAT": "image/png",
1350+
"DPI": "200",
1351+
"MAP_RESOLUTION": "200",
1352+
"FORMAT_OPTIONS": "dpi:200"
1353+
}.items())])
1354+
1355+
r, h = self._result(self._execute_request(qs))
1356+
self._img_diff_error(r, h, "WMS_GetMap_GroupedLayersUp")
1357+
1358+
qs = "?" + "&".join(["%s=%s" % i for i in list({
1359+
"MAP": urllib.parse.quote(os.path.join(self.testdata_path, 'test_project_wms_grouped_layers.qgs')),
1360+
"SERVICE": "WMS",
1361+
"VERSION": "1.3.0",
1362+
"REQUEST": "GetMap",
1363+
"BBOX": "613402.5658687877003,5809005.018114360981,619594.408781287726,5813869.006602735259",
1364+
"CRS": "EPSG:25832",
1365+
"WIDTH": "429",
1366+
"HEIGHT": "337",
1367+
"LAYERS": "areas and symbols,osm",
1368+
"STYLES": ",",
1369+
"FORMAT": "image/png",
1370+
"DPI": "200",
1371+
"MAP_RESOLUTION": "200",
1372+
"FORMAT_OPTIONS": "dpi:200"
1373+
}.items())])
1374+
1375+
r, h = self._result(self._execute_request(qs))
1376+
self._img_diff_error(r, h, "WMS_GetMap_GroupedLayersDown")
1377+
13331378

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

‎tests/testdata/qgis_server/test_project_wms_grouped_layers.qgs

Lines changed: 1941 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.