第二章 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:http://localhost/tutorial/example1-1.html
mapserver可以创建一个地图并将其转储到本地目录,或者直接发送到请求的Web浏览器,如本例所示。您可以在不需要HTML页面的情况下查看它,只需输入以下URL:http://<insert hostname or ip address here>/cgi bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/example1-1.map&layer=states&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参数(变量及其值),每个参数由一个与(&)分隔。因此,查看查询字符串,第一个参数“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...