查询模板

如何使用

这里是这些城市图层如下(删除一些注释):

01 MAP
02     NAME "EX3_"
03     IMAGETYPE "png24"
04     EXTENT 166221 -371954 1505849 632767
05     SIZE 400 300
06     SHAPEPATH "../data"
07     SYMBOLSET "../symbols/symbols35.sym"
08     FONTSET "../fonts/fonts.list"
09     TEMPLATEPATTERN "example3*"
10     WEB
11         HEADER "../maptmpl/example3_header.html"
12         FOOTER "../maptmpl/example3_footer_querymap.html"
13         TEMPLATE "to be replaced by map_web_template variable in section3.html"
14         IMAGEPATH "/oswebgis/ms_tmp/"
15         IMAGEURL "/ms_tmp/"
16     END
17     PROJECTION
18         "init=epsg:2163"
19     END
20     LEGEND
21         KEYSIZE 12 12
22         LABEL
23             TYPE BITMAP
24             SIZE MEDIUM
25             COLOR 0 0 89
26         END
27         STATUS ON
28     END
29     REFERENCE
30         IMAGE "../images/ugl_ref1.png"
31         SIZE 155 105
32         EXTENT 201621.496941 -294488.285333 1425518.020722 498254.511514
33         STATUS ON
34         MINBOXSIZE 10
35         MAXBOXSIZE 150
36         COLOR -1 -1 -1
37         OUTLINECOLOR 128 0 0
38         MARKERSIZE 8
39         MARKER "star"
40     END
41     SCALEBAR
42         IMAGECOLOR 255 255 255
43         LABEL
44             COLOR 0 0 0
45             SIZE TINY
46         END
47         STYLE 1
48         SIZE 100 2
49         COLOR 0 0 0
50         UNITS MILES
51         INTERVALS 2
52         TRANSPARENT FALSE
53         STATUS ON
54     END
55     QUERYMAP
56         SIZE 200 150
57         STATUS ON
58         STYLE HILITE
59         COLOR 255 0 0
60     END
61     LAYER
62         NAME "states"
63         DATA "states_ugl"
64         STATUS DEFAULT
65         TYPE POLYGON
66         PROJECTION
67             "init=epsg:4326"
68         END
69         CLASSITEM "CLASS"
70         CLASS
71             EXPRESSION "land"
72             STYLE
73                 SYMBOL 0
74                 COLOR 232 232 232
75             END
76         END
77     END
78     LAYER
79         NAME "relief"
80         DATA "raster/shdrlfi020g_ugl.tif"
81         STATUS OFF
82         TYPE RASTER
83         OFFSITE 169 209 254
84         DUMP TRUE
85         METADATA
86             "wms_title" "UGL Shaded Relief"
87             "wms_abstract" "Shaded Relief of Michigan, Minnesota, and Wisconsin.  Clipped from National Atlas data (http://www.nationalatlas.gov)."
88             "wms_srs" "EPSG:2163 EPSG:4326 EPSG:26915"
89         END
90         PROJECTION
91             "init=epsg:4326"
92         END
93         CLASS
94             NAME "Shaded Relief"
95             KEYIMAGE "graphics/relief_keyimage.png"
96         END
97     END
98     LAYER
99         NAME "modis"
100         DATA "raster/mod09a12003161_ugl_ll_idxa.tif"
101         STATUS OFF
102         TYPE RASTER
103         OFFSITE 70 74 66
104         PROJECTION
105             "init=epsg:4326"
106         END
107         CLASS
108             NAME "MODIS Image"
109             KEYIMAGE "graphics/modis_keyimage.png"
110         END
111     END
112     LAYER
113         NAME "landsat"
114         TYPE RASTER
115         OFFSITE 0 0 0
116         STATUS OFF
117         CONNECTIONTYPE WMS
118         CONNECTION "http://mapus.jpl.nasa.gov/wms.cgi?"
119         METADATA
120             "wms_srs" "EPSG:4326"
121             "wms_name" "global_mosaic"
122             "wms_server_version" "1.1.1"
123             "wms_format" "image/jpeg"
124         END
125         PROJECTION
126             "init=epsg:4326"
127         END
128         CLASS
129             NAME "Landsat Image"
130             KEYIMAGE "graphics/landsat_keyimage.png"
131         END
132     END
133     LAYER
134         NAME "cities_poly"
135         GROUP "cities"
136         TYPE POLYGON
137         STATUS ON
138         DATA "urban_ugl"
139         HEADER "../maptmpl/cities_header.html"
140         FOOTER "../maptmpl/cities_footer.html"
141         TOLERANCE 3
142         CLASS
143             NAME "Urban Areas"
144             TEMPLATE "../maptmpl/cities_query.html"
145             STYLE
146                 COLOR 255 240 115
147             END
148         END
149         PROJECTION
150             "init=epsg:4326"
151         END
152     END
153     LAYER
154         NAME "fedlands"
155         TYPE POLYGON
156         STATUS ON
157         DATA "fedlan_ugl"
158         CLASSITEM "FEATURE1"
159         CLASS
160             NAME "Federal Land"
161             EXPRESSION ( '[FEATURE1]' ne 'Null' )
162             STYLE
163                 COLOR 164 96 89
164                 OUTLINECOLOR 144 72 64
165             END
166         END
167         PROJECTION
168             "init=epsg:4326"
169         END
170     END
171     LAYER
172         NAME "hydro"
173         TYPE POLYGON
174         STATUS OFF
175         DATA "hydrop_ugl"
176         PROJECTION
177             "init=epsg:4326"
178         END
179         CLASSITEM "FEATURE"
180         CLASS
181             NAME "Lakes"
182             EXPRESSION /(^B|^C|^L|^R)./
183             STYLE
184                 COLOR 72 64 254
185             END
186         END
187         CLASS
188             NAME "Rivers"
189             EXPRESSION "Stream"
190             STYLE
191                 COLOR 136 128 255
192             END
193         END
194         CLASS
195             NAME "Wetlands"
196             EXPRESSION "Swamp or Marsh"
197             STYLE
198                 COLOR 195 252 255
199                 OUTLINECOLOR 195 252 255
200                 SYMBOL "circle"
201                 SIZE 0
202             END
203         END
204     END
205     LAYER
206         NAME "counties"
207         DATA "co2000_ugl"
208         STATUS OFF
209         TYPE LINE
210         PROJECTION
211             "init=epsg:4326"
212         END
213         CLASSITEM "county"
214         CLASS
215             NAME "County Boundary"
216             EXPRESSION /./
217             STYLE
218                 SYMBOL "line5"
219                 COLOR 92 92 92
220                 SIZE 1
221             END
222         END
223     END
224     LAYER
225         NAME "cty_roads"
226         GROUP "roads"
227         TYPE LINE
228         STATUS OFF
229         DATA "roads_ugl"
230         MAXSCALE 750000
231         PROJECTION
232             "init=epsg:4326"
233         END
234         CLASSITEM "CLASS1"
235         CLASS
236             NAME "Minor Arterial Roads"
237             EXPRESSION "3"
238             STYLE
239                 COLOR 165 165 165
240             END
241         END
242         CLASS
243             EXPRESSION "4"
244             STYLE
245                 COLOR 210 210 210
246             END
247         END
248     END
249     LAYER
250         NAME "state_hwy"
251         GROUP "roads"
252         MAXSCALE 1500000
253         STATUS OFF
254         DATA "roads_ugl"
255         TYPE LINE
256         FILTERITEM "CLASS1"
257         FILTER "2"
258         CLASS
259             NAME "Principal Arterial Roads"
260             STYLE
261                 COLOR 255 0 0
262                 SIZE 1
263                 SYMBOL "circle"
264             END
265         END
266         PROJECTION
267             "init=epsg:4326"
268         END
269     END
270     LAYER
271         NAME "interstate"
272         GROUP "roads"
273         STATUS OFF
274         DATA "roads_ugl"
275         TYPE LINE
276         FILTERITEM "CLASS1"
277         FILTER "1"
278         CLASS
279             NAME "Interstate Hwy."
280             STYLE
281                 COLOR 128 0 0
282             END
283         END
284         PROJECTION
285             "init=epsg:4326"
286         END
287     END
288     LAYER
289         NAME "states"
290         DATA "states_ugl"
291         STATUS OFF
292         TYPE LINE
293         PROJECTION
294             "init=epsg:4326"
295         END
296         CLASSITEM "CLASS"
297         CLASS
298             NAME "State Boundary"
299             EXPRESSION "land"
300             STYLE
301                 SYMBOL "line5"
302                 COLOR 32 32 32
303                 SIZE 1
304             END
305         END
306     END
307     LAYER
308         NAME "roads_anno"
309         GROUP "roads"
310         MAXSCALE 750000
311         STATUS OFF
312         DATA "roads_ugl"
313         TYPE LINE
314         LABELITEM "SIGN"
315         CLASSITEM "CLASS1"
316         CLASS
317             EXPRESSION "3"
318             STYLE
319                 COLOR 0 0 0
320                 SYMBOL "../symbols/sthwy.png"
321             END
322             LABEL
323                 MINFEATURESIZE 50
324                 MINDISTANCE 150
325                 POSITION CC
326                 SIZE TINY
327                 COLOR 0 0 0
328             END
329         END
330         CLASS
331             EXPRESSION "2"
332             STYLE
333                 COLOR 0 0 0
334                 SYMBOL "../symbols/ushwy.png"
335             END
336             LABEL
337                 MINFEATURESIZE 50
338                 MINDISTANCE 150
339                 POSITION CC
340                 SIZE TINY
341                 COLOR 0 0 0
342             END
343         END
344         PROJECTION
345             "init=epsg:4326"
346         END
347     END
348     LAYER
349         NAME "roads_anno1"
350         GROUP "roads"
351         STATUS OFF
352         DATA "roads_ugl"
353         TYPE LINE
354         LABELITEM "SIGN"
355         CLASSITEM "CLASS1"
356         CLASS
357             EXPRESSION "1"
358             STYLE
359                 COLOR 0 0 0
360                 SYMBOL "../symbols/interstate.png"
361             END
362             LABEL
363                 MINFEATURESIZE 20
364                 MINDISTANCE 150
365                 POSITION CC
366                 SIZE TINY
367                 COLOR 255 255 255
368             END
369         END
370         PROJECTION
371             "init=epsg:4326"
372         END
373     END
374     LAYER
375         NAME "states"
376         DATA "states_ugl"
377         STATUS OFF
378         TYPE POLYGON
379         PROJECTION
380             "init=epsg:4326"
381         END
382         CLASSITEM "CLASS"
383         LABELITEM "STATE"
384         CLASS
385             EXPRESSION "land"
386             STYLE
387                 COLOR -1 -1 -1
388             END
389             LABEL
390                 COLOR 132 31 31
391                 OUTLINECOLOR 128 128 128
392                 SHADOWCOLOR 218 218 218
393                 SHADOWSIZE 1 1
394                 TYPE TRUETYPE
395                 FONT "arial-bold"
396                 SIZE 12
397                 ANTIALIAS TRUE
398                 POSITION CL
399                 PARTIALS FALSE
400                 MINDISTANCE 200
401                 BUFFER 4
402             END
403         END
404     END
405 END

正如你所看到的,我们只对 MapFile 添加了两个参数:(1) TOLERANCE,在cities_poly layer中;(2) TEMPLATE在cities_poly layer的CLASS对象中。

这里就是Query TEMPLATE, cities_query.html:


<tr>
  <td>[lrn]</td>
  <td>[NAME]</td>
  <td>[STATE]</td>
</tr>

请注意,它看起来就像HTML表中的一个片段。MapServer“[NAME]”和“[STATE]”的标签实际上是和urban_ugl.dbf的属性, 这是与输出shape文件相关的非空间数据库。MapServer定义shape文件属性时, 我们始终把握名称(对于shape文件,这是真实的,但在所有的情况下,是不正确的)。 此之前我们在章节1中所定义CLASSITEM和LABELITEM时我们也使用这个。 对于其它的标签,“【LRN]”,是另一个MapServer内变量,将在图层内显示结果计数。

如果你使用了 "Query Multiple Layers查询多图层",MapServer CGI程序将对每个记录应用这个查询模板

View the MapFile | View the HTML Template

示例