iwillsw大侠安在,给我们大家一个GEOSERVER的WFS查询例子吧!

qimaozhifu 2011-06-26 10:04:16
GEOSERVER的WMS目前简单的可以看地图了,但是想查询一个城市在哪里,怎么做呢?我想输入一个城市名,然后地图上用一个MARKET标示一下这个城市,就是做不出来!我用的GEOSERVER2.0.2,找不到它自己的例子啊!根本就没有例子!

用OpenLayers2.8,它里面的WFS例子,居然没有一个是查找的,都是写啊、画啊、拖拽啊!法克!
iwillsw大侠,知道你是这方面的高手,给大家一个可以运行的html文件吧,功德无量啊!
...全文
668 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwillsw 2011-10-21
  • 打赏
  • 举报
回复
用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'] ; //获得属性
}

qimaozhifu 2011-07-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cuit 的回复:]
OpenLayers-2.8\examples\wfs-t.html
[/Quote]

这个程序我看了,我不认为它有价值。它的代码是:
<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="上海",而它这里面一个条件也没有,不知道它请求啥去了?
gnimgnot 2011-07-03
  • 打赏
  • 举报
回复
OpenLayers-2.8\examples\wfs-t.html
qimaozhifu 2011-07-02
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lorry1113 的回复:]
http://hi.baidu.com/liyingben/blog/item/55682b7788e10a0eb151b98b.html

看看吧,网络上很多的例子
[/Quote]

你给这个东西,你能看明白吗,他根本就没给出具体的做法,只是拿出一段代码来,具体应该怎么发出请求?怎么处理返回的数据?
我要的是切实可以执行的例子。
qimaozhifu 2011-07-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ron_cs 的回复:]
根据城市名获取相应的相应的经纬度,然后再在该点显示标记不就OK了吗?
[/Quote]

我觉得地图不是这么整的,,,不是直接去查找数据库吧,比如说SHP的地图,怎么查数据库呢?
ron_cs 2011-07-01
  • 打赏
  • 举报
回复
根据城市名获取相应的相应的经纬度,然后再在该点显示标记不就OK了吗?
lorry1113 2011-06-29
  • 打赏
  • 举报
回复
qimaozhifu 2011-06-27
  • 打赏
  • 举报
回复
顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

2,143

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧