MapServer6.4.1教程学习--缩放和漫游控件(2-1)
2015-01-26 23:18
435 查看
(http://demo.mapserver.org/cgi-bin/mapserv?map=/osgeo/mapserver/tutorial/htdocs/example2.map&layer=states&zoom=0&mode=browse&root=/tutorial&program=/cgi-bin/mapserv&map_web=template+example2-1.html)
![](https://img-blog.csdn.net/20150126231831888?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXNzd2Nsdw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
让我们看看mapfile:
#The annotated map file (sort of)
#Created by Pericles S. Nacionales for the MapServer tutorial
#20050623
#
#Map files 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 the very 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
4000
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--MapServerwill render 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 services specifications(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 output projection
#
# 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 involves defining a smallimage 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' # Thereference image
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 like there 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# end of map file
在第一节中的地图中,初始化时是把mapfile路径和其他参数("map=/ms4w/apps/tutorial/htdocs/example2-1.map&mode=browse")传递给MapServ("/cgi-bin/mapserv.exe?”)来调用的。这里第二节的页面中有一个超链接,如下所示:
<ahref="/cgi-bin/mapserv.exe?
map=/ms4w/apps/tutorial/htdocs/example2-1.map
&mode=browse&root=/tutorial&program=/cgi-bin/mapserv
&map_web=template+example2-1.html">
Proceed to Example 2.1</a>
这次我们使用”browse”模式而不是“map”模式。“Browse”模式告诉MapServ需要在我们的”/tmp/”目录下创建一个地图(图像)。图像的路径和名称是通过”img”被MapServ引用的。所以,当MapServ解析HTML模板时,它会用图像的正确路径 /ms_tmp/EX2_14222790837483.png替换掉”[img]”标记。
对于这幅地图你可以做一些操作。首先,当你在图像上的任何部分单击时,地图会以你单击位置为中心刷新。这就是漫游。当你单击”Map Control”下拉框时,你可以选择放大(”Zoom in”)或者缩小(”zoom out”)。如果你设置放大两倍(“zoom in 2x”),然后单击地图的任何部位,地图会以你单击处为中心放大刷新。当你选择zoom out时,情况恰好相反。当选择了”zoom in”或者”zoom out”,点击“Refresh”按键后,先前的地图就会放大或缩小。你可以使用刷新按钮在任何时候去刷新地图。
缩放/漫游控件使用的是MapServerCGI内部变量。这个例子展示了如何使用”zoom”变量。Zoom的值决定了要缩放的比例。如何值为“0”,MapServer就是用户鼠标单击位置为中心刷新地图。如果值大于“0”,CGI程序就放大地图(用地图当前比例乘以缩放值)。如果值是一个负数,CGI程序会缩小地图(用地图当前比例除以缩放值)。其他可以用于控制缩放和漫游的参数有“zoomdir”和“zoomsize”。这两个变量和“zoom”起的作用很相似—“zoomdir”控制缩放方向,“zoomsize”控制缩放比例。请参照 OSGeo
Gallery 或MapServerwiki 上的其他关于缩放/漫游的例子。
试着将“Map Mode”从“Browse”改为“Map”。当你点击刷新时发生了什么?请记住当我们使用“mode=map”时,Mapserver返回的是一幅静态地图…它会忽略HTML模板而将地图图片直接传给浏览器。
尽管这里添加了更多的数据层,但是它和第一节里面的mapfile仍旧很像。关于这个mapfile文件我没有新的东西需要解释,但是如果你对一些新的关键字好奇的话,请参考mapfile reference page。
现在让我们看一看HTML模板文件。注意到一个HTML 表单调用了MapServer CGI程序这点很重要。因为它是一个表单,你可以用单选按钮和复选框以及下拉框去实现你的接口。不要觉得这个例子很有限—其实这是一个很好的创意。:)想获得更多信息请查看HTMLtemplate
reference page。
PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。
让我们看看mapfile:
#The annotated map file (sort of)
#Created by Pericles S. Nacionales for the MapServer tutorial
#20050623
#
#Map files 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 the very 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
4000
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--MapServerwill render 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 services specifications(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 output projection
#
# 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 involves defining a smallimage 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' # Thereference image
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 like there 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# end of map file
在第一节中的地图中,初始化时是把mapfile路径和其他参数("map=/ms4w/apps/tutorial/htdocs/example2-1.map&mode=browse")传递给MapServ("/cgi-bin/mapserv.exe?”)来调用的。这里第二节的页面中有一个超链接,如下所示:
<ahref="/cgi-bin/mapserv.exe?
map=/ms4w/apps/tutorial/htdocs/example2-1.map
&mode=browse&root=/tutorial&program=/cgi-bin/mapserv
&map_web=template+example2-1.html">
Proceed to Example 2.1</a>
这次我们使用”browse”模式而不是“map”模式。“Browse”模式告诉MapServ需要在我们的”/tmp/”目录下创建一个地图(图像)。图像的路径和名称是通过”img”被MapServ引用的。所以,当MapServ解析HTML模板时,它会用图像的正确路径 /ms_tmp/EX2_14222790837483.png替换掉”[img]”标记。
对于这幅地图你可以做一些操作。首先,当你在图像上的任何部分单击时,地图会以你单击位置为中心刷新。这就是漫游。当你单击”Map Control”下拉框时,你可以选择放大(”Zoom in”)或者缩小(”zoom out”)。如果你设置放大两倍(“zoom in 2x”),然后单击地图的任何部位,地图会以你单击处为中心放大刷新。当你选择zoom out时,情况恰好相反。当选择了”zoom in”或者”zoom out”,点击“Refresh”按键后,先前的地图就会放大或缩小。你可以使用刷新按钮在任何时候去刷新地图。
缩放/漫游控件使用的是MapServerCGI内部变量。这个例子展示了如何使用”zoom”变量。Zoom的值决定了要缩放的比例。如何值为“0”,MapServer就是用户鼠标单击位置为中心刷新地图。如果值大于“0”,CGI程序就放大地图(用地图当前比例乘以缩放值)。如果值是一个负数,CGI程序会缩小地图(用地图当前比例除以缩放值)。其他可以用于控制缩放和漫游的参数有“zoomdir”和“zoomsize”。这两个变量和“zoom”起的作用很相似—“zoomdir”控制缩放方向,“zoomsize”控制缩放比例。请参照 OSGeo
Gallery 或MapServerwiki 上的其他关于缩放/漫游的例子。
试着将“Map Mode”从“Browse”改为“Map”。当你点击刷新时发生了什么?请记住当我们使用“mode=map”时,Mapserver返回的是一幅静态地图…它会忽略HTML模板而将地图图片直接传给浏览器。
尽管这里添加了更多的数据层,但是它和第一节里面的mapfile仍旧很像。关于这个mapfile文件我没有新的东西需要解释,但是如果你对一些新的关键字好奇的话,请参考mapfile reference page。
现在让我们看一看HTML模板文件。注意到一个HTML 表单调用了MapServer CGI程序这点很重要。因为它是一个表单,你可以用单选按钮和复选框以及下拉框去实现你的接口。不要觉得这个例子很有限—其实这是一个很好的创意。:)想获得更多信息请查看HTMLtemplate
reference page。
PS:中文版权为asswclw所有,请尊重劳动成果,转载将注明出处。
相关文章推荐
- MapServer6.4.1教程学习--地图交互和浏览器模式(1-9)
- MapServer6.4.1教程学习--图层控制(2-2)
- MapServer6.4.1教程学习--显示图层内类别(1-3)
- MapServer6.4.1教程学习--包含二个图层的静态地图(1-2)
- MapServer6.4.1教程学习--添加栅格图层(1-5)
- MapServer6.4.1教程学习--定义投影和范围(1-6)
- MapServer6.4.1教程学习--CGI变量和用户接口(2-0)
- MapServer6.4.1教程学习--标注地图(1-4)
- MapServer6.4.1教程学习--添加OGC WMS图层(1-7)
- ASP.NET 学习历程 - 清清月儿 .NET万花筒 Asp.net技术 Asp.net教程 Asp.net源码 Asp.net基础 Asp.net控件 Asp.net入门 - CSDNBlog
- 韩顺平_php从入门到精通_视频教程_第7讲_表单及表单控件②_学习笔记_源代码图解_PPT文档整理
- CityMaker学习教程08 一个示例,创建漫游路径
- IOS UI学习教程之使用UIImageView控件制作动画
- 韩顺平_php从入门到精通_视频教程_第6讲_浮动窗口_表单及表单控件①_学习笔记_源代码图解_PPT文档整理
- React Native学习教程之Modal控件自定义弹出View详解
- PyQt5学习教程8:使用Box Layout布局控件
- Android学习教程之动态GridView控件使用(6)
- ISemanticZoom 多用途 将语义缩放 带入你的控件 Windows8 教程
- 学校学习ios教程笔记,第八节初识ios控件中的UILable与UITextField
- [转]Ultra Fractal教程系列32——关于变换的学习07——缩放图层