Bug report #17282
Legend image for root group of WMS service
|Category:||Web Services clients/WMS|
|Affected QGIS version:||2.18.13||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:|
|Crashes QGIS or corrupts data:||No|
If open root group of WMS service then legend image only for one layer will be displayed at table of contents.
#2 Updated by Richard Duivenvoorde 10 months ago
I had a look into this, and the crux is that selecting the 'root' of the layer tree is interpreted by QGIS as requesting the layer width the 'default' style (that is: in the url you send you get an empty 'style' parameter: ...&STYLES=&LAYERS=...
BUT according to the OGC WMS spec:
"If only a single style is available, that style is known as the “default” style"...
"If the server advertises several styles for a layer, and the client sends a request for the default style, the choice of
which style to use as default is at the discretion of the server. The ordering of styles in the service metadata does
not indicate which is the default."
And caveat: from the capabilities document of a WMS you can not make up WHAT the default style is in case there are more styles available. Another problem: there could be more styles available then advertized, as the style is actually cascading...
So in the code of QGIS
you only get a valid legend url when:
1) there is just ONE style available (of which QGIS then rightfully concludes that THAT is the default style)
2) you request one of the named styles
3) (QGIS special): if you name one of the styles as 'default'
So in this case we cannot do anything (I think). Picking the first style for the legend in case of more style could be wrong (as it is not defined as the default style). So I think QGIS does what it can do.
IF you are managing the WMS yourself, you could name the style 'default', but you get into trouble off course when you have more several layers for which you want do define different 'defaults'.
IF there would be a OGC WMS 1.3.1 it would be nice if one of the styles would be advertised as 'default'.