Skip to content

Commit

Permalink
Server getLegendGraphic default WIDTH/HEIGHT when BBOX
Browse files Browse the repository at this point in the history
is set.

Fixes #31846
  • Loading branch information
elpaso committed Sep 17, 2019
1 parent 27b576c commit 5b33600
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/server/services/wms/qgswmsgetlegendgraphics.cpp
Expand Up @@ -128,7 +128,7 @@ namespace QgsWms
}
}

void checkParameters( const QgsWmsParameters &parameters )
void checkParameters( QgsWmsParameters &parameters )
{
if ( parameters.allLayersNickname().isEmpty() )
{
Expand All @@ -153,11 +153,25 @@ namespace QgsWms
throw QgsBadRequestException( QgsServiceException::QGIS_InvalidParameterValue,
parameters[QgsWmsParameter::BBOX] );
}
// If we have a contextual legend (BBOX is set)
// make sure WIDTH and HEIGHT are > 0, default to 800x600
if ( ! parameters.bbox().isEmpty() )
{
if ( parameters.width().isEmpty() )
{
parameters.set( QgsWmsParameter::WIDTH, 800 );
}
if ( parameters.height().isEmpty() )
{
parameters.set( QgsWmsParameter::HEIGHT, 600 );
}
}
}

QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree )
{
const QgsWmsParameters parameters = context.parameters();

QgsWmsParameters parameters = context.parameters();
std::unique_ptr<QgsLayerTreeModel> model( new QgsLayerTreeModel( &tree ) );

if ( context.scaleDenominator() > 0 )
Expand All @@ -170,7 +184,6 @@ namespace QgsWms
{
QgsRenderer renderer( context );
const QgsRenderer::HitTest symbols = renderer.symbols();

for ( QgsLayerTreeNode *node : tree.children() )
{
QgsLayerTreeLayer *layer = QgsLayerTree::toLayer( node );
Expand Down
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsgetlegendgraphics.h
Expand Up @@ -32,7 +32,7 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response );

void checkParameters( const QgsWmsParameters &parameters );
void checkParameters( QgsWmsParameters &parameters );

QgsLayerTreeModel *legendModel( const QgsWmsRenderContext &context, QgsLayerTree &tree );

Expand Down
19 changes: 19 additions & 0 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Expand Up @@ -804,6 +804,25 @@ def test_wms_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR_hex(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR", max_size_diff=QSize(10, 2))

def test_BBoxNoWidthNoHeight(self):
"""Test with BBOX and no width/height (like QGIS client does)"""

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_wms_grouped_nested_layers.qgs',
"SERVICE": "WMS",
"VERSION": "1.3",
"REQUEST": "GetLegendGraphic",
"LAYER": "areas%20and%20symbols",
"FORMAT": "image/png",
"CRS": "EPSG:4326",
"BBOX": "52.44462990911360123,10.6723591605239374,52.44631832182876963,10.6795952150175264",
"SLD_VERSION": "1.1",
}.items())])

r, h = self._result(self._execute_request(qs))
self.assertFalse(b'Exception' in r)
self._img_diff_error(r, h, "WMS_GetLegendGraphic_NoWidthNoHeight", max_size_diff=QSize(10, 2))


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.
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 5b33600

Please sign in to comment.