iwillsw大侠安在,给我们大家一个GEOSERVER的WFS查询例子吧!
GEOSERVER的WMS目前简单的可以看地图了,但是想查询一个城市在哪里,怎么做呢?我想输入一个城市名,然后地图上用一个MARKET标示一下这个城市,就是做不出来!我用的GEOSERVER2.0.2,找不到它自己的例子啊!根本就没有例子!用OpenLayers2.8,它里面的WFS例子,居然没有一个是查找的,都是写啊、画啊、拖拽啊!法克!
iwillsw大侠,知道你是这方面的高手,给大家一个可以运行的html文件吧,功德无量啊! --------------------编程问答-------------------- 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶 --------------------编程问答-------------------- http://hi.baidu.com/liyingben/blog/item/55682b7788e10a0eb151b98b.html
看看吧,网络上很多的例子 --------------------编程问答-------------------- 根据城市名获取相应的相应的经纬度,然后再在该点显示标记不就OK了吗? --------------------编程问答--------------------
我觉得地图不是这么整的,,,不是直接去查找数据库吧,比如说SHP的地图,怎么查数据库呢? --------------------编程问答--------------------
你给这个东西,你能看明白吗,他根本就没给出具体的做法,只是拿出一段代码来,具体应该怎么发出请求?怎么处理返回的数据?
我要的是切实可以执行的例子。
--------------------编程问答-------------------- OpenLayers-2.8\examples\wfs-t.html --------------------编程问答--------------------
这个程序我看了,我不认为它有价值。它的代码是:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers: WFS-T</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, wfs;
OpenLayers.ProxyHost = "proxy.cgi?url=";
function init() {
map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS(
"State",
"http://sigma.openplans.org/geoserver/wms",
{layers: 'topp:tasmania_state_boundaries'}
);
wfs = new OpenLayers.Layer.WFS(
"Cities",
"http://sigma.openplans.org/geoserver/wfs",
{typename: 'topp:tasmania_cities'},
{
typename: "tasmania_cities",
featureNS: "http://www.openplans.org/topp",
extractAttributes: false,
commitReport: function(str) {
OpenLayers.Console.log(str);
}
}
);
map.addLayers([wms, wfs]);
var panel = new OpenLayers.Control.Panel({
displayClass: "olControlEditingToolbar"
});
var draw = new OpenLayers.Control.DrawFeature(
wfs, OpenLayers.Handler.Point,
{
handlerOptions: {freehand: false, multi: true},
displayClass: "olControlDrawFeaturePoint"
}
);
var save = new OpenLayers.Control.Button({
trigger: OpenLayers.Function.bind(wfs.commit, wfs),
displayClass: "olControlSaveFeatures"
});
panel.addControls([
new OpenLayers.Control.Navigation(),
save, draw
]);
map.addControl(panel);
map.zoomToExtent(new OpenLayers.Bounds(140.64,-44.42,151.89,-38.80));
}
</script>
</head>
<body onload="init()">
<h1 id="title">WFS Transaction Example</h1>
<div id="tags">
</div>
<p id="shortdesc">
Shows the use the WFS layer for transactions.
</p>
<div id="map" class="smallmap"></div>
<p id="docs">
This is an example of using a WFS layer type. Note that it requires a
working GeoServer install, which the OpenLayers project does not maintain;
however, if you're interested, you should be able to point this against
a default GeoServer setup without too much trouble.
</p>
</body>
</html>
我不知道它WFS里的commitReport: function(str) {
OpenLayers.Console.log(str);
}
这段代码是啥意思。不管咋样,我需要一个条件传上去,比如说city="上海",而它这里面一个条件也没有,不知道它请求啥去了? --------------------编程问答-------------------- 用wfs服务实,核心代码如下,完整的html自己写吧
new OpenLayers.Request.GET( {
url : "http://地图服务器地址/wfs?request=GetFeature",
params: {
typeName: "CityLayer", //查询城市图层CityLayer
CITYNAME: "北京" //CITYNAME是CityLayer图层的一个属性字段名
},
callback : handler //回调函数
});
这里用的GET方式,也可以用POST方式
回调函数负责处理服务端返回的GML数据(查询结果),其中核心代码如下:
var g = new OpenLayers.Format.GML();
var features = g.read(req.responseText); //得到返回的feature集合
if (features.length>0) {
var feature = features[0]; //如果有多个返回记录,取第一个feature
var point = feature.geometry.getBounds().getCenterLonLat(); //获得中心点地理坐标
var cname = feature.attributes['CITYNAME'] ; //获得属性
}
补充:企业软件 , 地理信息系统