Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction between the Legend filter and the Layer filter #10241

Closed
1 task done
ElenaGallo opened this issue Apr 23, 2024 · 4 comments · Fixed by #10718
Closed
1 task done

Interaction between the Legend filter and the Layer filter #10241

ElenaGallo opened this issue Apr 23, 2024 · 4 comments · Fixed by #10718

Comments

@ElenaGallo
Copy link
Contributor

ElenaGallo commented Apr 23, 2024

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.

2.mp4

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

  • Not browser related

Acceptance criteria

Other useful information

Related to #10180 (comment)

@tdipisa
Copy link
Member

tdipisa commented Oct 14, 2024

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
Copy link
Contributor

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:

  • BBOX
  • SRS or CRS (depending on the WMS version, SRS for 1.1.1 and CRS for 1.3.0)
  • SRCWIDTH and SRCHEIGHT, the size of the reference map (width and height already have a different meaning in GetLegendGraphic)
  • Content dependent evaluation is enabled via the following LEGEND_OPTIONS parameters:
    • countMatched: adds the number of features matching the particular rule at the end of the rule label (requires visible labels to work). Applicable only to vector layers.
    • hideEmptyRules: hides rules that are not matching any feature. Applicable only if countMatched is true.

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

@ElenaGallo
Copy link
Contributor Author

ElenaGallo commented Jan 9, 2025

When the Interactive legend is enabled and then a filter layer is added, if I disable the filter layer it is no longer possible to filter the legend.

filter.legend.mp4

How to Reproduce

  • Open this map
  • Enable Interactive legend for the layer
  • Create a Filter layer
  • Disable the filter layer
    -> the legend is no longer filterable

@dsuren1
Copy link
Contributor

dsuren1 commented Jan 9, 2025

@ElenaGallo This is the expected behavior. When you disable filter, it disables all the filters (layer and legend) and becomes applicable only when filter is enabled on the layer. This is to maintain consistent behavior

@ElenaGallo ElenaGallo self-assigned this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants