检查“城市”的图层,然后单击“刷新”按钮。该地图将刷新,城市图层现在应该显示出来。改变地图模式到“查询单层”或“查询多图层”,然后点击其中一个城市。
您刚刚执行了非空间查询。结果可能没有任何意义,但会有一个结果。我们在接下来的两个练习将格式化查询结果,但现在我们将看看添加 MapFile 和HTML模板的变化。
这里是这些城市图层如下(删除一些注释):
LAYER # Urban areas polygon layer begins here
NAME cities_poly
GROUP cities
TYPE Polygon
STATUS on
DATA urban_ugl
# The keyword TOLERANCE provides a measure of sensitivity for point-based
# queries. In this example, a mouse-click will have a radius of 3 pixels.
# TOLERANCE has and associated keyword, TOLERANCEUNITS. When TOLERANCEUNITS
# isn't defined, MapServer assumes the units to be pixels.
#关键字TOLERANCE提供了一个以点为基础查询的灵敏度测量。在这个例子中,点击鼠标,将有一个半径为3像素的圆.TOLERANCE有一个关联的关键字,TOLERANCEUNITS。当TOLERANCEUNITS没有定义,假定MapServer单位是像素。
TOLERANCE 3
CLASS
NAME 'Urban Areas'
# The TEMPLATE keyword within a CLASS object is used to define the
# HTML query template to use in displaying database records when the
# query or nquery mode in MapServer is invoked.
#在CLASS中TEMPLATE关键字是用来定义HTML查询模板,以用作显示数据库记录,当在MapServer中调用来查询或多次查询模式时
TEMPLATE '../templates/cities_query.html'
STYLE
COLOR 255 240 115
END
END # CLASS
PROJECTION
"init=epsg:4326"
END
END # Urban areas polygon layer ends here
正如你所看到的,我们只对 MapFile 添加来两个参数——TOLERANCE,在cities_poly layer中——TEMPLATE在cities_poly layer的CLASS对象中。
这里就是寻找模板
, 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内变量,将在图层内显示结果计数。
View the MapFile |
View the HTML Template
|