Open ElenaGallo opened 6 months ago
On the MS side we can for sure prevent the interactive legend from displaying under certain conditions. In general, on the GS side, it would be good to evaluate a possible enhancement of the GetLegendGraphic handling in JSON format
Standard GLG is filtered only if hideEmptyRules is specified in the request:
https://gs-stable.geo-solutions.it/geoserver/wms?service=WMS&request=GetLegendGraphic&format=image/png&height=50&width=100&layer=gs:us_states&style=pophade&version=1.3.0&SLD_VERSION=1.1.0&LEGEND_OPTIONS=forceLabels:on;hideEmptyRules:true&LANGUAGE=en&SCALE=18489335&CQL_FILTER=("SUB_REGION"='E N Cen' OR "SUB_REGION"='E S Cen' OR "SUB_REGION"='Mid Atl' OR "SUB_REGION"='Mtn')
The JSON legend seems to completely lacking this logic:
https://gs-stable.geo-solutions.it/geoserver/wms?service=WMS&request=GetLegendGraphic&format=application/json&height=50&width=100&layer=gs:us_states&style=pophade&version=1.3.0&SLD_VERSION=1.1.0&LEGEND_OPTIONS=forceLabels:on;hideEmptyRules:true&LANGUAGE=en&SCALE=18489335&CQL_FILTER=("SUB_REGION"='E N Cen' OR "SUB_REGION"='E S Cen' OR "SUB_REGION"='Mid Atl' OR "SUB_REGION"='Mtn')
On the MS side we can for sure prevent the interactive legend from displaying under certain conditions. In general, on the GS side, it would be good to evaluate a possible enhancement of the GetLegendGraphic handling in JSON format
Standard GLG is filtered only if hideEmptyRules is specified in the request:
https://gs-stable.geo-solutions.it/geoserver/wms?service=WMS&request=GetLegendGraphic&format=image/png&height=50&width=100&layer=gs:us_states&style=pophade&version=1.3.0&SLD_VERSION=1.1.0&LEGEND_OPTIONS=forceLabels:on;hideEmptyRules:true&LANGUAGE=en&SCALE=18489335&CQL_FILTER=("SUB_REGION"='E N Cen' OR "SUB_REGION"='E S Cen' OR "SUB_REGION"='Mid Atl' OR "SUB_REGION"='Mtn')
The JSON legend seems to completely lacking this logic:
https://gs-stable.geo-solutions.it/geoserver/wms?service=WMS&request=GetLegendGraphic&format=application/json&height=50&width=100&layer=gs:us_states&style=pophade&version=1.3.0&SLD_VERSION=1.1.0&LEGEND_OPTIONS=forceLabels:on;hideEmptyRules:true&LANGUAGE=en&SCALE=18489335&CQL_FILTER=("SUB_REGION"='E N Cen' OR "SUB_REGION"='E S Cen' OR "SUB_REGION"='Mid Atl' OR "SUB_REGION"='Mtn')
After an additional investigation it seems possible to filter rules in a legend but all the following parameters must be included in the GetLegend graphic request:
After testing, hideEmptyRules works also if the countMatched is not present in the request. Here a working example:
https://gs-stable.geo-solutions.it/geoserver/wms?service=WMS&request=GetLegendGraphic&format=image%2Fpng&height=50&width=100&layer=gs%3Aus_states&style=pophade&version=1.3.0&SLD_VERSION=1.1.0&LEGEND_OPTIONS=hideEmptyRules:true;forceLabels%3Aon&LANGUAGE=en&SCALE=231116&SRS=EPSG%3A3857&CRS=EPSG%3A3857&SRCWIDTH=512&SRCHEIGHT=512&BBOX=-8453323.832114212%2C4696291.017841227%2C-8140237.76425813%2C5009377.085697309&CQL_FILTER=(%22SUB_REGION%22%3D%27E%20N%20Cen%27%20OR%20%22SUB_REGION%22%3D%27E%20S%20Cen%27%20OR%20%22SUB_REGION%22%3D%27Mid%20Atl%27%20OR%20%22SUB_REGION%22%3D%27Mtn%27)
Map
Legend
Description
It should be possible in GS to filter the JSON legend according to the general filter defined in 'Layer filter' because now when there is an attribute filter for the layer and the interactive legend is enabled, the interactive legend does not work as expected.
https://github.com/geosolutions-it/MapStore2/assets/56537133/361e52af-1bfd-4d27-ad26-1502a2572f0f
How to reproduce
Open this map
Click on Filter Layer
Set the Attribute Filter
Click on Settings layer
From Display tab, set Enable interactive legend
Click on X
Open the layer Legend
[x] Not browser related
Browser info
(use this site: https://www.whatsmybrowser.org/ for non expert users) | Browser Affected | Version | |---|---| |Internet Explorer| | |Edge| | |Chrome| | |Firefox| | |Safari| |Other useful information
Related to https://github.com/geosolutions-it/MapStore2/pull/10180#issuecomment-2071968824