Skip to content
Permalink
Browse files

Merge pull request #6792 from mhugent/get_legend_fix_no_layers

2.18 Server: return empty image in GetLegendGraphis if no layer is there
  • Loading branch information
mhugent committed Apr 17, 2018
2 parents 73f7bd3 + c217cbb commit 673fafb04b54ee4fb5efe2d6b6dd8466feedd641
@@ -762,7 +762,7 @@ QImage* QgsWMSServer::getLegendGraphics()

if ( layersList.size() < 1 )
{
return nullptr;
return createImage( 1, 1, false );
}

//scale
@@ -782,7 +782,7 @@ QImage* QgsWMSServer::getLegendGraphics()
QStringList layerIds = mConfigParser->layerSet( layersList, stylesList, dummyCRS, scaleDenominator );
if ( layerIds.size() < 1 )
{
return nullptr;
return createImage( 1, 1, false );
}

//get icon size, spaces between legend items and font from config parser
@@ -893,6 +893,25 @@ def test_wms_GetLegendGraphic_BBox2(self):
r, h = self._result(self.server.handleRequest(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")

def test_wms_GetLegendGraphic_EmptyLegend(self):
mapPath = self.testdata_path + 'test_project_contextual_legend.qgs'
qs = "&".join(["%s=%s" % i for i in list({
"MAP": urllib.quote(mapPath),
"SERVICE": "WMS",
"VERSION": "1.3.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "QGIS%20Server%20Hello%20World",
"FORMAT": "image/png",
"HEIGHT": "840",
"WIDTH": "1226",
"BBOX": "10.38450,-49.6370,73.8183,42.9461",
"SRS": "EPSG:4326",
"SCALE": "15466642"
}.items())])

r, h = self._result(self.server.handleRequest(qs) )
self.assertTrue( h['Content-Type'] == 'image/png' )

def _result(self, data):
headers = {}
for line in data[0].decode('UTF-8').split("\n"):

0 comments on commit 673fafb

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