示例1.4
标注地图
(http://www.mapserver.org/tutorial/example1-4.html#example1-4)
我们也可以给地图添加标注:
MapServer具有非常灵活的标注引擎。它支持truetype字体的同时也支持本地图片方式。还支持TrueType字体的缩放。标注角度和位置能够用户定制。如果你花时间去学习创建好标注的那些参数,你会得到信息量丰富且令人愉悦的地图作为奖励。
下面是示例1.4的mapfile:
#The annotated map file (sort of)
#Created by Pericles S. Nacionales for the MapServer tutorial
#20050408
#
#MapServer map file uses the pound sign (#) to denote the start of a line
#comment--each line that needs to be commented has to be prepended with a"#".
#
#Map files begin with MAP keyword to signify the start of the map object.
#Well, the entire map file is THE map object. Enclosed between MAP and END
#at the very bottom of this map file, are keyword/value pairs and other
#objects.
MAP
IMAGETYPE PNG
EXTENT -97.238976 41.619778 -82.122902 49.385620
SIZE 400 300
SHAPEPATH "../data"
IMAGECOLOR 255 255 255
FONTSET "../fonts/fonts.list"
# Layer objects are defined beneath the mapobject. You need at least one
# layer defined in your map file before youcan display a map... You can
# define as many layers as you'd likealthough a limit is typically hard-coded
# in map.h in the MapServer source. The default limit is set at 100. You'd
# have to have a very specialized applicationto need more than 100 layers in
# your application.
# Start of LAYER DEFINITIONS---------------------------------------------
LAYER # States polygon layer begins here
NAME states_poly
DATA states_ugl
STATUS OFF
TYPE POLYGON
# CLASSITEM defines the non-spatialattribute that you will be using to
# separate a layer into classes. This attribute will be in the DBF file
# of your shapefile (it will be differentfor each data format). In this
# example the shapefile states_ugl has anassociated database
# (states_ugl.dbf) that contains anattribute called "CLASS". Youwill be
# using two values in the CLASS attributeto separate the classes (also
# called themes) used in this layer--landand water. CLASSITEM is used in
# association with the EXPRESSION parameterin the CLASS object. See below.
CLASSITEM "CLASS"
# Just like CLASSITEM, LABELITEM definesthe database attribute that you
# will be using to draw labels. In this case, the values of the attribute
# "STATE" will be used to labelthe states polygons.
LABELITEM "STATE"
# The class object is defined within thelayer object. You can define as
# many classes as you need (well, there arelimits as with layers, but it's
# senseless to define more than ten on a"normal" layer. There are
# situations, however, where you might haveto do it.)
CLASS
NAME 'States'
EXPRESSION 'land'
# There are styles in a class, just likethere are classes in a layer,
# just like there are layers in amap. You can define multiple styles in
# a class just as you can define multipleclasses in a layer and multiple
# layers in a map.
STYLE
COLOR 232 232 232
END
# There can be labels in a class, justlike there are classes in a layer,
# just like there are layers in amap. You can define multiple labels in
# a class just as you can define multipleclasses in a layer and multiple
# layers in a map.
# MapServer has a very flexible labelingsystem. With that flexibility
# comes complexity, specially when usingtruetype fonts. Please read
# through the LABEL section of theMapServer map file documentation at
# http://www.mapserver.org/mapfile formore information.
LABEL
COLOR 132 31 31
TYPE TRUETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 300
BUFFER 4
# create a background shadow
# Note that the tutorial package has not been updated, so this has
# to be done manually!
#SHADOWCOLOR 218 218 218 # prior to version 6
#SHADOWSIZE 2 2 # prior to version 6
STYLE # since to version 6
GEOMTRANSFORM 'labelpoly'
COLOR 218 218 218
OFFSET 2 2
END # STYLE
END # end of label
END
CLASS
NAME 'Water'
EXPRESSION 'water'
STYLE
COLOR 198 198 255
END
END
END # States polygon layer ends here
LAYER # States line layer begins here
NAME states_line
DATA states_ugl
STATUS OFF
TYPE LINE
CLASSITEM "CLASS"
CLASS
NAME 'State Boundary'
EXPRESSION 'land'
STYLE
COLOR 64 64 64
END
END
END # States line layer ends here
# End of LAYER DEFINITIONS-------------------------------
END# All map files must come to an end just as all other things must come to..
MapFile结构
下面是mapfile内的对象结构:
MAP
(states_poly)LAYER----------|---------LAYER (states_line)
(land)CLASS-----|-CLASS (water) |-CLASS
STYLE-|-LABEL |-STYLE |-STYLE</pre>
LABEL对象和关键字
这里我们再介绍一些LABEL对象相关的参数:
FONTSET
这里为TrueType字体列表文件指定全路径。这个文件列出了所有可能获得的字体。仔细看这个文件本身和MapServerfontset documentation去获得更多信息。FONTSET是MAP对象的参数。
LABELITEM
用来指定标注所用的数据属性,本例为”STATE”。LABELITEM是LAYER对象的参数。
LABEL
表示LABEL对象的开始标记。标注对象可以用在其他对象下面(如SCALEBAR对象)。
COLOR
处于LABEL对象内部,指定标注文本的颜色。
SHADOWCOLOR (不推荐使用)
指定标注文本阴影颜色。
注意:从MapServer6开始,GEOMTRANSFORM LABELPOLY的LABEL STYLE必须使用。本教程还未更新。
SHADOWSIZE (不推荐使用)
指定阴影尺寸。此值以像素单位代表X,Y的偏移值。所以,“2 2”意味着两个像素宽和两个像素高。
注意:从MapServer6开始,GEOMTRANSFORM LABELPOLY的LABEL STYLE必须使用。本教程还未更新。
TYPE
在LABEL对象内部指定使用哪种类型字体。我们可以选择TRUETYPE或BITMAP(内置字体)。我们选择TRUETYPE。
FONT
如果你指定TYPE为TRUETYPE,你需要指定使用的是哪种字体。这里使用的是字体列表文件中的“alias”。
SIZE
如果使用的是truetype字体,此值代表字体像素尺寸大小。如果是位置,你会看到如”small”或”large”的字样。
ANTIALIAS
用来打开truetype字体抗锯齿功能打开或关闭。记住这个值不是on或off,而是TRUE或FALSE。
POSITION
指定相对于标注点标注文本的位置。它是垂直和水平位置的联合体。你可以将垂直对齐设置为:C表示中间,U表示上,L代表下。水平对齐可设置为:C代表中间,L代表左,R代表右。所以,为了将标注文本对齐到标注ID中间,你要使用“CC“(中间-中间)。或者你想对齐在ID的左下方,你要使用”LL”.另一个办法是让MapServer来决定标签的最佳位置,这时你要使用”AUTO”。
PARTIALS
告诉MapServer是否需要生成不完整的标注文本。默认的是不生成标注文本的片断。这个值要么是TRUE要么是FALSE。
MINDISTANCE
指定重复标签间的最小距离像素值。增加或减小这个值看看会发生什么。
BUFFER
每个标注的像素填充值。这个用来增强可读性。BUFFER值为4个像素值意味着在一个标注的4个像素内是不会画其他标注的。你也可以改变这个值看它是怎么作用的。
你也可以独立于POLYGON层创建标注。你要用ANNOTATION数据类型来实现这个功能。看看下一个例子了解你要如何实现这种标注。你会注意到”label”对象内的CLASS对象有一个COLOR参数,它的值为”-1 -1 -1”。负值告诉MapServer给CLASS透明色(标注ID不需要显示)。再一次的,玩味一下参数的值去了解它是如何作用于地图的。
PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。