5.6. 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.

5.6.1. 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:

    CLASSGROUP "group1"
        NAME "name1"
        GROUP "group1"
        NAME "name2"
        GROUP "group2"
        NAME "name3"
        GROUP "group1"

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

5.6.2. Example#

Here is an example:


Mapfile is as follows:

 2    NAME "named-style_"
 3    IMAGETYPE "png24"
 4    EXTENT -180 -90 180 90
 5    SIZE 600 300
 6    SHAPEPATH "/gdata"
 7    SYMBOLSET "../symbols/symbols35.sym"
 8    FONTSET "../fonts/fonts.list"
10        NAME "png"
11        DRIVER "AGG/PNG"
12        MIMETYPE "image/png"
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
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

Use GetCapabilities to return:

  <LegendURL width="72" height="20">
     <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" ...

Consider the following sample WMS request snippet:


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:


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.