Skip to content

Commit

Permalink
Merge pull request #6792 from mhugent/get_legend_fix_no_layers
Browse files Browse the repository at this point in the history
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 673fafb
Show file tree
Hide file tree
Showing 3 changed files with 3,722 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/qgswmsserver.cpp
Expand Up @@ -762,7 +762,7 @@ QImage* QgsWMSServer::getLegendGraphics()

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

//scale
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/src/python/test_qgsserver.py
Expand Up @@ -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"):
Expand Down

0 comments on commit 673fafb

Please sign in to comment.