看一下这个例子在执行,打开例三中的地图并取消在城市区图层的页眉和页脚。当完成时保存 MapFile 。
图层内的 HEADER
和 FOOTER
对象关键字是用来定义用在页眉和页脚模板的模板关键字。
可以将下面两行取消注释,看看模板文件本身,看他们如何工作。
HEADER '../templates/cities_header.html'
FOOTER '../templates/cities_footer.html'
检查“城市”的图层,然后单击“刷新”按钮。该地图将刷新,城市图层现在应该显示出来。改变地图模式到“查询单层”或“查询多图层”,然后点击其中一个城市。
现在结果应该有一个标题,并且应该以表格的形式呈现。
这就是城市页眉的样子
<b>Layer: cities</b> <p> <table cellpadding=5 cellspacing=2 border=0> <tr bgcolor=#CCCCCC> <td bgcolor=#ffffff> </td> <th>NAME</th> <th>STATE</th> </tr>这里是查询城市文件
<tr> <td>[lrn]</td> <td>[NAME]</td> <td>[STATE]</td> </tr>最后,这是城市页脚的样子
</table> <p>
当MapServer的一个特定层处理查询时,寻找那层最上面的模板。然后,它将处理从数据库中得到的记录。 令查询模板的记录应用到 每个记录。当模板已被应用到所有的记录,它将再次寻找模板层的页脚。查看源代码查询结果页面看到这是如何工作的。
View the MapFile | View the HTML Template
7 | FONTSET "../fonts/fonts.list" | 7 | FONTSET "../fonts/fonts.list" | ||
n | 8 | TEMPLATEPATTERN "tmpl-*" | n | 8 | TEMPLATEPATTERN "example-p*" |
9 | LEGEND | 9 | LEGEND | ||
17 | END | 17 | END | ||
n | 18 | SYMBOL | n | ||
19 | NAME "star" | ||||
20 | TYPE VECTOR | ||||
21 | FILLED TRUE | ||||
22 | POINTS | ||||
23 | 0 0.375 | ||||
24 | 0.35 0.375 | ||||
25 | 0.5 0 | ||||
26 | 0.65 0.375 | ||||
27 | 1 0.375 | ||||
28 | 0.75 0.625 | ||||
29 | 0.875 1 | ||||
30 | 0.5 0.75 | ||||
31 | 0.125 1 | ||||
32 | 0.25 0.625 | ||||
33 | END | ||||
34 | END | ||||
35 | REFERENCE | 18 | REFERENCE | ||
36 | IMAGE "../images/worldref.png" | 19 | IMAGE "../images/worldref.png" | ||
n | 37 | SIZE 300 150 | n | 20 | SIZE 155 105 |
38 | EXTENT -180 -90 180 90 | 21 | EXTENT -180 -90 180 90 | ||
39 | STATUS ON | 22 | STATUS ON | ||
n | 40 | MINBOXSIZE 30 | n | 23 | MINBOXSIZE 10 |
41 | MAXBOXSIZE 150 | 24 | MAXBOXSIZE 150 | ||
n | 42 | COLOR 255 255 0 | n | 25 | COLOR -1 -1 -1 |
43 | OUTLINECOLOR 255 50 50 | 26 | OUTLINECOLOR 128 0 0 | ||
44 | MARKERSIZE 30 | 27 | MARKERSIZE 8 | ||
45 | MARKER "star" | 28 | MARKER "star" | ||
n | 46 | END | n | ||
47 | QUERYMAP | ||||
48 | SIZE 200 150 | ||||
49 | STATUS ON | ||||
50 | STYLE HILITE | ||||
51 | COLOR 255 0 0 | ||||
52 | END | 29 | END | ||
59 | STYLE 1 | 36 | STYLE 1 | ||
n | 60 | SIZE 160 2 | n | 37 | SIZE 100 2 |
61 | COLOR 0 0 0 | 38 | COLOR 0 0 0 | ||
n | 62 | UNITS KILOMETERS | n | 39 | UNITS MILES |
63 | INTERVALS 2 | 40 | INTERVALS 2 | ||
67 | WEB | 44 | WEB | ||
n | 68 | HEADER "qtpl_header.html" | n | ||
69 | FOOTER "qtpl_footer.html" | ||||
70 | TEMPLATE "to be replaced by map_web_template variable in section3.html" | 45 | TEMPLATE "to be replaced by map_web_template variable in section3.html" | ||
79 | LAYER | 54 | LAYER | ||
n | 80 | NAME "land" | n | 55 | NAME "topo" |
81 | DATA "land_shallow_topo_8192.tif" | 56 | DATA "land_shallow_topo_8192.tif" | ||
83 | TYPE RASTER | 58 | TYPE RASTER | ||
n | n | 59 | PROCESSING "BANDS=1,2,3" | ||
60 | OFFSITE 71 74 65 | ||||
84 | END | 61 | END | ||
85 | LAYER | 62 | LAYER | ||
n | 86 | NAME "topo" | n | 63 | NAME "modis_jpl" |
87 | TYPE RASTER | 64 | TYPE RASTER | ||
n | n | 65 | OFFSITE 0 0 0 | ||
66 | STATUS OFF | ||||
88 | CONNECTIONTYPE WMS | 67 | CONNECTIONTYPE WMS | ||
106 | LABELITEM "NAME" | 85 | LABELITEM "NAME" | ||
n | n | 86 | HEADER "../maptmpl/states_header.html" | ||
87 | FOOTER "../maptmpl/states_footer.html" | ||||
107 | TOLERANCE 3 | 88 | TOLERANCE 3 | ||
109 | NAME "the States" | 90 | NAME "the States" | ||
n | 110 | TEMPLATE "qtpl_country.html" | n | 91 | TEMPLATE "../maptmpl/states_query.html" |
111 | STYLE | 92 | STYLE | ||
131 | DATA "wriver.shp" | 112 | DATA "wriver.shp" | ||
n | 132 | STATUS ON | n | 113 | STATUS OFF |
133 | TYPE LINE | 114 | TYPE LINE | ||
n | 134 | TOLERANCE 3 | n | ||
135 | CLASS | 115 | CLASS | ||
136 | NAME "World River" | 116 | NAME "World River" | ||
t | 137 | TEMPLATE "qtpl_river.html" | t | ||
138 | STYLE | 117 | STYLE |