<div dir="ltr"><div>Hi group,<div><br></div><div>I have a problem with GetLegendGraphic, it ignores the STYLE-parameter in a specific situation.</div><div><br></div><div>1. We have layer groups (GROUP keyword)</div><div>2. We have multiple styles in a WMS service</div><div>3. We have a default WMS style, by using the CLASSGROUP keyword</div><div><br></div><div>the above is a common situation for our INSPIRE view services.<br></div><div>In this setup GetLegendGraphic ignores the STYLE parameter and always uses the style set by the CLASSGROUP in the mapfile.</div>See examples below.<br><br></div>I guess this is a bug or missing feature? Or are we doing something wrong in the mapfile? If it is a bug, do you want me to create an issue?<br><div><div><br></div><div>Thanks,</div><div>Erik Gustafson<br></div><div><br></div><div><br></div><div>Request examples:</div><div>mapserv?map=map.map&SERVICE=WM<wbr>S&VERSION=1.3.0&REQUEST=getleg<wbr>endgraphic&layer=GROUPNAME&<wbr>format=image/png&sld_version=<wbr>1.1.0&STYLE=DEFAULT</div><div>> Ok. <br></div><div><br></div><div>mapserv?map=map.map&SERVICE=WM<wbr>S&VERSION=1.3.0&REQUEST=getleg<wbr>endgraphic&layer=GROUPNAME&<wbr>format=image/png&sld_version=<wbr>1.1.0&STYLE=ALTERNATE</div><div>> Not Ok. Expected STYLE=ALTERNATE from the classes named CLASS2 but got STYLE=DEFAULT, the classes named CLASS1<br></div><div><br></div><div>Example mapfile:</div><div>MAP<br>  WEB<br>    METADATA<br>      "wms_enable_request" "*"<br>    END<br>  END<br><br> LAYER<br>  GROUP "GROUPNAME"<br>  NAME  "LAYER1"<br>  CLASSGROUP "DEFAULT"<br><br>  TYPE POLYGON<br>  STATUS ON<br><br>  CLASS<br>    NAME 'CLASS1'<br>    GROUP "DEFAULT"<br>    STYLE<br>      COLOR 0 0 255<br>    END<br>  END<br><br>  CLASS<br>    NAME 'CLASS2'<br>    GROUP "ALTERNATE"<br>    STYLE<br>      COLOR 255 0 0<br>      WIDTH 0.4<br>    END<br>  END<br>END<br><br> LAYER<br>  GROUP "GROUPNAME"<br>  DEBUG 0<br>  NAME  "LAYER2"<br>  CLASSGROUP "DEFAULT"<br><br>  TYPE POLYGON<br>  STATUS ON<br><br>  CLASS<br>    NAME 'CLASS1'<br>    GROUP "DEFAULT"<br>    STYLE<br>      OUTLINECOLOR 0 0 255<br>      WIDTH 0.4<br>    END<br>  END<br><br>  CLASS<br>    NAME 'CLASS2'<br>    GROUP "ALTERNATE"<br>    STYLE<br>      OUTLINECOLOR 255 0 0<br>      WIDTH 0.4<br>    END<br>  END<br>END<br>END<br></div><div> </div><div>Currently we use a modified mapwms.c to work around this, which works for us but maybe breaks other functionality.</div><div>diff --git a/mapwms.c b/mapwms.c<br>index 1b09109..077f596 100644<br>--- a/mapwms.c<br>+++ b/mapwms.c<br>@@ -4428,6 +4428,20 @@ int msWMSLegendGraphic(mapObj *map, int nVersion, char **names,<br>         nLayers++;<br>         lp->status = MS_ON;<br>         iLayerIndex = i;<br>+<br>+       // set classgroup if a STYLE is requested<br>+        if (pszStyle && strlen(pszStyle) > 0 && strcasecmp(pszStyle, "default") != 0) {<br>+             for (j=0; j<GET_LAYER(map, iLayerIndex)->numclasses; j++) {<br>+               if (GET_LAYER(map, iLayerIndex)->class[j]->group &&<br>+                   strcasecmp(GET_LAYER(map, iLayerIndex)->class[j]->group, pszStyle) == 0) {<br>+                  msFree(GET_LAYER(map, iLayerIndex)->classgroup);<br>+                 GET_LAYER(map, iLayerIndex)->classgroup = msStrdup(pszStyle);<br>+                 break;<br>+               }<br>+             }<br>+<br>+       }<br>+<br>         if (GET_LAYER(map, i)->connectiontype == MS_WMS) {<br>           /* we do not cascade a wms layer if it contains at least<br>            * one class with the property name set */<br>@@ -4485,7 +4499,7 @@ this request. Check wms/ows_enable_request settings.",<br>     /*if STYLE is set, check if it is a valid style (valid = at least one<br>     of the classes have a the group value equals to the style */<br>     /*style is only validated when there is only one layer #3411*/<br>-    if (nLayers == 1 &&  pszStyle && strlen(pszStyle) > 0 && strcasecmp(pszStyle, "default") != 0) {<br>+    if (pszStyle && strlen(pszStyle) > 0 && strcasecmp(pszStyle, "default") != 0) {<br>       for (i=0; i<GET_LAYER(map, iLayerIndex)->numclasses; i++) {<br>         if (GET_LAYER(map, iLayerIndex)->class[i]->group &&<br>             strcasecmp(GET_LAYER(map, iLayerIndex)->class[i]->group, pszStyle) == 0)<br>@@ -4496,10 +4510,6 @@ this request. Check wms/ows_enable_request settings.",<br>         msSetError(MS_WMSERR, "style used in the STYLE parameter is not defined on the layer.",<br>             "msWMSGetLegendGraphic()");<br>         return msWMSException(map, nVersion, "StyleNotDefined", wms_exception_format);<br>-      } else {<br>-        msFree(GET_LAYER(map, iLayerIndex)->classgroup);<br>-        GET_LAYER(map, iLayerIndex)->classgroup = msStrdup(pszStyle);<br>-<br>       }<br>     }<br>   } else {<br></div></div></div>