使用MapServer模板

MapServer 模板文件的要求

Templates must contain the magic string mapserver template in the first line of the template. Often this takes the form of an HTML, javascript or XML comment. This line is not written to the client. The magic string is not case sensitive.

MapServer will only accept certain file extensions for templates; valid file extensions are: .gml.html.htm.js.kml.svg.tmpl.wml.xml

CGI变量

All CGI parameters can be referenced in template substitutions, MapServer specific parameters as well as user defined ones. In principle parameters are handed through by the MapServer 1:1. This feature is essential for implementing MapServer applications.

The reference below only lists special template substitution strings which are needed to obtain information modified by the MapServer, e.g. a new scale, query results, etc.

Template substitution strings are case sensitive.

Attribute item substitutions must be the same case as the item names in the dbase file.

ArcView and ArcInfo generally produce dbase files with item names that are all uppercase. Appropriate URL encoding (i.e. ‘ ‘ to ‘+’) is applied when templates are URLs.

Some substitutions are also available in escaped form (i.e. URL encoded).

特殊字符

Templates are simply HTML files or URL strings that contains special characters that are replaced by mapserv each time the template is processed. The simple substitution allows information such as active layers or the spatial extent to be passed from the user to mapserv and back again. Most often the new values are dumped into form variables that will be passed on again. The list of special characters and form variables is given below. HTML templates can include just about anything including JavaScript and Java calls.

In HTML files, the attribute values can be inside quotes(“”). Writing attribute values inside quotes allows you to set special characters in value that you couldn’t use normally (ie: ],=,” and space). To write a single quote in a attribute value, just use two quotes (“”).