geosolutions-it / MapStore2

The solution to create and share maps, dashboards, geostories with 3D support on the web. And it is open-source too!
https://mapstore.geosolutionsgroup.com/
Other
511 stars 398 forks source link

Interaction between the Legend filter and the Layer filter #10241

Open ElenaGallo opened 6 months ago

ElenaGallo commented 6 months ago

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

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

tdipisa commented 3 weeks 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')

allyoucanmap commented 2 weeks 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')

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 Map

Legend Legend