Draw maps with style layer

More advanced WMSs use "style layers" to describe a map. A style layer can be thought of as a transparent layer composed of symbolic elements. A map is composed of these style layers in a certain order, which is usually called Z-value order. Users can define complex or simple maps by adding or removing style layers. A style layer is actually a combination of a layer and a style. Conceptually, the layer defines a stream of features, and the style defines how those features are symbolized. In a WMS process, the drawing style of a map is specified according to the LAYERS and STYLES request parameters.

Support for named styles

Named styles support are introduced in MapServer 5.2. The support is base on MS RFC 39: Support of WMS/SLD Named Styles.

MapServer 5.2 introduces the possibility to assign a group to a series of classes defined on a layer object using two new non-mandatory keywords CLASSGROUP (at the layer level) and GROUP at the class level:

LAYER
    ...
    CLASSGROUP "group1"
    ...
    CLASS
        NAME "name1"
        GROUP "group1"
        ...
    END
    CLASS
        NAME "name2"
        GROUP "group2"
        ...
    END
    CLASS
        NAME "name3"
        GROUP "group1"
        ...
    END
    ...

At rendering time, if the CLASSGROUP is defined, only classes that have the same group name would be used. Based on this concept, WMS/SLD support uses the class groups as named styles. Each group of classes is considered equivalent to a named style:

The GetCapbilities request will output all the styles that are available
The GetMap request can use the STYLES parameter to specify a named style
The GetLegendGraphic can use the STYLES parameter to specify a named style

Example

Here is an example:

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb5.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMAP&LAYERS=states&BBOX=73,3,136,54&CRS=CRS:84&INFO_FORMAT=text/html&format=image/png&width=200&height=150&styles=group1

Mapfile is as follows:

01 MAP
02     NAME "named-style_"
03     IMAGETYPE "png24"
04     EXTENT -180 -90 180 90
05     SIZE 600 300
06     SHAPEPATH "/gdata"
07     SYMBOLSET "../symbols/symbols35.sym"
08     FONTSET "../fonts/fonts.list"
09     OUTPUTFORMAT
10         NAME "png"
11         DRIVER "AGG/PNG"
12         MIMETYPE "image/png"
13         IMAGEMODE RGB
14         EXTENSION "png"
15         FORMATOPTION "GAMMA=0.75"
16     END
17     WEB
18         IMAGEPATH "/owg/ms_tmp/"
19         IMAGEURL "/ms_tmp/"
20         METADATA
21             "wms_title" "WMS Demo Server"
22             "wms_version" "1.3.0"
23             "wms_onlineresource" "http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb5.map&"
24             "wms_srs" "EPSG:4326"
25             "wms_enable_request" "*"
26             "ows_enable_request" "*"
27             "wms_feature_info_mime_type" "text/html"
28             "wms_format" "image/png"
29         END
30     END
31     PROJECTION
32         "init=epsg:4326"
33     END
34     LAYER
35         NAME "wcountry"
36         DATA "wcountry.shp"
37         STATUS OFF
38         TYPE POLYGON
39         METADATA
40             "wms_title" "world contry"
41             "wms_version" "1.3.0"
42             "wms_srs" "EPSG:4326 EPSG:3857"
43             "wms_enable_request" "*"
44             "ows_enable_request" "*"
45             "wms_format" "image/png"
46         END
47         PROJECTION
48             "init=epsg:4326"
49         END
50         CLASSGROUP "grploy"
51         CLASS
52             NAME "Poly Style 1"
53             GROUP "psty1"
54             STYLE
55                 COLOR 232 232 232
56                 OUTLINECOLOR 32 32 32
57             END
58         END
59         CLASS
60             NAME "Poly Style 2"
61             GROUP "psty2"
62             STYLE
63                 COLOR 204 204 153
64                 OUTLINECOLOR 0 255 255
65             END
66         END
67         CLASS
68             NAME "Line Style"
69             GROUP "lsty"
70             STYLE
71                 OUTLINECOLOR 255 0 0
72             END
73         END
74     END
75 END

Use GetCapabilities to return:

<Style>
  <Name>group1</Name>
  <Title>group1</Title>
  <LegendURL width="72" height="20">
     <Format>image/png</Format>
     <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" ...
  </LegendURL>
</Style>

Consider the following sample WMS request snippet:

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb5.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMAP&LAYERS=states,states&BBOX=73,3,136,54&CRS=CRS:84&INFO_FORMAT=text/html&format=image/png&width=200&height=150&styles=group3,group2

There are three style layers:

  • States: group1
  • States: group2
  • States: group3

They are stacked in a certain order. A layer can be drawn multiple times with different styles to achieve the desired effect. The following example draws the road layer using the casing and centerline styles:

http://webgis.pub/cgi-bin/mapserv?map=/owg/mfb5.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMAP&LAYERS=states,states&BBOX=73,3,136,54&CRS=CRS:84&INFO_FORMAT=text/html&format=image/png&width=200&height=150&styles=group1,group2

A WMS itself may not know how to make a meaningful combination of style layers, it's all up to the client. WMS uses names to identify styles and layers, and other documents refer to such named layers and styles. This is currently the only way for WMS to define style layers.