[mapserver-users] GetLegendGraphic: STYLE support for GROUP-layers (bug?)

Erik Gustafson gustafson.erik at gmail.com
Thu Jan 18 05:59:06 PST 2018


Hi group,

I have a problem with GetLegendGraphic, it ignores the STYLE-parameter in a
specific situation.

1. We have layer groups (GROUP keyword)
2. We have multiple styles in a WMS service
3. We have a default WMS style, by using the CLASSGROUP keyword

the above is a common situation for our INSPIRE view services.
In this setup GetLegendGraphic ignores the STYLE parameter and always uses
the style set by the CLASSGROUP in the mapfile.
See examples below.

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?

Thanks,
Erik Gustafson


Request examples:
mapserv?map=map.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=getleg
endgraphic&layer=GROUPNAME&format=image/png&sld_version=1.1.0&STYLE=DEFAULT
> Ok.

mapserv?map=map.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=getleg
endgraphic&layer=GROUPNAME&format=image/png&sld_version=
1.1.0&STYLE=ALTERNATE
> Not Ok. Expected STYLE=ALTERNATE from the classes named CLASS2 but got
STYLE=DEFAULT, the classes named CLASS1

Example mapfile:
MAP
  WEB
    METADATA
      "wms_enable_request" "*"
    END
  END

 LAYER
  GROUP "GROUPNAME"
  NAME  "LAYER1"
  CLASSGROUP "DEFAULT"

  TYPE POLYGON
  STATUS ON

  CLASS
    NAME 'CLASS1'
    GROUP "DEFAULT"
    STYLE
      COLOR 0 0 255
    END
  END

  CLASS
    NAME 'CLASS2'
    GROUP "ALTERNATE"
    STYLE
      COLOR 255 0 0
      WIDTH 0.4
    END
  END
END

 LAYER
  GROUP "GROUPNAME"
  DEBUG 0
  NAME  "LAYER2"
  CLASSGROUP "DEFAULT"

  TYPE POLYGON
  STATUS ON

  CLASS
    NAME 'CLASS1'
    GROUP "DEFAULT"
    STYLE
      OUTLINECOLOR 0 0 255
      WIDTH 0.4
    END
  END

  CLASS
    NAME 'CLASS2'
    GROUP "ALTERNATE"
    STYLE
      OUTLINECOLOR 255 0 0
      WIDTH 0.4
    END
  END
END
END

Currently we use a modified mapwms.c to work around this, which works for
us but maybe breaks other functionality.
diff --git a/mapwms.c b/mapwms.c
index 1b09109..077f596 100644
--- a/mapwms.c
+++ b/mapwms.c
@@ -4428,6 +4428,20 @@ int msWMSLegendGraphic(mapObj *map, int nVersion,
char **names,
         nLayers++;
         lp->status = MS_ON;
         iLayerIndex = i;
+
+       // set classgroup if a STYLE is requested
+        if (pszStyle && strlen(pszStyle) > 0 && strcasecmp(pszStyle,
"default") != 0) {
+             for (j=0; j<GET_LAYER(map, iLayerIndex)->numclasses; j++) {
+               if (GET_LAYER(map, iLayerIndex)->class[j]->group &&
+                   strcasecmp(GET_LAYER(map,
iLayerIndex)->class[j]->group, pszStyle) == 0) {
+                  msFree(GET_LAYER(map, iLayerIndex)->classgroup);
+                 GET_LAYER(map, iLayerIndex)->classgroup =
msStrdup(pszStyle);
+                 break;
+               }
+             }
+
+       }
+
         if (GET_LAYER(map, i)->connectiontype == MS_WMS) {
           /* we do not cascade a wms layer if it contains at least
            * one class with the property name set */
@@ -4485,7 +4499,7 @@ this request. Check wms/ows_enable_request settings.",
     /*if STYLE is set, check if it is a valid style (valid = at least one
     of the classes have a the group value equals to the style */
     /*style is only validated when there is only one layer #3411*/
-    if (nLayers == 1 &&  pszStyle && strlen(pszStyle) > 0 &&
strcasecmp(pszStyle, "default") != 0) {
+    if (pszStyle && strlen(pszStyle) > 0 && strcasecmp(pszStyle,
"default") != 0) {
       for (i=0; i<GET_LAYER(map, iLayerIndex)->numclasses; i++) {
         if (GET_LAYER(map, iLayerIndex)->class[i]->group &&
             strcasecmp(GET_LAYER(map, iLayerIndex)->class[i]->group,
pszStyle) == 0)
@@ -4496,10 +4510,6 @@ this request. Check wms/ows_enable_request
settings.",
         msSetError(MS_WMSERR, "style used in the STYLE parameter is not
defined on the layer.",
             "msWMSGetLegendGraphic()");
         return msWMSException(map, nVersion, "StyleNotDefined",
wms_exception_format);
-      } else {
-        msFree(GET_LAYER(map, iLayerIndex)->classgroup);
-        GET_LAYER(map, iLayerIndex)->classgroup = msStrdup(pszStyle);
-
       }
     }
   } else {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20180118/3a4acbb0/attachment.html>


More information about the mapserver-users mailing list