较为高级的 WMS 用“样式层”来描述一幅地图。可以认为一个样式层是由符号化的要素组成的一个透明层。一幅地图是由这些样式层按一定的顺序组成的,通常称这些样式层是Z值排序。用户可以通过增加或删除样式层来定义复杂或简单的地图。一个样式层实际上是一个图层和一个样式的组合,从概念上看,图层定义了一个要素流,而样式定义了这些要素如何符号化。在一个 WMS 过程中,一幅地图的绘制样式是根据 LAYERS 和 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
这里给出一个实例:
http://webgis.cn/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 如下:
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.cn/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
使用 GetCapabilities
, 会返回:
<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>
考虑下面的一个 WMS 请求示例片断:
http://webgis.cn/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
这里有3个样式层:
它们是按一定的顺序叠加的。一个图层可以用不同的样式绘制多次,以达到用户需要的效果。下例是对道路图层用 casing
和 centerline
两种样式分别绘制:
http://webgis.cn/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
一个 WMS 本身可能不知道样式层如何进行有意义的组合,这一切都由客户端决定。WMS 用名称去标识样式和层,其他文档引用这种命名的层和样式,这是目前 WMS 定义样式层的唯一方法。