Skip to content
Permalink
Browse files

Merge pull request #39673 from elpaso/server-wms-getlegendgraphics-js…

…on-symbolscale

Server wms getlegendgraphics json symbolscale
  • Loading branch information
elpaso committed Oct 29, 2020
2 parents 1132494 + dabcf7f commit bda2e100e8d1724f520ceba9e3efb8b2fec3b390
@@ -716,6 +716,15 @@ QJsonObject QgsSymbolLegendNode::exportSymbolToJson( const QgsLegendSettings &se

QJsonObject json;
json[ QStringLiteral( "icon" ) ] = base64;
if ( mItem.scaleMaxDenom() > 0 )
{
json[ QStringLiteral( "scaleMaxDenom" ) ] = mItem.scaleMaxDenom();
}
if ( mItem.scaleMinDenom() > 0 )
{
json[ QStringLiteral( "scaleMinDenom" ) ] = mItem.scaleMinDenom();
}
mItem.scaleMaxDenom();
return json;
}

@@ -20,6 +20,7 @@
os.environ['QT_HASH_SEED'] = '1'

import re
import json
import urllib.request
import urllib.parse
import urllib.error
@@ -30,7 +31,19 @@
import osgeo.gdal # NOQA

from test_qgsserver_wms import TestQgsServerWMSTestBase
from qgis.core import QgsProject
from qgis.core import (
QgsProject,
QgsMarkerSymbol,
QgsRuleBasedRenderer,
QgsVectorLayer,
)

from qgis.server import (
QgsBufferServerRequest,
QgsBufferServerResponse,
QgsServer,
QgsServerRequest,
)

# Strip path and content length because path may vary
RE_STRIP_UNCHECKABLE = br'MAP=[^"]+|Content-Length: \d+'
@@ -1002,6 +1015,36 @@ def test_wms_GetLegendGraphic_JSON_multiple_layers(self):
"&FORMAT=application/json",
"wms_getlegendgraphic_json_multiple_layers")

def testJsonSymbolMaxMinScale(self):
"""Test min/max scale in symbol json export"""

project = QgsProject()
layer = QgsVectorLayer("Point?field=fldtxt:string",
"layer1", "memory")

symbol = QgsMarkerSymbol.createSimple(
{'name': 'square', 'color': 'red'})

scale_min = 10000
scale_max = 1000
rule = QgsRuleBasedRenderer.Rule(symbol, scale_min, scale_max, '')
rootrule = QgsRuleBasedRenderer.Rule(None)
rootrule.appendChild(rule)
layer.setRenderer(QgsRuleBasedRenderer(rootrule))

project.addMapLayers([layer])

server = QgsServer()
request = QgsBufferServerRequest("/?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetLegendGraphic" +
"&LAYERS=layer1" +
"&FORMAT=application/json")
response = QgsBufferServerResponse()
server.handleRequest(request, response, project)
j = json.loads(bytes(response.body()))
node = j['nodes'][0]
self.assertEqual(node['scaleMaxDenom'], 1000)
self.assertEqual(node['scaleMinDenom'], 10000)


if __name__ == '__main__':
unittest.main()

0 comments on commit bda2e10

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