mapserver+openlayers实现左键点击查询
效果图
第一步,配置自己的mapfile,在要查询的图层LAYER对象内加上HEADER,TEMPLATE,FOOTER三个参数,同时,TEMPLATE fooOnlyForWMSGetFeatureInfo前加#屏蔽(切记)。
我的一个例子
LAYER
NAME 'Basin'
TYPE POLYGON
DUMP true
HEADER "header.html"
TEMPLATE "content_ChinaData.html"
FOOTER "footer.html"
#TEMPLATE fooOnlyForWMSGetFeatureInfo
EXTENT 72.159645 12.440230 136.365480 59.396737
DATA 'C:\ms4w\Apache\htdocs\DATA\ChinaData.shp'
METADATA
'ows_title' 'ChinaData'
'ows_srs' 'EPSG:4326'
"gml_include_items" "all"
"gml_featureid" "id" #必须指定id
'queryable' 'true'
END
STATUS OFF
TRANSPARENCY 100
PROJECTION
'proj=longlat'
'datum=WGS84'
'no_defs'
END
CLASS
NAME 'ChinaData'
STYLE
WIDTH 1
OUTLINECOLOR 0 0 0
COLOR 255 255 255
END
END
END
2、配置"header.html"、"content_Basin.html"、"footer.html"三个文件,这三个文件各自不是一个完整的网页,组合在一起才是,如果要查询的图层不止一个
可以多做几个"content_Basin.html"的网页,但是"header.html"、"footer.html"各自只要一个就行了,每个网页第一句是<!-- MapServer Template -->(必须的)
我的实例
header.html
<!-- MapServer Template -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/transitional.dtd"> <html> <head> <!-- enforce the client to display result html as UTF-8 encoding -->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></meta>
<title>GetFeatureInfo Response</title>
<style type="text/css">
table.featureInfo, table.featureInfo td, table.featureInfo th {
border:1px solid #ddd;
border-collapse:collapse;
margin:0;
padding:0;
font-size: 90%;
padding:.4em .4em;
}
table.featureInfo th {
padding:.2em .2em;
font-weight:bold;
background:#eee;
}
table.featureInfo td{
background:#fff;
}
table.featureInfo tr.odd td{
background:#eee;
}
table.featureInfo caption{
text-align:left;
font-size:100%;
font-weight:bold;
padding:.2em .2em;
}
</style>
</head> <body>
<table class="featureInfo">
content_Basin.html
<!-- MapServer Template -->
<caption class="featureInfo">图层:盆地</caption> <tbody>
<th>名称</th>
<th>面积</th>
<tr >
<td >[item name="Name" format=$value escape=none]</td>
<td>[item name="Area" precision="1" format=$value escape=none]</td> </tr>
footer.html
<!-- MapServer Template --> </tbody> </table> <br/> </body> </html>
3、点击功能的实现
在代码中加入
info = new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://127.0.0.1/cgi-bin/mapserv.exe?',
title: 'Identify features by clicking',
queryVisible: true,
infoFormat:'text/html',///nimeide
queryVisible:true,
layers:[Basint,AreaOfReserch,Oilfield],
eventListeners: {
getfeatureinfo: function(event) {
map.addPopup(new OpenLayers.Popup.FramedCloud(
"chicken",
map.getLonLatFromPixel(event.xy),
null,
event.text,
null,
true
));
}
}
});
map.addControl(info);
info.activate();
最新文章
- framebuffer line_length 參數
- float和double的精度
- 在VMware中安装ubuntu出现菜单栏无法显示的情况
- HTML5学习总结-05 HTML5表单
- Spring Boot工程发布到Docker
- [转] 深入探讨C++中的引用
- c语言编程之二叉排序树
- Javascript中的Keycode值列表
- 一个无聊的实验:验证网站是否通过web容器还是微服务部署
- slua 中使用 lua5.3
- linux下安装多个mysql实例(摘自国外:How to create multiple mysql instance in CentOS 6.4 and Red Hat 6.4)
- MDX示例:求解中位数、四分位数(median、quartile)
- java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet
- MVC 模型绑定
- 如何配置Spring的XML文件及使用
- 调用phprpc的时候出现Fatal error: Cannot redeclare gzdecode()
- 损失函数&;经验函数
- Django-rest-framework源码分析----认证
- warning: ISO C++ forbids converting a string constant to &#39;char*&#39; [-Wwrite-strings]
- linux 乌班图 nginx php直接下载下来
热门文章
- 优化通过redis实现的一个抢红包流程【下】
- Struts2 In Action笔记_页面到动作的数据流入和流出
- 配置dubbo架构的maven项目
- 零基础快速入门SpringBoot2.0 (一)
- 定位设备--llseek实现
- css分层,实现遮罩底层弹出新窗口里可以操作,最下层能看到单不能操作
- [译]The Python Tutorial#7. Input and Output
- python3.7 time模块
- 2018年湘潭大学程序设计竞赛 E	吃货
- Linux 内核源码外编译 linux模块--编译驱动模块的基本方法