能够控制图层的显隐是网络地图应用的标准特征。使用表单对象作为控件的话有很多方法可以做到这一点。你可以用下拉框/菜单,复选框,与/或单选按钮。在这个例子中你会看到用复选按钮和下拉框是如何实现图层选择的。
下面是mapfile文件内容。
# The annotated map file (sort of)
# Createdby Pericles S. Nacionales for the MapServer tutorial
# 20050623
#
# Mapfiles begin with map keyword to signify the start of the map object.
# Well,the entire map file is THE map object. Enclose between MAP and END
# at thevery bottom of this map file, are keyword/value pairs and other
# objects.
MAP
NAME EX2_
IMAGETYPE png24
EXTENT 166221 -371954 1505849 632767 # LAEA
#EXTENT -97.5 41.619778 -82.122902 49.38562 #Geographic
SIZE 400 300
SHAPEPATH "../data"
SYMBOLSET "../symbols/symbols35.sym"
FONTSET "../fonts/fonts.list"
# When changing any of the mapfile parametersvia the web interface, you
# need to define a TEMPLATEPATTERN. This is required for security reasons.
# Since the example filenames in section 2begin with "example2" (as in
# example2-1.html or example2-2.html), youcan use it as the pattern.
# The template pattern is a regularexpression used by MapServer to match the
# value of map_web_template variable against.
TEMPLATEPATTERN 'example2*'
# The web object is defined at the levelbelow the map object. All
# web-related parameters (I interchange"parameters" and "keyword/value
# pairs" quite frequently, sorry aboutthat) are defined in this object.
WEB
TEMPLATE 'to be replaced by map_web_template variable in section2.html'
IMAGEPATH'/osgeo/mapserver/fgs/tmp/ms_tmp/'
IMAGEURL '/ms_tmp/'
END # Every object in MapServer must have anEND.;)
# The projection object is typically usedwithin the map and the layer
# objects. You only define it once within themap object and this definition
# becomes your output projection--MapServer willrender your maps in this
# projection. You also use the projection object within the layer object to
# define your input projection. Your layers can be in different
# projections--MapServer will reproject theminto your output projection.
# If no projection is defined within thelayer object, MapServer assumes
# your input projection is the same as youroutput projection. This is not
# a required object unless you're creating amap file that supports one of
# the OGC interoperability web servicesspecifications (WMS/WFS/WCS).
PROJECTION
# Projection parameters can be defined intwo ways...
# This is the traditional Proj.4 definitionof Lambert Azimuthal Equal-Area
# projection for the Continental U.S.
# "proj=laea"
# "ellps=clrk66"
# "lat_0=45"
# "lon_0=-100"
#
# Alternatively, you can specify an EPSGcode.
# This is the EPSG code for LambertAzimuthal Equal-Area
# projection for the U.S.
"init=epsg:2163"
END # This is the ending of the outputprojection
#
# Start of legend
#
LEGEND
KEYSIZE 12 12
LABEL
TYPE BITMAP
SIZE MEDIUM
COLOR 0 0 89
END
STATUS ON
END
# The reference object is used to define areference map for your mapping
#application. This typically involvesdefining a small image that covers
# the entire area of the map and defining abox that represents the current
# view on in relation to the entire area.
REFERENCE
IMAGE '../images/ugl_ref1.png' # The referenceimage
SIZE 155 105 # The size of the referenceimage in pixels
EXTENT 201621.496941 -294488.2853331425518.020722 498254.511514 # The extent of the reference image in map units
STATUS ON
MINBOXSIZE 10 # How small can the referencebox be before it gets drawn as a point, in pixels
MAXBOXSIZE 150 # The maximum size of thereference box, in pixels
COLOR -1 -1 -1 # The reference box fillcolor, negative numbers mean transparent
OUTLINECOLOR 128 0 0 # The reference boxoutline color
MARKERSIZE 8 # The size of the point marker
MARKER 'star' # The marker symbol
END
# A scalebar object is defined one levelbelow the map object. This object
# controls how a scalebar is drawn byMapServer. Scalebars can be embedded
# in the map itself or can be created as aseparate image. It has an
# associated MapServer CGI variable called"scalebar" (or [scalebar] when
# used in the HTML template).
SCALEBAR
IMAGECOLOR 255 255 255
LABEL
COLOR 0 0 0
SIZE TINY
END
STYLE 1
SIZE 100 2
COLOR 0 0 0
UNITS MILES
INTERVALS 2
TRANSPARENT FALSE
STATUS ON
END # Scalebar object ends
# Layer objects, too, are defined beneath themap object. Be mindful of the
# order of your layer objects. MapServer "stacks them" in reverse
# order--that is, the last layer you define(at the bottom of the map file)
# will be drawn on top and the first layeryou define (right after this
# comment), will be drawn at the bottom. Here's my rule: rasters and
# polygons are defined first, followed by theline layers. The point and
# annotation layers are defined last. You can play around with the ordering
# of your layers until you're satisfied.
# Start of LAYER DEFINITIONS---------------------------------------------
LAYER # States polygon layer begins here
NAME states
DATA states_ugl
STATUS DEFAULT
TYPE POLYGON
REQUIRES "![modis] OR ![modis_jpl]"
# Here's an example of the input projectiondefinition.
# EPSG:4326 is code for geographic(latlong) projection
# using the WGS84 datum
PROJECTION
"init=epsg:4326"
END
CLASSITEM "CLASS"
# The class object is defined within thelayer object. You can define as
# many classes as you need (well, there arelimits, but it's senseless to
# define more than ten on a"normal" layer. There aresituations,
# however, where you might have to do it.)
CLASS
EXPRESSION 'land'
# There are styles in a class, just likethere are classes in a layer,
# just like there are layers in a map.
STYLE
SYMBOL 0
COLOR 232 232 232
END # And they all must come to an end.
END # End of this class.
END # States polygon layer ends here
LAYER # MODIS raster layer begins here
NAME modis
DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
STATUS OFF
TYPE RASTER
OFFSITE 70 74 66 #167 151 152
PROJECTION
"init=epsg:4326"
END
END # MODIS raster layer ends here
LAYER # MODIS WMS map from JPL (or from USGS)
NAME modis_jpl
TYPE RASTER
OFFSITE 0 0 0
STATUS OFF
CONNECTIONTYPE WMS
CONNECTION"http://wms.jpl.nasa.gov/wms.cgi?"
METADATA
"wms_srs" "EPSG:4326"
"wms_name""daily_terra" #"global_mosaic" "daily_aqua"
"wms_server_version""1.1.1"
"wms_format""image/jpeg"
END
PROJECTION
"init=epsg:4326"
END
END # MODIS WMS image ends here
LAYER # Hydrography layer begins here
NAME hydro
TYPE POLYGON
STATUS OFF
DATA hydrop_ugl
PROJECTION
"init=epsg:4326"
END
CLASSITEM 'FEATURE'
CLASS
NAME 'Lakes'
EXPRESSION /(^B|^C|^L|^R)./
STYLE
COLOR 72 64 254
END
END # CLASS
CLASS
NAME 'Rivers'
EXPRESSION 'Stream'
STYLE
COLOR 136 128 255
END
END # CLASS
CLASS
NAME 'Wetlands'
EXPRESSION 'Swamp or Marsh'
STYLE
COLOR 195 252 255
OUTLINECOLOR 195 252 255
SYMBOL 'circle'
SIZE 0
END
END # CLASS
END #LAYER
LAYER # ROADS LAYER
NAME cty_roads
GROUP roads
TYPE LINE
STATUS OFF
DATA roads_ugl
MAXSCALE 750000
PROJECTION
"init=epsg:4326"
END
CLASSITEM 'CLASS1'
CLASS
NAME 'Minor Arterial Roads'
EXPRESSION '3'
STYLE
COLOR 165 165 165
END
END #CLASS
CLASS
EXPRESSION '4'
STYLE
COLOR 210 210 210
END
END # CLASS
END #ROADS LAYER
LAYER # state highways begin here
NAME state_hwy
GROUP roads
MAXSCALE 1500000
STATUS OFF
DATA roads_ugl
TYPE LINE
FILTERITEM 'CLASS1'
FILTER '2'
CLASS
NAME 'Principal Arterial Roads'
STYLE
COLOR 255 0 0
SIZE 1
SYMBOL 'circle'
END
END
PROJECTION
"init=epsg:4326"
END
END # highways
LAYER # interstate highways begin here
NAME interstate
GROUP roads
# MAXSCALE 22500000
STATUS OFF
DATA roads_ugl
TYPE LINE
FILTERITEM 'CLASS1'
FILTER '1'
CLASS
NAME "Interstate Hwy."
STYLE
COLOR 128 0 0
END
END
PROJECTION
"init=epsg:4326"
END
END # highways
LAYER # States line layer begins here
NAME states
DATA states_ugl
STATUS OFF
TYPE LINE
PROJECTION
"init=epsg:4326"
END
CLASSITEM "CLASS"
CLASS
NAME 'State Boundary'
EXPRESSION 'land'
STYLE
SYMBOL 'line5'
COLOR 32 32 32
SIZE 1
END
END
END # States line layer ends here
LAYER
NAME roads_anno
GROUP roads
MAXSCALE 750000
STATUS OFF
DATA roads_ugl
TYPE ANNOTATION
LABELITEM "SIGN"
CLASSITEM "CLASS1"
CLASS
EXPRESSION "3"
STYLE
COLOR 0 0 0 # dummy color
SYMBOL '../symbols/sthwy.png'
END
LABEL
MINFEATURESIZE 50
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 0 0 0
END
END
CLASS
EXPRESSION "2"
STYLE
COLOR 0 0 0 # dummy color
SYMBOL '../symbols/ushwy.png'
END
LABEL
MINFEATURESIZE 50
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 0 0 0
END
END
PROJECTION
"init=epsg:4326"
END
END # highway annotation
LAYER
NAME roads_anno1
GROUP roads
STATUS OFF
DATA roads_ugl
TYPE ANNOTATION
LABELITEM "SIGN"
CLASSITEM "CLASS1"
CLASS
EXPRESSION "1"
STYLE
COLOR 0 0 0 # dummy color
SYMBOL '../symbols/interstate.png'
END
LABEL
MINFEATURESIZE 20
MINDISTANCE 150
POSITION CC
SIZE TINY
COLOR 255 255 255
END
END
PROJECTION
"init=epsg:4326"
END
END
LAYER # States label layer begins here
NAME states
DATA states_ugl
STATUS OFF
TYPE ANNOTATION
PROJECTION
"init=epsg:4326"
END
CLASSITEM "CLASS"
LABELITEM "STATE"
CLASS
EXPRESSION 'land'
STYLE
COLOR -1 -1 -1
END
LABEL
COLOR 132 31 31
OUTLINECOLOR 128 128 128
SHADOWCOLOR 218 218 218
SHADOWSIZE 1 1
TYPE TRUETYPE
FONT arial-bold
SIZE 12
ANTIALIAS TRUE
POSITION CL
PARTIALS FALSE
MINDISTANCE 200
BUFFER 4
END # end of label
END # end of class
END # States label layer ends here
# End of LAYER DEFINITIONS-------------------------------
END # endof map file
请注意除了“State”多边形背景图层外其他图层状态是如何改变成OFF状态的。State背景图层默认显示,这样当绘制时如果没有图层是显示状态的情况下,也是有东西可以显示的。我们应用的客户需要控制哪些图层显示或关闭。
如果你看一看sourcecode of our HTML template,你会理解MapServ是如何控制图层的显隐。
PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。