博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MapServer教程2
阅读量:5064 次
发布时间:2019-06-12

本文共 101478 字,大约阅读时间需要 338 分钟。

 

第二章 Tutorial 教程

MapServer Tutorial MapServer教程

  • Tutorial background 教程背景
  • Section 1: Static Maps and the MapFile 第一阶段:静态地图Maps和地图文件MapFile
  • Section 2: CGI variables and the User Interface 第二阶段:CGI变量和用户界面
  • Section 3: Query and more about HTML Templates 第三阶段:查询和HTML模板
  • Section 4: Advanced User Interfaces 第四阶段:增强用户界面

Tutorial background教程背景

  • Tutorial Timeframe 教程时间框架

虽然有些用户可以在一天内完成本教程,但那些详细研究每个示例的用户可能期望在一周内完成本教程。

  • Tutorial Data 教程数据

本教程中使用的数据集取自美国内政部a zs美国国家地图集(现在由data.gov托管)。数据集被裁剪到上五大湖地区(明尼苏达州、密歇根州和威斯康星州),以减少存储空间。额外的光栅图像是由明尼苏达大学的Terrasip项目提供的。使用本教程时,鼓励您使用自己的数据集。

与MapServer本身一样,本教程对任何人都是开放的和可自定义的。这样做的目的是希望有人(或某些人)能够帮助设计和进一步开发它。

在http://download.osgeo.org/mapserver/docs/mapserver-tutorial.zip下载本教程的数据(以及所有HTML文件)。

 

  • Before Using the Tutorial 在使用本教程之前

使用本教程有一些先决条件:

1。用户需要在其计算机上安装并运行Web服务器。此Web服务器必须支持通用网关接口(CGI)程序。
2。用户应该对Web服务器和Internet安全有基本的了解。配置不正确的Web服务器很容易被恶意的人攻击。你的软件安装会失败你zll会损失数小时的工作效率,最坏的情况是你的电脑可以用来攻击互联网上的其他电脑。
3。建议本教程的用户在继续此操作之前先阅读MapServer简介。
4。要使用本教程,用户需要在他们的系统。MapServer源代码可在此处下载。关于如何编译的文档已经存在并安装MapServer:
•对于Unix用户,请阅读MapServer Unix编译和安装指南。
•Windows用户应阅读MapServer Win32编译和安装指南
此外,许多平台都存在预编译的二进制文件(请参见下载页)。

Windows, UNIX/Linux Issues  Windows、Unix/Linux问题

Paths

路径

本教程是在Linux/Unix上创建的,但是应该在Windows平台上进行最小的更改。主要区别在于map文件中的路径。Windows用户需要指定其教程文件所在硬盘的驱动器号。这里是一个例子:

 Unix地图文件可能包含如下参数:

在Windows中,相同的参数可能如下所示:

或者:

请注意,斜杠或反斜杠在Windows中都有效。如果您想区分映射文件中的虚拟路径(如URL或Web地址)和本地路径,通常的反斜杠可能对您很有用。但是,如果您计划在某个时间点将应用程序移动到Unix,那么您的zll有一项单调的任务,即将所有反斜杠切换为斜杠。

当我们讨论路径的主题时,请记住,map文件中的路径通常与系统的根目录相关:UNIX中的斜杠(_aij/_ a i)或Windows中的某些驱动器号(_aijc:_ a i)。这是正确的,除非特别要求输入URL或引用URL。使用HTML模板文件时,路径是相对于Web服务器的根目录。也就是说,“/tutorial/“是相对于“https://demo.mapserver.org/“的。请阅读http://www.alistaparate.com/articles/slashforward/了解有关URL的一些细节。

Executable

可执行文件

另一个问题是,Unix可执行文件不需要.exe或.com扩展名,但在Windows中需要。如果您使用的是Windows,请将.exe附加到所有实例中的”/cgi bin/mapserv“或”/cgi-bin/mapserv“改为"cgi-bin/mapserv.exe"或"/cgi-bin/mapserv50.exe "。

 

Other Resources 其他资源

还有其他文档可以让您更好地了解MapServer提供的许多定制。请访问MapServer文档页面:http://www.mapserver.org/documentation.html。在这里,您可以找到几个howto文档,从入门到使用mapscript,这是一个针对mapserver的脚本接口。

 

Section 1: Static Maps and the MapFile

• 拿个shapefile,任何人我们可以用鼠标在一个浏览器上显示该shapefile形状文件。看:

Example 1.1 - A map with a single layer:

mapserver可以创建一个地图并将其转储到本地目录,或者直接发送到请求的Web浏览器,如本例所示。您可以在不需要HTML页面的情况下查看它,只需输入以下URL:http://<insert hostname or ip address here>/cgi bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1.map&amp;layer=states&amp;mode=map(记住将“<insert hostname or ip address here>”替换为Web服务器的名称,例如“localhost”,或其IP地址,例如“127.0.0.1”)。

这个URL可以分为三部分:第一部分,http://<insert hostname or ip address here>/cgi bin/mapserv.exe?,调用mapserver cgi程序。如果您按原样调用它,您将得到这个熟悉的消息:

No query information to decode. QUERY_STRING is set, but empty.

接下来的三个部分是组成查询字符串的部分。查询字符串包含CGI参数(变量及其值),每个参数由一个与(&amp;)分隔。因此,查看查询字符串,第一个参数“map”有一个值“/ms4w/apps/tutorial/htdocs/example1-1.map”--这告诉mapserver cgi程序(mapserv或mapserv.exe)要处理/解析什么mapfile。下一个参数“layer=states”告诉mapserv.exe“打开”状态层——回想一下,我们将层对象命名为“states”。最后一个参数“mode=map”告诉mapserv.exe如何处理来自mapfile的输出。在本例中,它告诉mapserv.exe直接将映像转储到Web浏览器(客户端),而不首先在服务器上创建临时映像。mapserver“模式”cgi变量可以采用“map”以外的值。例如,如果使用“mode=browse”,mapserver将把映像转储到服务器上的临时目录。浏览模式现在不起作用,但稍后我们将再次使用。

这是map文件的外观(例如1-1.map):

# 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  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME       "The Upper Great Lakes States"      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR        232 232 232        OUTLINECOLOR 32 32 32      END    END  END # States polygon layer ends here  # End of LAYER DEFINITIONS -------------------------------END # All map files must come to an end just as all other things must come to...
View Code

 mapfile是mapserver的基本配置机制。它由“对象”组成,每个对象可以有关键字或其他对象。它有一个层次结构,一些对象落在其他对象之下…在这个层次结构的顶部是映射对象,所有其他对象都属于它。这个例子显示了对象的一个非常直接的继承关系。当您通过每个示例时,这些层次树的复杂性将增加。

关于mapfiles的一些简短说明:我们用对象名定义mapfile中的每个对象,并用“end”关闭它,在注释前面加上一个磅()符号。

让我们按对象分解“example1-1.map”。其结构如下:

让我们看下Map文件中的关键字:

MAP地图

每个MAP地图文件都以MAP开始——整个地图文件就是MAP地图对象。

IMAGETYPE图像类型

关键字imagetype用于定义mapserver cgi程序应用于输出的图像格式。在本例中,我们使用索引颜色png(类似于gif)。如果我们使用gif支持、wbmp或jpeg编译gd库,这可能是gif。我们还可以指定其他输出选项(pdf、swf、geotiff),前提是我们编译了对它们的支持并使用outputformat对象指定它们。输出格式超出了本教程的范围,但您可以通过阅读MapServer网站中的文档了解更多信息。

EXTENT范围

此参数指定地图的输出范围——初始地图的边界框。范围值按以下格式给出:<lower left x><lower left y><upper right x><upper right y>,每个值之间用空格分隔。这需要与数据使用相同的单位,或者,如果指定了不同的输出投影,则需要与输出投影使用相同的单位。

在这个例子中,我们的数据是地理投影的,所以单位是十进制的。您可以使用作为gdal/ogr库包一部分的实用程序“ogrinfo”来获取特定形状文件(或其他支持的矢量格式)的范围。下面是我用于获取此示例范围的命令:

ogrinfo -al -so states_ugl.shp

这将返回以下输出:

INFO: Open of `states_ugl.shp'using driver `ESRI Shapefile' successful.Layer name: states_uglGeometry: PolygonFeature Count: 204Extent: (-97.238976, 41.619778) - (-82.122902, 49.385620)Layer SRS WKT:(unknown)AREA: Real (12.3)PERIMETER: Real (12.3)STATESP020: Real (11.0)STATE: String (20.0)STATE_FIPS: String (2.0)CLASS: String (5.0)

您还可以使用ArcView或其他开源的GIS包——Quantum GIS、Thuban等。

请随意更改范围的值,以便更好地了解它如何更改您的地图。

SIZE 尺寸

这是MapServer将生成的图像(地图)的大小(像素)。所以我们的地图是400像素宽,300像素高。再次,把它改为你喜欢的内容,看看它是如何影响你的地图的。

SHAPEPATH 形状路径

这是到数据层的路径。您可以提供绝对路径(即“/ms4w/apps/tutorial/data”或“c:/ms4w/apps/tutorial/data”)或相对于map地图文件位置的路径(在本例中,您将使用“../data”)。此路径不必是可访问Web的,除非您希望任何人下载您的原始数据,否则可能不应该是。它与Web没有直接关系,因此在这里甚至不要考虑URL——只需确保运行Web服务器的用户(通常是*nix世界中的“nobody”或“apache”)可以读取shapepath中的数据。

IMAGECOLOR 图像颜色

这是地图的背景色。这些值是RGB值,因此255红色、255绿色和255b会产生白色背景。继续玩这个value。

 

现在让我们看看图层对象参数:

Layer图层

标记地图对象中图层的开始。尽管默认情况下限制为100,但可以指定任意多个层。要更改此限制,必须编辑map.h头文件(在soure树中)并重新编译mapserver。

NAME名字

这是层标识符。MapServer使用此名称打开和关闭图层。在本例中,它不起作用,因为我们将图层状态STATUS属性设置为默认。在后面的例子中我们将回到这个问题。

DATA数据

数据的名称(本例中为shapefile)。请阅读MapServer矢量数据指南以了解有关如何访问MapServer中的矢量数据的更多信息。

MAPServer通过使用ogr库(gdal软件包的一部分)支持ESRI的shapefile以外的矢量数据格式。请访问gdal项目网站http://www.gdal.org/并阅读http://www.gdal.org/ogr/ogr_formats.html,了解有关各种支持的ogr格式的更多信息。

TYPE类型

它是什么类型的数据?如果是矢量数据,则可以指定它是多边形、直线(即使数据在技术上是多段线,也可以使用直线)还是点。也可以指定光栅或注释数据。这里我们要显示多边形。

STATUS状态

层根据其状态打开或关闭。DEFAULT默认值始终为“开”。当层名称作为查询字符串的一部分传递时,打开或关闭工作。

 

让我们看看CLASS类对象参数:

CLASS类

标记Layer层对象中CLASS类对象的开头。您可以在一个层中指定任意多个类,尽管默认情况下限制为50个类。您必须重新编译mapserver才能更改此默认值。

NAME名字

此类的描述性标识符。图层对象可以有多个类,就像地图对象可以有多个图层一样。MapServer将类名用作图例的标签,因此在命名类时请确保使用适当的描述性名称。我们稍后将在本教程中讨论图例。

 

最后,我们来看一下STYLE样式对象参数:

STYLE风格

标记样式对象的开始。您可以在一个类中定义多个样式——当您想将一个样式覆盖到另一个样式上时,这很有用。

COLOR颜色

这是多边形的填充颜色。如果类型是line,这是line颜色。这些值采用RGB格式。

OUTLINECOLOR轮廓颜色

这是多边形的轮廓颜色。这些值采用RGB格式。默认情况下,MapServer不绘制多边形轮廓,因此如果要查看多边形边界,则需要定义一个大纲颜色。

这结束了本教程中的第一个示例。建议您更改映射文件中关键字的值。它将帮助您理解这些关键字的作用。

 

 

Example 1.2: Static Map with Two Layers

• 我们可以重复显示相同的shapefile数据集。我们可以在一个图层中显示多边形属性,在另一个图层中显示线条属性。˘

Example 1.2 - A map with two layers

 

与第一个示例一样,此图像是通过将<img>标记的源链接到此URL生成的。这就是本节中大多数示例的工作方式。

无论如何,您会注意到这里的地图与第一个示例相同。是的,但地图文件不同。看看。

这是映射文件的外观(example 1-2.map):

# 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  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to 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    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME       "States"      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR    232 232 232      END    END  END # States polygon layer ends here  LAYER # States line layer begins here    NAME         states_line    DATA         states_ugl    STATUS       OFF    TYPE         LINE    CLASS      NAME       "State Boundary"      STYLE        COLOR    32 32 32      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...
View Code

按对象划分的map文件结构如下所示:

在这里,我们将原始层分为两层。第一层仍然是多边形层,但样式不再具有outline颜色。第二层与第一层类似,只是类型更改为线条,样式中的颜色更改为与第一个示例中的outline轮廓颜色相同的颜色。这将生成与第一个图像相同的图像…那么,为什么要这样做?如果我们继续在状态层的顶部添加层,那么轮廓很可能会被其他层覆盖。为了在添加这些其他层之后仍能看到状态边界,我们必须将状态边界线层与状态多边形层分离,并将其放在其他层的顶部。我们如何定义/添加层是有顺序的,在本节中,您将清楚地看到它。

 

Example 1.3: Displaying Classes in a Layer

• 我们可以选择要显示的形状文件的哪些部分。我们使用类对象来完成这项工作…
– 示例1.3-使用类制作“有用”地图

这是map地图文件的外观(Example 1-3.map):

# 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  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to 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-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also     # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME 'States'      EXPRESSION 'land' # Only polygons where "CLASS" = 'land' will be drawn.      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR      232 232 232      END    END    CLASS      NAME 'Water'      EXPRESSION 'water' # Only polygons where "CLASS" = 'water' will be drawn.      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    32 32 32      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...
View Code

按对象划分的map文件结构如下所示:

 

我们的地图文件仍然只有两个图层,但是多边形图层被分解为两个类。让我们看看其他参数:

 

CLASSITEM

此关键字用于指定用于分隔类对象的属性。在这个例子中,属性是“class”。如果打开与该层的shapefile关联的数据库文件,您将看到有一个名为“class”的列(属性)。

我们如何知道要使用哪个属性?好吧,shapefiles中的数据库记录存储在dbf文件中。您可以在电子表格程序(如openoffice.org的calc)或桌面地理信息系统软件(如qgis、thuban或arcview)中打开它。如果您的数据带有元数据(应该是!),您可以浏览该元数据文件以获取属性信息。您还可以使用“ogrinfo”在shapefiles中显示基本属性信息——回顾示例1.1(在“layer srs wkt:”后面的最后几行显示属性名称和类型)。

 

EXPRESSION

对于每个类,我们指定要使用的属性值。这是最简单的表达形式。表达式可能比这更复杂,允许计算正则表达式或逻辑表达式。请查看mapfile引用页,了解如何使用表达式。

 

 

Example 1.4: Labeling the Map

我们也可以在地图上添加标签…

MapServer有一个非常灵活的标签引擎。它支持本机位图和TrueType字体。TrueType支持字体缩放。标签的角度和位置可以定制…如果您花时间学习创建好标签所涉及的许多参数,您将获得信息丰富、美观的地图。

这是map文件的外观(例如1-4.map):

# 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 map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to 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-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also     # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # Just like CLASSITEM, LABELITEM defines the database attribute that you     # will be using to draw labels.  In this case, the values of the attribute     # "STATE" will be used to label the states polygons.    LABELITEM    "STATE"    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME 'States'      EXPRESSION 'land'      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR      232 232 232      END      # There can be labels in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple labels in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      # MapServer has a very flexible labeling system.  With that flexibility      # comes complexity, specially when using truetype fonts.  Please read       # through the LABEL section of the MapServer map file documentation at      # http://www.mapserver.org/mapfile for more information.      LABEL        COLOR 132 31 31        SHADOWCOLOR 218 218 218        SHADOWSIZE 2 2        TYPE TRUETYPE        FONT arial-bold        SIZE 12        ANTIALIAS TRUE        POSITION CL        PARTIALS FALSE        MINDISTANCE 300        BUFFER 4      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...
View Code

按对象划分的map文件结构如下所示:

这里我们介绍LABEL对象的几个参数:

FONTSET字体集

这里我们指定TrueType字体列表(或字体集)文件的完整路径。此文件列出了每个可用字体。有关详细信息,请参见文件本身和mapfile引用。fontset是地图对象的参数。

LABELITEM

这将指定要用于标记的数据属性,在本例中为“STATE”。labelitem是层对象的参数。

LABEL标签

标记标签对象的开头。标签对象可用于其他对象(即scaleBar对象)下。

COLOR颜色

在标签对象中,颜色指定标签文本的颜色。

SHADOWCOLOR阴影颜色

指定标签文本的阴影颜色。

SHADOWSIZE阴影大小

指定阴影大小。该值对应于x和y以像素为单位移动。所以,“2 2”是指两个像素宽两个像素高。

TYPE类型

在Label对象中,TYPE指定要使用的字体类型。我们可以选择TrueType或BitMap(内置字体)。我们选择TrueType。

FONT字体

如果将TYPE指定为TrueType,则需要指定要使用的字体。这里的值是字体列表文件中的“别名”。

SIZE尺寸

如果使用TrueType字体,则值为像素大小。如果是位图,可以说“小”或“大”。

ANTIALIAS

这将打开或关闭TrueType抗锯齿。请记住,值不是开或关,而是真或假。

POSITION位置

标签文本相对于标签点的位置。该值是垂直和水平位置的组合。垂直对齐有以下选项:C代表中心,U代表上部,L代表下部。对于水平对齐,您有以下选项:C代表中心,L代表左侧,R代表右侧。因此,要将标签文本与标签ID的中心对齐,需要使用值“cc”(中心)。或者如果你想把它放在身份证的左下角,你可以用LL。另一种方法是让MapServer决定标签的最佳位置。为此,您将使用值“auto”。

PARTIALS部分

告诉MapServer是否生成不完整的标签文本。这里的默认设置是不生成标签文本的片段。该值为真或假。

MINDISTANCE最小距离

这是重复标签之间的最小距离(像素)。看看如果增加或减少这个值会发生什么。

BUFFER缓冲器

每个标签的填充(像素)。这用于增强可读性。4个像素的缓冲区意味着在4个像素的范围内不会绘制任何标签。再次,改变看看它是如何工作的。

还可以创建与多边形层分离的标签。对ANNOTATION数据类型执行此操作。查看下一个示例的映射文件,了解如何实现这种标记。您将注意到“label”层中的类对象的颜色参数值为“-1-1-1”。负数告诉MapServer给这个类一个透明的颜色(标签ID不显示)。再次,使用这些值了解它如何影响地图。

 

 Example 1.5: Adding a Raster Layer

除了支持矢量数据(点、线、多边形和注释),MapServer还可以显示光栅数据。通过使用gdal库,mapserver可以输入和输出多种光栅格式。在4.x之前的版本中,光栅输入仅限于单层、灰度或索引彩色图像,而MapServer现在支持RGB和多光谱(多层)图像。此示例演示如何选择使用多光谱数据时要显示的图层。在使用RGB和多光谱图像时,可能会出现明显的性能问题。

因为MapServer5.x使用gd版本2.0.x库来生成输出图像,所以它也支持RGB(24位或真彩色)输出。因此,除了8位(索引颜色或灰度)PNG,您现在还可以使用PNG24(真颜色)进行输出。此示例使用PNG24作为ImageType。与RGB输入一样,使用PNG24时可能会出现明显的性能问题。

mapserver实际上也可以使用gdal生成输出图像,但这是另一个主题。如果您想了解更多信息,请查看mapfile引用中的outputformat对象。

这是映射文件的外观(例如1-5.map):

# 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      PNG24  EXTENT         -97.238976 41.619778 -82.122902 49.385620  SIZE           400 300  SHAPEPATH      "../data"  IMAGECOLOR     255 255 255  FONTSET        "../fonts/fonts.list"  SYMBOLSET      "../symbols/symbols35.sym"  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  #  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # CLASSITEM defines the non-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also     # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME 'States'      EXPRESSION 'land'      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR      232 232 232      END    END  END # States polygon layer ends here  # In addition to vector data (shapefiles are vector data), MapServer supports  # a host of raster formats.  In GIS world, one of the most common raster  # formats is GeoTIFF, a TIFF image with geospatial headers.  MapServer also  # supports JPEG, PNG, GIF, and other common formats.  Other raster formats  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,   # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.  Pretty much   # any raster format you can think of is probably supported, thanks to the  # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"  # or GOODLE?).  More information on GDAL is available at http://www.gdal.org.  #  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true  # color), and multispectral (images with more than 3 bands, like raw LandSat  # images) rasters.  LAYER # MODIS raster layer begins here    NAME         modis    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"    STATUS       OFF    TYPE         RASTER    PROCESSING   "BANDS=1,2,3"    OFFSITE      71 74 65  END # MODIS raster 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        SYMBOL     'line5'        COLOR      64 64 64        SIZE       1      END    END  END # States line layer ends here  # Labels can be defined in its own layer.  This is useful if, say, you want  # to label a polygon layer that's covered by another layer.  By keeping the  # label separate from the polygon and placing it near the bottom of the map  # file (so its drawn on, or near the, top), you can still see the label even  # though you might not be able to see the polygon.  It is also a good  # alternate to point symbols.  #  # A label layer is actually defined with ANNOTATION type (This is derived from   # points, Node IDs for lines, or polygon IDs).  LAYER # States label layer begins here    NAME         states_label    DATA         states_ugl    STATUS       OFF    TYPE         ANNOTATION    CLASSITEM    "CLASS"    # Just like CLASSITEM, LABELITEM defines the database attribute that you    # will be using to draw labels.  In this case, the values of the attribute    # "STATE" will be used to label the states polygons.    LABELITEM    "STATE"    CLASS      EXPRESSION 'land'      STYLE        COLOR      -1 -1 -1      END      # There can be labels in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple labels in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      # MapServer has a very flexible labeling system.  With that flexibility      # comes complexity, specially when using truetype fonts.  Please read       # through the LABEL section of the MapServer map file documentation at      # http://www.mapserver.org/mapfile for more information.      LABEL        COLOR 132 31 31        SHADOWCOLOR 218 218 218        SHADOWSIZE 2 2        TYPE TRUETYPE        FONT arial-bold        SIZE 12        ANTIALIAS TRUE        POSITION CL        PARTIALS FALSE        MINDISTANCE 300        BUFFER 4      END # end of label    END # end of class  END # States label layer ends here  # End of LAYER DEFINITIONS -------------------------------END # All map files must come to an end just as all other things must come to...
View Code

 按对象划分的map地图文件结构如下所示:

当您查看map地图文件时,您将看到新的图层对象被添加到区域polygon多边形图层的下面(后面)。为什么?mapserver以相反的顺序显示层——后进先出(lifo)。地图文件中定义的第一个图层绘制在地图的底部。

所以,如果我们画了state多边形层,它会在底部。因为光栅图层被绘制在上面,所以我们看不到它。这就是为什么第一层的状态值为off的原因。状态线图层定义在光栅图层的下方,以便在顶部绘制(您可以看到)。这就是我们将状态线层与状态多边形层分离的原因。当然,标签是在最上面。

MapServer可以根据其他图层的状态自动打开或关闭图层——比如说,当光栅图层打开时,希望关闭状态多边形图层。这是通过使用Requires参数来完成的。记住这一点,因为一旦开始创建自己的MapServer应用程序,您可能会想要使用它。

让我们看看mapfile中引入的新参数:

IMAGETYPE 图像类型

这不是新的,但值“png24”是。PNG24是PNG格式的24位或真彩色版本。mapserver现在拥有数百万个颜色组合,而不是仅限于输出图像的256种颜色组合。顺便说一下,试着把这个值改回png。请注意,使用这两种格式生成图像所需的时间。在选择真彩色和索引颜色时,要考虑生成图像所需的时间。

SYMBOLSET符号集

指向符号定义文件的路径。此文件中的符号由类对象中的符号参数引用。现在不需要,但我想我现在就把它扔到这里。更多信息,请参考地图文件参考和地图服务器的地图符号构造。

DATA数据“光栅/mod09a1203161_ugl_ll_8bit.tif”

在新添加的图层对象中,数据参数指向geotiff图像。与矢量数据集一样,MapServer支持多种光栅文件格式。这种支持是通过使用gdal库来实现的。有关MapServer支持的不同光栅格式的详细信息,以及有关在MapServer中使用光栅的一般性讨论,请阅读http://www.mapserver.org/input/graster.html上的光栅数据操作方法。

TYPE RASTER类型光栅

当使用光栅数据(图像)时,我们使用值光栅作为参数类型,而不是矢量数据的多边形、直线和点值以及标签ID的注释。

PROCESSING "BANDS=1,2,3"处理“波段=1,2,3”

在MapServer 4.x中,这个层对象参数是新的。处理关键字有很多值,但在本例中,我们使用它来选择要显示多光谱图像中的波段。这里的值是将传递到gdal库的字符串。有关这一点的文档目前是最少的,但有关使用processing关键字的更多示例,请参阅mapfile参考。

OFFSITE

此参数告诉MapServer要渲染为背景(或忽略)的像素值。您可以使用图像处理或图像操作程序(例如,Imagine、Photoshop、Gimp)获取像素值。

要在使用RGB图像而不是索引颜色图像时比较地图创建速度,请替换地图文件中的以下行:

DATA "raster/mod09a12003161_ugl_ll_8bit.tif"STATUS DEFAULT TYPE RASTER PROCESSING "BANDS=1,2,3" OFFSITE 71 74 65

为:

DATA "raster/mod09a12003161_ugl_ll_idxa.tif"STATUS DEFAULT TYPE RASTEROFFSITE 70 74 66

另外,尝试将imagetype从png24更改为png。

 

 

 

Example 1.6: Defining Projections and Extents

我们可以将我们的数据从几乎任何投影重新投影到几乎任何…是的,看看!

哇!这里发生了什么?

你刚刚经历了一次on-the-fly的再投射。在map文件中定义投影对象时,MapServer将图层和投影信息传递给执行重投影的proj.4库。有关proj.4库的更多信息,请访问http://trac.osgeo.org/proj/。

这个例子试图为MapServer中的投影支持提供一些帮助。

这是map文件的外观(例如1-6.map):

# 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      PNG24  # EXTENT 199949.651166 -371954.772084 1472121.6862 632767.19157  EXTENT       201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA  #EXTENT         -97.5 41.619778 -82.122902 49.38562 # Geographic  SIZE           400 300  SHAPEPATH      "../data"  SYMBOLSET      "../symbols/symbols35.sym"  FONTSET        "../fonts/fonts.list"  # The projection object is typically used within the map and the layer  # objects. You only define it once within the map object and this definition  # becomes your output projection--MapServer will 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 them into your output projection.    # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not   # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  #  # This is the output PROJECTION definition ------  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal Equal-Area    # projection for the U.S.    #    # "init=epsg:2163"  END # End of the output Projection definition ---  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  #  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # Here's an example of the input projection definition.    # EPSG:4326 is code for geographic (latlong) projection    # using the WGS84 datum.    #    # PROJECTION objects within the LAYER object define the input    # projection--this is the native projection of your data.    PROJECTION      "init=epsg:4326"    END    # CLASSITEM defines the non-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also     # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME 'States'      EXPRESSION 'land'      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR      232 232 232      END    END  END # States polygon layer ends here  # In addition to vector data (shapefiles are vector data), MapServer supports  # a host of raster formats.  In GIS world, one of the most common raster  # formats is GeoTIFF, a TIFF image with geospatial headers.  MapServer also  # supports JPEG, PNG, GIF, and other common formats.  Other raster formats  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,   # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.  Pretty much   # any raster format you can think of is probably supported, thanks to the  # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"  # or GOODLE?).  More information on GDAL is available at http://www.gdal.org.  #  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true  # color), and multispectral (images with more than 3 bands, like raw LandSat  # images) rasters.  LAYER # MODIS raster layer begins here    NAME         modis    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"    STATUS       OFF    TYPE         RASTER    PROCESSING   "BANDS=1,2,3"    OFFSITE      71 74 65    PROJECTION      "init=epsg:4326"    END  END # MODIS raster layer ends here  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      64 64 64        SIZE       1      END    END  END # States line layer ends here  LAYER # States label layer begins here    NAME         states_label    DATA         states_ugl    STATUS       OFF    TYPE         ANNOTATION    PROJECTION      "init=epsg:4326"    END        CLASSITEM    "CLASS"    # Just like CLASSITEM, LABELITEM defines the database attribute that you    # will be using to draw labels.  In this case, the values of the attribute    # "STATE" will be used to label the states polygons.    LABELITEM    "STATE"    CLASS      EXPRESSION 'land'      STYLE        COLOR      -1 -1 -1      END      # There can be labels in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple labels in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      # MapServer has a very flexible labeling system.  With that flexibility      # comes complexity, specially when using truetype fonts.  Please read       # through the LABEL section of the MapServer map file documentation at      # http://www.mapserver.org/mapfile for more information.      LABEL        COLOR 132 31 31        SHADOWCOLOR 218 218 218        SHADOWSIZE 2 2        TYPE TRUETYPE        FONT arial-bold        SIZE 12        ANTIALIAS TRUE        POSITION CL        PARTIALS FALSE        MINDISTANCE 300        BUFFER 4      END # end of label    END # end of class  END # States label layer ends here  # End of LAYER DEFINITIONS -------------------------------END # All map files must come to an end just as all other things must come to...
View Code

在我们的地图文件中,您可能注意到的第一件事是原始范围已被注释掉,新的范围值看起来与纬度和经度值不同。另外,我们在顶部附近和每个Layer层中添加了一个投影对象。

让我们看看新的对象和参数:

EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514

我们提供给MapServer的范围需要与输出投影使用相同的单位。由于兰伯特方位角的等面积单位是米,我们必须给新的范围以米。我们可以使用arcview或其他一些gis包计算新的范围,也可以使用proj.4的cs2cs实用程序。下面的命令可用于重新投影原始范围值:

cs2cs +proj=latlong +datum=WGS84 +to +proj=laea +ellps=clrk66 +lat_0=45 +lon_0=-100

键入命令后,输入西南坐标对(左下角坐标),用空格分隔:-97.5 41.619778

“cs2cs”实用程序给出的值:

208398.01       -372335.44 0.000

 然后键入东北坐标对(右上角坐标),再次用空格分隔:-82.122902 49.38562,并返回以下值:

1285308.08      632638.93 0.000

您会注意到“cs2cs”返回一组三个值。您可以忽略第三个值0.000,因为它表示高度(我们不使用)。无论如何,我们不能将范围表示为:

EXTENT 208398.01 -372335.44 1285308.08 632638.93

但这与上面的范围不符,你说。好吧,这就是你回绝的时候通常会发生的事情——地图不一定像你想象的那样居中。你可以绕着它转,向左走几千米,向右再加几米。或者,您可以使用图形化的地理信息系统包来提供范围。以下是使用ArcView获取范围的说明。

MapServer可以通过两种方式获取投影定义。第一个显示在映射文件的输出投影对象(第一个投影块)中。这是将参数传递到proj.4库的传统方法。另一种方法是使用EPSG代码。这些代码是欧洲石油调查集团(EPSG)定义的标准投影代码(或空间参考标识符)。在我们的兰伯特方位角等面积投影,它有一个代码“2163”。如果在投影后注释掉这四行,并取消对行“init=epsg:2163”的注释,这将向项目4提供相同的信息。如果您想了解EPSG代码的更多信息,请查看“/usr/local/share/proj/epsg”或“c:/proj/nad/epsg”(MS4W中的“/ms4W/proj/nad”)。此外,请访问EPSG网站http://www.epsg.org。

如果您需要了解有关投影的更多信息,请查看以下链接:

你可以通过在网上搜索“地图投影”找到更多信息。

 

 

 Example 1.7: Adding OGC WMS Layers

 我们可以使用来自互联网上其他地图服务器的层(只要它们是WMS服务器)。

MapServer的另一个令人兴奋的特性是它能够使用来自其他地图服务器的层。在这种情况下,MapServer应用程序将成为WMS(或WFS)客户机。mapserver还可以将map文件中的层共享(或服务于其他地图服务器)。这使应用程序成为一个WMS(或WFS)服务器。什么是WMS或WFS?这些是由开放地理空间联盟(OGC)发布的“基于Web的互操作性服务”规范。

wms代表web map服务,wfs代表web feature服务。简单来说,这两种规范的区别在于,WMS使用Web光栅格式(PNG、GIF、JPEG)共享层,而WFS使用地理标记语言GML。第三个OGC互操作性规范是Web Coverage Services规范或WCS——MapServer仅在服务器级别支持此规范。要查找有关WMS、WFS和WCS的更多信息,请访问OGC的网站,并查找OGC实现规范或OGC抽象规范。MapServer网站还提供了这些规范的文档。

此示例演示如何在map地图文件中添加WMS层。

这是map文件的外观(示例1-7.map):

# 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      PNG24  EXTENT        201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA  #EXTENT         -97.5 41.619778 -82.122902 49.38562 # Geographic  SIZE           400 300  SHAPEPATH      "../data"  SYMBOLSET      "../symbols/symbols35.sym"  FONTSET        "../fonts/fonts.list"  # The projection object is typically used within the map and the layer  # objects. You only define it once within the map object and this definition  # becomes your output projection--MapServer will 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 them into your output projection.  # If no projection is defined within the layer object, MapServer assumes  # your input projection is the same as your output projection.  This is not  # a required object unless you're creating a map file that supports one of  # the OGC interoperability web services specifications (WMS/WFS/WCS).  #  # This is the output PROJECTION definition ------  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal Equal-Area    # projection for the U.S.    "init=epsg:2163" END    # The web object is defined at the level below the map object.  All  # web-related parameters (I interchange "parameters" and "keyword/value  # pairs" quite frequently, sorry about that) are defined in this object.  WEB    IMAGEPATH "/ms4w/tmp/"    IMAGEURL  "/tmp/"  END  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  #  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # Here's an example of the input projection definition.    # EPSG:4326 is code for geographic (latlong) projection    # using the WGS84 datum.    #    # PROJECTION objects within the LAYER object define the input    # projection--this is the native projection of your data.    PROJECTION      "init=epsg:4326"    END    # CLASSITEM defines the non-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database    # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also    # called themes) used in this layer--land and water.  CLASSITEM is used in    # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # The class object is defined within the layer object.  You can define as    # many classes as you need (well, there are limits as with layers, but it's    # senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      NAME 'States'      EXPRESSION 'land'      # There are styles in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple styles in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      STYLE        COLOR      232 232 232      END    END  END # States polygon layer ends here  # In addition to vector data (shapefiles are vector data), MapServer supports  # a host of raster formats.  In GIS world, one of the most common raster  # formats is GeoTIFF, a TIFF image with geospatial headers.  MapServer also  # supports JPEG, PNG, GIF, and other common formats.  Other raster formats  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,   # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.  Pretty much   # any raster format you can think of is probably supported, thanks to the  # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"  # or GOODLE?).  More information on GDAL is available at http://www.gdal.org.  #  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true  # color), and multispectral (images with more than 3 bands, like raw LandSat  # images) rasters.  LAYER # MODIS raster layer begins here    NAME         modis    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"    STATUS       OFF    TYPE         RASTER    PROCESSING   "BANDS=1,2,3"    OFFSITE      71 74 65    PROJECTION      "init=epsg:4326"    END  END # MODIS raster layer ends here  # MapServer can consume (in ESRI parlance) layers from other map servers as  # long as those servers are Web Mapping Service (WMS) providers.  WMS is a   # web service specification from Open Geospatial Consortium (OGC) and is  # intended to be an interoperability standard for web mapping applications.    # This allows us to display layers we don't usually have (or can't store in   # our computers due to space limitations).  The downside is that we have to   # depend on some other server to display our layer, and that server can be   # down when you really need it.  The cool thing is that JPL has a WMS server   # that serves out MODIS and LandSat maps for the whole world--try storing   # those datasets on your computer!  LAYER # MODIS WMS map from JPL    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" "modis"      "wms_server_version" "1.1.1"      "wms_format" "image/jpeg"    END    PROJECTION      "init=epsg:4326"    END  END # Modis WMS image ends here  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 # States label layer begins here    NAME         states_label    DATA         states_ugl    STATUS       OFF    TYPE         ANNOTATION    PROJECTION      "init=epsg:4326"    END        CLASSITEM    "CLASS"    # Just like CLASSITEM, LABELITEM defines the database attribute that you    # will be using to draw labels.  In this case, the values of the attribute    # "STATE" will be used to label the states polygons.    LABELITEM    "STATE"    CLASS      EXPRESSION 'land'      STYLE        COLOR      -1 -1 -1      END      # There can be labels in a class, just like there are classes in a layer,      # just like there are layers in a map.  You can define multiple labels in      # a class just as you can define multiple classes in a layer and multiple      # layers in a map.      # MapServer has a very flexible labeling system.  With that flexibility      # comes complexity, specially when using truetype fonts.  Please read      # through the LABEL section of the MapServer map file documentation at      # http://www.mapserver.org/mapfile for more information.      LABEL        COLOR 132 31 31        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
View Code

让我们来看看WMS层:

LAYER #来自JPL的MODIS WMS地图

标记WMS Layer图层对象的开始。

NAME modis_jpl

The LAYER 标识符.

TYPE RASTER 类型光栅

因为这个WMS层是一个图像,所以我们使用光栅作为层类型。

OFFSITE 0 0 0

Ignore the black background color忽略黑背景色

STATUS OFF

Turn this layer off by default.默认关掉图层

CONNECTIONTYPE WMS WMS连接类型

要使用的层连接类型。默认值是本地的——如果我们想显式定义,我们将向地图文件中的所有其他向量和光栅层添加CONNECTIONTYPE LOCAL 。相反,我们只定义外部的连接类型。WMS是一个外部数据层,来自另一个地图服务器。

连接“http://mapus.jpl.nasa.gov/wms.cgi?”

允许我们从另一个服务器“获取”数据的连接字符串。对于WMS连接,这是一个URL。如果我们使用PostGIS数据库,它将是一个SQL语句。请注意,字符串必须在映射文件中的一行中。

METADATA 元数据

标记WMS层的元数据对象的开头。MapServer使用此对象中定义的参数以及上面的连接参数来形成对WMS服务器的有效WMS请求。

"wms_srs" "epsg:4326"

WMS投影。有时,WMS服务器支持多个投影。如果是这种情况,您可能希望在输出投影中请求映射。不幸的是,JPL服务器不支持这种投影。

"wms_name" "modis"

WMS层名称。这就像添加参数“layers=modis”。

"wms_server_version" "1.1.1"

服务器符合的WMS版本。MapServer遵循1.1.1版。

"wms_format" "image/jpeg"

T我们期望从WMS服务器接收的图像格式。您可以尝试将该值替换为“image/png”或其他内容。

END

标记METADATA元数据对象的结尾

要了解有关向应用程序添加WMS层的更多信息,请访问WMS客户端操作说明文档。

 除了添加WMS图层对象,地图下还有一个新对象。这是Web对象。Web对象中有两个参数:

imagepath'/data/tmp/'

指向Web可访问临时目录的绝对本地路径。运行Web服务器进程的用户应该能够写入此目录。确保路径末尾包含斜线(/)。(您的IMAGEPATH可能如下所示:“/home/apache/htdocs/tmp/”或“c:/inetpub/wwwroot/tmp/”。

IMAGEURL '/tmp/'

这是相对于Web服务器的根目录显示ImagePath的方式。如果必须为此键入完整的URL,它将是“http://terrasip.gis.umn.edu/tmp/”。确保路径末尾包含斜线(/)。

最后,在MAP对象中,我添加了一个新参数:NAME。这是MAP对象的标识符。MapServer将此作为它创建的所有图像的前缀,并将其转储到“tmp”目录。在这一点上不需要它,但是拥有它也不会带来伤害。

如果要将数据层共享到其他地图服务器,则需要在地图对象内以及要共享的每个图层对象内添加元数据对象。从另一台服务器添加的所有WMS层将自动层叠,并且也将对其他服务器可用。要了解有关如何使MapServer应用程序成为WMS服务器的更多信息,请阅读。还存在用于配置MapServer应用程序以支持WFS标准的文档,无论是作为WFS服务器还是作为WFS客户机。

 

 

 

Example 1.8: Changing the Map's Output Format

MapServer可以输出各种格式,如PDF和geotiff。

 

根据您选择的格式,图像可能不会显示在浏览器上。如果链接无法显示在浏览器上,请右键单击上面的图形,并将链接保存为您在地图文件中指定的任何格式。

# 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  NAME           EX1.8_  EXTENT         201621.496941 -294488.285333 1425518.020722 498254.511514 # LAEA  #EXTENT         -97.5 41.619778 -82.122902 49.38562 # Geographic  SIZE           400 300  IMAGECOLOR     255 255 255  SHAPEPATH      "../data"  SYMBOLSET      "../symbols/symbols35.sym"  FONTSET        "../fonts/fonts.list"  IMAGETYPE PNG24  OUTPUTFORMAT    NAME png    DRIVER "GD/PNG"    MIMETYPE "image/png"    IMAGEMODE PC256    EXTENSION "png"  END  OUTPUTFORMAT    NAME png24    DRIVER "GD/PNG"    MIMETYPE "image/png"    IMAGEMODE RGBA    EXTENSION "png"  END  OUTPUTFORMAT    NAME jpeg    DRIVER "GD/JPEG"    FORMATOPTION "QUALITY=75"    MIMETYPE "image/jpeg"    IMAGEMODE RGB    EXTENSION "jpg"  END  OUTPUTFORMAT    NAME GTiff    DRIVER "GDAL/GTiff"    MIMETYPE "image/tiff"    IMAGEMODE RGB    EXTENSION "tif"  END  #OUTPUTFORMAT  #  NAME pdf  #  MIMETYPE "application/x-pdf"  #  DRIVER pdf  #  #FORMATOPTION "OUTPUT_TYPE=RASTER" # not mandatory but needed for WMS layer  #END  OUTPUTFORMAT    NAME AGG    DRIVER "AGG/PNG"    IMAGEMODE RGB  END  OUTPUTFORMAT    NAME AGGA    DRIVER "AGG/PNG"    IMAGEMODE RGBA  END  OUTPUTFORMAT    NAME AGGJ    DRIVER "AGG/JPEG"    IMAGEMODE RGB  END  # The web object is defined at the level below the map object.  All  # web-related parameters (I interchange "parameters" and "keyword/value  # pairs" quite frequently, sorry about that) are defined in this object.  WEB    IMAGEPATH '/ms4w/tmp/ms_tmp/'    IMAGEURL  '/ms_tmp/'  END  # The projection object is typically used within the map and the layer  # objects. You only define it once within the map object and this definition  # becomes your output projection--MapServer will 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 them into your output projection.    # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not  # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  #  # This is the output PROJECTION definition ------  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal Equal-Area    # projection for the U.S.    "init=epsg:2163"  END  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  #  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # Here's an example of the input projection definition.    # EPSG:4326 is code for geographic (latlong) projection    # using the WGS84 datum.    #    # PROJECTION objects within the LAYER object define the input    # projection--this is the native projection of your data.    PROJECTION      "init=epsg:4326"    END    # CLASSITEM defines the non-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also    # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    # The class object is defined within the layer object.  You can define as    # many classes as you need but it is good cartographic practice to limit     # classes to 8 to 10 per layer. (There are also limits as with layers and     # it's senseless to define more than ten on a "normal" layer.  There are    # situations, however, where you might have to do it.)    CLASS      EXPRESSION 'land'      STYLE        SYMBOL     0        COLOR      232 232 232      END    END  END # States polygon layer ends here  # In addition to vector data (shapefiles are vector data), MapServer supports  # a host of raster formats.  In GIS world, one of the most common raster  # formats is GeoTIFF, a TIFF image with geospatial headers.  MapServer also  # supports JPEG, PNG, GIF, and other common formats.  Other raster formats  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,   # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.  Pretty much   # any raster format you can think of is probably supported, thanks to the  # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"  # or GOODLE?).  More information on GDAL is available at http://www.gdal.org.  #  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true  # color), and multispectral (images with more than 3 bands, like raw LandSat  # images) rasters.  LAYER # MODIS raster layer begins here    NAME         modis    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"    STATUS       OFF    TYPE         RASTER    PROCESSING   "BANDS=1,2,3"    OFFSITE      71 74 65    PROJECTION      "init=epsg:4326"    END  END # MODIS raster layer ends here  LAYER # MODIS WMS map from JPL    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" "modis"      "wms_server_version" "1.1.1"      "wms_format" "image/jpeg"    END    PROJECTION      "init=epsg:4326"    END  END # Modis WMS image ends here    LAYER # States line layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         LINE    PROJECTION      "init=epsg:4326"    END    CLASSITEM    "CLASS"    CLASS      EXPRESSION 'land'      STYLE        #SYMBOL     'line1'        COLOR      32 32 32        #SIZE       1      END    END  END # States line layer ends here  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    255 255 255        TYPE     TRUETYPE        FONT     arial-bold        SIZE     12        ANTIALIAS    TRUE        POSITION     CL        PARTIALS     FALSE        MINDISTANCE  300        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
View Code

我们的mapfile现在包含一个新的对象outputformat。此对象在map对象内定义,并与imagetype关键字一起使用。根据您使用MapServer编译的库,您可以有几个输出格式选择——gd库提供PNG(8位和24位)、GIF、JPEG和WBMP;gdal库是许多MapServer输入格式的源,也可以向PNG、JPEG、TIFF/GEOTIFF和其他RASTE提供输出。R格式;pdflib库提供PDF输出;ming库提供闪存输出。查看outputformat对象并通过更改mapfile上的imagetype关键字进行实验。输出格式的名称应用作imagetype值(例如:imagetype png或imagetype png24)。

请在以下位置查阅outputformat对象引用:

http://www.mapserver.org/mapfile/outputformat.html outputformat

 

 

 

Example 1.9: Interactive Maps and the Browse Mode

上面的地图是在“地图”模式下创建的。这是一个静态地图(单击它不会改变)。

 

这个动态地图是在“浏览”模式下生成的。点击地图上的任何一点,看看会发生什么。

这两个地图都使用相同的mapfiile文件定义。区别在于第二个地图(动态创建的地图)依赖于HTML表单进行交互。如果你看一下这个页面是如何与前一个页面链接的,你会发现它与前一个例子不一样。用mapserver的术语来说,这个页面就是一个HTML模板。您将在第2部分中了解有关HTML模板的更多信息。

查看此页面中的“表单”块(右键单击浏览器并选择“查看源代码”或类似内容):

View Code

每当用户单击地图时,此块执行mapserver cgi程序(“/cgi-bin/mapserv.exe”)。地图实际上是另一种形式的“输入”,在这里用行表示:

 方括号([map]、[mapext]和[img])中的项称为mapserver标记——这些是mapserver cgi变量,在重新加载时会被mapserver cgi程序替换。标记[map]是mapfile路径的一个占位符,因此在运行mapserver时,它被替换为“/ms4w/apps/tutorial/htdocs/example1-9.map”。标记[mapext]替换为当前地图范围“91734.994981-533247.003346 1432483.085284 471473.996656”,并且[img]标记替换为mapserver cgi程序创建的图像路径,“/ms_tmp/ex1.9_156222312833540.png”。继续检查映像路径(/ms4w/tmp/)是否存在此映像。(这些参数是在.map文件里获取的吗?:)

值为“browse”的隐藏变量“mode”告诉CGI程序需要在“tmp”目录中创建和转储图像。然后,这个图像被引用为[img],这就是您在浏览器上看到的。

现在,看看地图文件:

# 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  NAME           EX1.9_  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"  # The web object is defined at the level below the map object.  All  # web-related parameters (I interchange "parameters" and "keyword/value  # pairs" quite frequently, sorry about that) are defined in this object.  WEB    TEMPLATE  'example1-9.html'    IMAGEPATH '/ms4w/tmp/ms_tmp/'    IMAGEURL  '/ms_tmp/'  END  # The projection object is typically used within the map and the layer  # objects. You only define it once within the map object and this definition  # becomes your output projection--MapServer will 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 them into your output projection.    # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not   # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  #  # This is the output PROJECTION definition ------  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal Equal-Area    # projection for the U.S.    "init=epsg:2163"  END  # Layer objects are defined beneath the map object.  You need at least one  # layer defined in your map file before you can display a map...  You can  # define as many layers as you'd like although 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 application to need more than 100 layers in  # your application.  #  # Start of LAYER DEFINITIONS ---------------------------------------------  LAYER # States polygon layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    # Here's an example of the input projection definition.    # EPSG:4326 is code for geographic (latlong) projection    # using the WGS84 datum.    #    # PROJECTION objects within the LAYER object define the input    # projection--this is the native projection of your data.    PROJECTION      "init=epsg:4326"    END    # CLASSITEM defines the non-spatial attribute 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 different for each data format).  In this    # example the shapefile states_ugl has an associated database     # (states_ugl.dbf) that contains an attribute called "CLASS".  You will be    # using two values in the CLASS attribute to separate the classes (also     # called themes) used in this layer--land and water.  CLASSITEM is used in     # association with the EXPRESSION parameter in the CLASS object.  See below.    CLASSITEM    "CLASS"    CLASS      EXPRESSION 'land'      STYLE        SYMBOL     0        COLOR      232 232 232      END    END  END # States polygon layer ends here  # In addition to vector data (shapefiles are vector data), MapServer supports  # a host of raster formats.  In GIS world, one of the most common raster  # formats is GeoTIFF, a TIFF image with geospatial headers.  MapServer also  # supports JPEG, PNG, GIF, and other common formats.  Other raster formats  # supported by MapServer include ESRI Arc/Info grid, HDF and HDF-EOS, NetCDF,   # Generic raster binaries, OGC Web Map Service (WMS) layers, etc.  Pretty much   # any raster format you can think of is probably supported, thanks to the  # impressive Geospatial Data Abstraction Library (GDAL, pronounced "GOODALL"  # or GOODLE?).  More information on GDAL is available at http://www.gdal.org.  #  # MapServer 4.x can read and display bitmapped (like GIFs), RGB/A (true  # color), and multispectral (images with more than 3 bands, like raw LandSat  # images) rasters.  LAYER # MODIS raster layer begins here    NAME         modis    DATA         "raster/mod09a12003161_ugl_ll_8bit.tif"    STATUS       OFF #DEFAULT    TYPE         RASTER    PROCESSING   "BANDS=1,2,3"    OFFSITE      71 74 65    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 #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 # States line layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         LINE    PROJECTION      "init=epsg:4326"    END    CLASSITEM    "CLASS"    CLASS      EXPRESSION 'land'      STYLE        SYMBOL     'line5'        COLOR      32 32 32        SIZE       1      END    END  END # States line layer ends here  LAYER # States label layer begins here    NAME         states    DATA         states_ugl    STATUS       OFF    TYPE         POLYGON    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 # All map files must come to an end just as all other things must come to...# End of section 1, dude!
View Code

只有一件事被添加到map文件中:

TEMPLATE 'example1-9.html'

这将告诉MapServer使用页面“example1-9.html”作为模板文件。MapServer将处理此文件并替换它遇到的标记,然后将其发送到Web浏览器。本教程接下来的两个部分就是这样工作的。

这标志着第1节的结束。我希望您在本节中留下足够的知识,了解如何在MapServer映射文件中设置内容。在创建自己的映射文件和应用程序时,我不能过分强调保持MapServer映射文件引用打开的重要性。没有它,我就不会在这个教程中走得太远。

 

 

 

 Section 2: CGI variables and the User Interface

 到目前为止,我们只在创建地图时查看了地图文件。在创建Web地图应用程序时,我们通常打算制作用户(应用程序的用户)可以交互更改的映射。也就是说,用户应该能够更改地图的内容(或其中的信息)。为了实现这种交互性,我们使用mapserver HTML模板。

MapServer HTML模板本质上是一个HTML文件,带有一些特定于MapServer的标记——这些标记是MapServer CGI变量带括在方括号“[]”中。当mapserver cgi程序处理一个应用程序时,它首先解析查询字符串和mapfile并生成必要的输出。其中一些输出将需要写入HTML模板文件,您还必须使用web template关键字(或单独的HTML初始化文件)在mapfile中指定该文件。CGI程序将用适当的值替换HTML模板中的所有变量,然后再将其发送回Web浏览器。如果要在Web浏览器上直接查看HTML模板,则不会呈现任何映射,而是会得到空白图像和其他垃圾。

MapServer为Web映射提供了几个变量——您在示例1.9中看到的“img”变量只是一个示例。最初作为绘图接口的一部分设计的核心CGI变量很少,但实际上所有mapfile参数都可以定义为变量。CGI变量的最终参考可在http://www.mapserver.org/cgi/index.html上找到。

我们还可以定义自己的变量——mapserver将把它传递给我们的应用程序。例如,我们可以创建一个名为“root”的变量来表示本教程的根目录——“root”的值将是“/tutorial”。当mapserver cgi程序处理我们的html模板时,它将用“/tutorial”替换他“[根]”标记的每个实例。您将在下面的每个示例中看到这一点。

所以,让我们为我们的应用程序构建一个交互式界面…

Example 2.1 - Pan and Zoom Controls

示例2.1-平移和缩放控件

Web地图应用程序的用户应该能够在地图上平移和缩放…

查看地图文件:

# 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 parameters via the web interface, you  # need to define a TEMPLATEPATTERN.  This is required for security reasons.  # Since the example filenames in section 2 begin with "example2" (as in  # example2-1.html or example2-2.html), you can use it as the pattern.    # The template pattern is a regular expression used by MapServer to match the   # value of map_web_template variable against.  TEMPLATEPATTERN 'example2*'  # The web object is defined at the level below the map object.  All   # web-related parameters (I interchange "parameters" and "keyword/value   # pairs" quite frequently, sorry about that) are defined in this object.  WEB    TEMPLATE  'to be replaced by map_web_template variable in section2.html'    IMAGEPATH '/ms4w/tmp/ms_tmp/'    IMAGEURL  '/ms_tmp/'  END # Every object in MapServer must have an END.;)    # The projection object is typically used within the map and the layer   # objects. You only define it once within the map object and this definition   # becomes your output projection--MapServer will 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 them into your output projection.  # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not  # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal 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 a reference map for your mapping   # application.  This typically involves defining a small image that covers   # the entire area of the map and defining a box that represents the current   # view on in relation to the entire area.  REFERENCE    IMAGE '../images/ugl_ref1.png' # The reference image    SIZE 155 105 # The size of the reference image in pixels    EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units    STATUS ON    MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels    MAXBOXSIZE 150 # The maximum size of the reference box, in pixels    COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent    OUTLINECOLOR 128 0 0 # The reference box outline color     MARKERSIZE 8 # The size of the point marker    MARKER 'star' # The marker symbol  END    # A scalebar object is defined one level below the map object.  This object   # controls how a scalebar is drawn by MapServer.  Scalebars can be embedded   # in the map itself or can be created as a separate 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 the map 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 layer you define (right after this   # comment), will be drawn at the bottom.  Here's my rule: rasters and   # polygons are defined first, followed by the line 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 projection definition.    # 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 the layer object.  You can define as    # many classes as you need (well, there are limits, but it's senseless to     # define more than ten on a "normal" layer.  There are situations,     # 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 POLYGON    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 POLYGON    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         POLYGON    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
View Code

与第1节中的映射一样,我们通过调用mapserv(“/cgi-bin/mapserv.exe”)初始化应用程序。并将我们的mapfile路径和其他参数(“map=/ms4w/apps/tutorial/htdocs/example2-1.map&amp;mode=browse”)传递给它。所以这个页面有一个来自第2节页面的链接,如下所示:

这次我们使用“浏览”模式而不是“地图”。浏览模式告诉mapserv在我们的“/tmp/”目录上创建一个映射(一个图像)。图像路径和名称由名称为“img”的mapserv引用。因此,当mapserv解析我们的HTML模板时,它将用正确的图像路径替换“[img]”/ms_tmp/ex2_156231592315176.png。

你可以用这张地图做一些事情。首先,您可以单击图像的任何部分,地图将刷新并使您单击的点居中。这是平移。如果单击“地图控件”下拉框,可以选择“放大”或“缩小”值。如果将其设置为“放大2倍”,然后单击地图的任何部分,地图将刷新、放大,并以单击的点为中心。反之,如果你缩小。当选择“放大”或“缩小”值并单击“刷新”按钮时,地图将刷新并放大或缩小上一个地图的中心。您可以随时使用“刷新”按钮刷新地图。

缩放/平移控件使用内部mapserver cgi变量。此示例演示如何使用“zoom”变量。缩放值决定放大或缩小的距离。如果值为“0”,则MapServer将根据用户的鼠标单击重新输入图像。如果该值大于“0”,则CGI程序放大(地图的当前比例乘以缩放值)。如果是负数,那么CGI程序会缩小(将当前比例除以缩放值)。其他可用于控制缩放和平移的变量有“zoomdir”和“zoomsize”。这两个变量的作用与“缩放”差不多——“zoomdir”控制缩放方向,“zoomsize”控制放大或缩小的距离。请查看osgeo库或mapserver wiki上的其他示例,以获取其他缩放/平移控制选项。

尝试将“地图模式”从“浏览”更改为“地图”。单击刷新时会发生什么?记住,当我们使用“模式=映射”时,mapserver会返回一个静态映射…它忽略HTML模板,只将映射图像直接流式传输到浏览器。

尽管添加了更多的数据层,但它仍然与第一节中的映射文件相似。我没有什么新的东西可以解释这个地图文件,但是如果你对一些新的关键字感兴趣,请查阅地图文件参考页。

现在,看看HTML模板文件。您会注意到这实际上是一个调用mapserver cgi程序的HTML表单。因为它是一个表单,所以您可以使用单选按钮和复选框以及下拉框来实现您的界面。不要觉得受这个例子的限制——有创造力是件好事。;)有关详细信息,请查看HTML模板引用页。

  

……他们还应该能够打开和关闭地图上的图层。
示例2.2-层控制

能够打开和关闭地图层是Web映射应用程序的标准功能。使用表单对象作为控件有很多方法可以实现这一点。您可以使用下拉框/菜单、复选框和/或单选按钮。在本例中,您将看到如何使用复选框和放置框实现层选择。

这里是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 parameters via the web interface, you  # need to define a TEMPLATEPATTERN.  This is required for security reasons.  # Since the example filenames in section 2 begin with "example2" (as in  # example2-1.html or example2-2.html), you can use it as the pattern.    # The template pattern is a regular expression used by MapServer to match the   # value of map_web_template variable against.  TEMPLATEPATTERN 'example2*'  # The web object is defined at the level below the map object.  All   # web-related parameters (I interchange "parameters" and "keyword/value   # pairs" quite frequently, sorry about that) are defined in this object.  WEB    TEMPLATE  'to be replaced by map_web_template variable in section2.html'    IMAGEPATH '/ms4w/tmp/ms_tmp/'    IMAGEURL  '/ms_tmp/'  END # Every object in MapServer must have an END.;)    # The projection object is typically used within the map and the layer   # objects. You only define it once within the map object and this definition   # becomes your output projection--MapServer will 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 them into your output projection.  # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not  # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal 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 a reference map for your mapping   # application.  This typically involves defining a small image that covers   # the entire area of the map and defining a box that represents the current   # view on in relation to the entire area.  REFERENCE    IMAGE '../images/ugl_ref1.png' # The reference image    SIZE 155 105 # The size of the reference image in pixels    EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units    STATUS ON    MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels    MAXBOXSIZE 150 # The maximum size of the reference box, in pixels    COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent    OUTLINECOLOR 128 0 0 # The reference box outline color     MARKERSIZE 8 # The size of the point marker    MARKER 'star' # The marker symbol  END    # A scalebar object is defined one level below the map object.  This object   # controls how a scalebar is drawn by MapServer.  Scalebars can be embedded   # in the map itself or can be created as a separate 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 the map 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 layer you define (right after this   # comment), will be drawn at the bottom.  Here's my rule: rasters and   # polygons are defined first, followed by the line 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 projection definition.    # 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 the layer object.  You can define as    # many classes as you need (well, there are limits, but it's senseless to     # define more than ten on a "normal" layer.  There are situations,     # 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 POLYGON    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 POLYGON    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         POLYGON    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
View Code

注意图层的STATUS已经被改为OFF,除了“States”多边形背景。

状态背景保留为默认设置,因此在绘制地图时,如果不打开任何图层,则始终会显示某些内容。应用程序的用户应该能够控制打开或关闭哪些层。

如果您查看HTML模板的源代码,您将了解mapserv如何打开/关闭层。

 

地图应始终包含一个scaleBar。
示例2.3-添加scaleBar

 这里是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 parameters via the web interface, you  # need to define a TEMPLATEPATTERN.  This is required for security reasons.  # Since the example filenames in section 2 begin with "example2" (as in  # example2-1.html or example2-2.html), you can use it as the pattern.    # The template pattern is a regular expression used by MapServer to match the   # value of map_web_template variable against.  TEMPLATEPATTERN 'example2*'  # The web object is defined at the level below the map object.  All   # web-related parameters (I interchange "parameters" and "keyword/value   # pairs" quite frequently, sorry about that) are defined in this object.  WEB    TEMPLATE  'to be replaced by map_web_template variable in section2.html'    IMAGEPATH '/ms4w/tmp/ms_tmp/'    IMAGEURL  '/ms_tmp/'  END # Every object in MapServer must have an END.;)    # The projection object is typically used within the map and the layer   # objects. You only define it once within the map object and this definition   # becomes your output projection--MapServer will 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 them into your output projection.  # If no projection is defined within the layer object, MapServer assumes   # your input projection is the same as your output projection.  This is not  # a required object unless you're creating a map file that supports one of   # the OGC interoperability web services specifications (WMS/WFS/WCS).  PROJECTION    # Projection parameters can be defined in two ways...    # This is the traditional Proj.4 definition of 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 EPSG code.    # This is the EPSG code for Lambert Azimuthal 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 a reference map for your mapping   # application.  This typically involves defining a small image that covers   # the entire area of the map and defining a box that represents the current   # view on in relation to the entire area.  REFERENCE    IMAGE '../images/ugl_ref1.png' # The reference image    SIZE 155 105 # The size of the reference image in pixels    EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514 # The extent of the reference image in map units    STATUS ON    MINBOXSIZE 10 # How small can the reference box be before it gets drawn as a point, in pixels    MAXBOXSIZE 150 # The maximum size of the reference box, in pixels    COLOR -1 -1 -1 # The reference box fill color, negative numbers mean transparent    OUTLINECOLOR 128 0 0 # The reference box outline color     MARKERSIZE 8 # The size of the point marker    MARKER 'star' # The marker symbol  END    # A scalebar object is defined one level below the map object.  This object   # controls how a scalebar is drawn by MapServer.  Scalebars can be embedded   # in the map itself or can be created as a separate 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 the map 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 layer you define (right after this   # comment), will be drawn at the bottom.  Here's my rule: rasters and   # polygons are defined first, followed by the line 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 projection definition.    # 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 the layer object.  You can define as    # many classes as you need (well, there are limits, but it's senseless to     # define more than ten on a "normal" layer.  There are situations,     # 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 POLYGON    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 POLYGON    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         POLYGON    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
View Code

 

 

如果用户要浏览地图,则应提供参考地图。
示例2.4-添加参考图

 HTML Template:

MapServer 5.x Tutorial

Example 2.4: Adding a Reference Map

Select Layers:
State Boundaries  Water Features  Roads
Select Background:
Map Mode:
Map Control:

Reference:

View Code

这段代码中有趣的部分是标签,即[缩放\选择]。当mapserv看到这样的标记时,它将评估是否选择了值(“1”)。如果选中,则MapServ会将此选项标记为“已选中”。再次,转到示例2.1并“查看”代码。“recenter”选项应该是“selected”(这样当我们再次提交表单时,“zoom”的值将是“1”)。

最后一个标签是“[img]”标签。正如您将注意到的,它是表单输入对象的一部分。“[img]”将替换为mapserv生成的映像的完整路径和名称。

一旦mapserver替换了所有标记,它将向浏览器发送一个合适的HTML表单。用户将再次能够进行更改。

像任何好的地图一样,它应该包括一个传说。
示例2.5-添加图例

 这里是HTML模板源代码:

MapServer 5.x Tutorial

Example 2.5: Adding a Legend

Select Layers:
State Boundaries  Water Features  Roads
Select Background:
Map Mode:
Map Control:

Reference:

Legend:

View Code

这段代码中有趣的部分是标签,即[缩放\选择]。当mapserv看到这样的标记时,它将评估是否选择了值(“1”)。如果选中,则MapServ会将此选项标记为“已选中”。再次,转到示例2.1并“查看”代码。“recenter”选项应该是“selected”(这样当我们再次提交表单时,“zoom”的值将是“1”)。

最后一个标签是“[img]”标签。正如您将注意到的,它是表单输入对象的一部分。“[img]”将替换为mapserv生成的映像的完整路径和名称。
一旦mapserver替换了所有标记,它将向浏览器发送一个合适的HTML表单。用户将再次能够进行更改。

转载于:https://www.cnblogs.com/2008nmj/p/11059494.html

你可能感兴趣的文章
NYOJ-613//HDU-1176-免费馅饼,数字三角形的兄弟~~
查看>>
graphite custom functions
查看>>
一个自己写的判断2个相同对象的属性值差异的工具类
查看>>
oracle连接的三个配置文件(转)
查看>>
Python内置函数(29)——help
查看>>
oracle导出/导入 expdp/impdp
查看>>
Objective - C基础: 第四天 - 10.SEL类型的基本认识
查看>>
Android TextView加上阴影效果
查看>>
《梦断代码》读书笔记(三)
查看>>
Java8 Lambda表达应用 -- 单线程游戏server+异步数据库操作
查看>>
[Unity3D]Unity3D游戏开发MatchTarget的作用攀登效果实现
查看>>
AngularJS学习篇(一)
查看>>
关于Xshell无法连接centos6.4的问题
查看>>
css3动画——基本准则
查看>>
输入月份和日期,得出是今年第几天
查看>>
pig自定义UDF
查看>>
Kubernetes 运维学习笔记
查看>>
spring security 11种过滤器介绍
查看>>
代码实现导航栏分割线
查看>>
大数据学习系列(8)-- WordCount+Block+Split+Shuffle+Map+Reduce技术详解
查看>>