From:http://liushaobo2005.blog.163.com/blog/static/253056702011541462372/

wfs是OGC的标准规范,主要用于提供对矢量地理数据的服务,我们以一个对摄像头图层进行操作为例了解如何通过openlayer+geoserver实现WFS操作。

首先利用postgis建表camera,参照http://postgis.refractions.net/docs/ch04.html

接着在geoserver中创建相关图层camera,数据来源为刚建立的postgis表

修改geoserver的WFS service配置,将Service Level改为Transactional,实现事物级的操作。

此时我们已经完成了服务器端的配置,接着通过openlayer来实现对WFS服务的调用。

wfs-protocol-transactions.js

//定义DeleteFeature类

var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function(layer, options) {
OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.layer = layer;
this.handler = new OpenLayers.Handler.Feature(
this, layer, {click: this.clickFeature}
);
},
clickFeature: function(feature) {
// if feature doesn't have a fid, destroy it
if(feature.fid == undefined) {
this.layer.destroyFeatures([feature]);
} else {
feature.state = OpenLayers.State.DELETE;
this.layer.events.triggerEvent("afterfeaturemodified",
{feature: feature});
feature.renderIntent = "select";
this.layer.drawFeature(feature);
}
},
setMap: function(map) {
this.handler.setMap(map);
OpenLayers.Control.prototype.setMap.apply(this, arguments);
},
CLASS_NAME: "OpenLayers.Control.DeleteFeature"
}); function init() { var mapOptions = {
resolutions: [],
projection: new OpenLayers.Projection('EPSG:900913'),
maxExtent: new OpenLayers.Bounds(1.2636720449E7,2510310.336,1.2787005936E7,2660595.8230000017),
units: "meters",
controls: []
}; map = new OpenLayers.Map('map', mapOptions ); var wms = new OpenLayers.Layer.WMS(
"szroad","http://yourgeoserver:8088/geoserver/gwc/service/wms",
{layers: 'szroad', format: 'image/png' },
{ tileSize: new OpenLayers.Size(256,256) }
); var saveStrategy = new OpenLayers.Strategy.Save(); wfs = new OpenLayers.Layer.Vector("Editable Features", {
strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
projection: new OpenLayers.Projection("EPSG:900913"),
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0",
srsName: "EPSG:900913",
url: "http://yourgeoserver:8088/geoserver/wfs",
featureType: "camera",
featureNS: "http://yourgeoserver:8088/szglj",
featurePrefix:"szglj",
geometryName: "the_geom"
})
}); map.addLayers([wms, wfs]); var panel = new OpenLayers.Control.Panel(
{'displayClass': 'customEditingToolbar'}
); var navigate = new OpenLayers.Control.Navigation({
title: "Pan Map"
}); var drawCamera = new OpenLayers.Control.DrawFeature(
wfs, OpenLayers.Handler.Point,
{
title: "Draw Feature",
displayClass: "olControlDrawFeaturePoint"
}
); drawCamera.featureAdded = function(feature) {
feature.attributes ={"code":"100000001","name":"一号摄像头"};
} var editCamera = new OpenLayers.Control.ModifyFeature(wfs, {
title: "Modify Feature",
displayClass: "olControlModifyFeature"
}); var delCamera = new DeleteFeature(wfs, {title: "Delete Feature"}); var saveCamera = new OpenLayers.Control.Button({
title: "Save Changes",
trigger: function() {
if(editCamera.feature) {
editCamera.selectControl.unselectAll();
}
saveStrategy.save();
},
displayClass: "olControlSaveFeatures"
}); panel.addControls([navigate, saveCamera, delCamera, editCamera, drawCamera]);
panel.defaultControl = navigate;
map.addControl(panel);
map.zoomTo(3);
}

wfs-protocol-transactions.html

<html>
<head>
<link rel="stylesheet" href="http://liushaobo2005.blog.163.com/blog/../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="http://liushaobo2005.blog.163.com/blog/style.css" type="text/css" />
<script. src="http://liushaobo2005.blog.163.com/blog/../lib/OpenLayers.js"></script>
<style>
.customEditingToolbar {
float: right;
right: 0px;
height: 30px;
width: 200px;
}
.customEditingToolbar div {
float: right;
margin: 5px;
width: 24px;
height: 24px;
} .olControlNavigationItemActive {
background-image: url("../theme/default/img/editing_tool_bar.png");
background-repeat: no-repeat;
background-position: -103px -23px;
}
.olControlNavigationItemInactive {
background-image: url("../theme/default/img/editing_tool_bar.png");
background-repeat: no-repeat;
background-position: -103px -0px;
}
.olControlDrawFeaturePointItemInactive {
background-image: url("../theme/default/img/editing_tool_bar.png");
background-repeat: no-repeat;
background-position: -77px -0px;
}
.olControlDrawFeaturePointItemActive {
background-image: url("../theme/default/img/editing_tool_bar.png");
background-repeat: no-repeat;
background-position: -77px -23px ;
}
.olControlModifyFeatureItemActive {
background-image: url(../theme/default/img/move_feature_on.png);
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlModifyFeatureItemInactive {
background-image: url(../theme/default/img/move_feature_off.png);
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlDeleteFeatureItemActive {
background-image: url(../theme/default/img/remove_point_on.png);
background-repeat: no-repeat;
background-position: 0px 1px;
}
.olControlDeleteFeatureItemInactive {
background-image: url(../theme/default/img/remove_point_off.png);
background-repeat: no-repeat;
background-position: 0px 1px;
} </style>
<script. src="http://liushaobo2005.blog.163.com/blog/wfs-protocol-transactions.js"></script>
</head>
<body nload="init()">
<div id="map" style="width:100%;height:100%"></div>
</body>
</html>

注意:

1.openlayer中WFS layer的featureNS为geoserver中编辑的矢量图层的workspace 的Namespace URI。

2.提交wfs服务时js存在跨域问题,所以必须保证地图web server和WFS服务器在同一域环境下。

[转]openlayer+geoserver实现WFS操作的更多相关文章

  1. [转]Geoserver实现WFS操作

    From:http://liushaobo2005.blog.163.com/blog/static/253056702011541462372/ wfs是OGC的标准规范,主要用于提供对矢量地理数据 ...

  2. cesium结合geoserver利用WFS服务实现图层新增(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  3. openlayers6结合geoserver利用WFS服务实现图层新增功能(附源码下载)

    内容概览 1.openlayers6结合geoserver利用WFS服务实现图层新增功能2.源代码demo下载 效果图如下: 本篇主要是openlayers6通过调用geoserver发布的地图服务W ...

  4. leaflet结合geoserver利用WFS服务实现图层新增功能(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  5. cesium结合geoserver利用WFS服务实现图层编辑(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  6. leaflet结合geoserver利用WFS服务实现图层删除功能(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  7. cesium结合geoserver利用WFS服务实现图层删除(附源码下载)

    前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...

  8. GeoServer中WMS、WFS的请求规范

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 1.1WMS简介 Web地图服务(WMS)利用具有地理空间位置 ...

  9. GeoServer中WMS、WFS的请求规范(转载)

    1.背景 1.1WMS简介 Web地图服务(WMS)利用具有地理空间位置信息的数据制作地图.其中将地图定义为地理数据可视的表现.这个规范定义了三个操作:GetCapabitities返回服务级元数据, ...

随机推荐

  1. C# 集合详解 (适合新手)

    System.Collections 命名空间包含接口和类,这些接口和类定义各种对象(如列表.队列.位数组.哈希表和字典)的集合.System.Collections.Generic 命名空间包含定义 ...

  2. json中换行问题

    json中不能存在换行,但可以进行替换后给服务器 function(text_info) { text_info=text_info.replace(/\r/gm,"<br\>& ...

  3. Wap touch flispan demo

    直接上代码了 仔细看看例子就会明白 简单实用 <!DOCTYPE HTML> <html> <head> <meta charset="utf-8& ...

  4. UESTC_Palindromic String 2015 UESTC Training for Search Algorithm & String<Problem M>

    M - Palindromic String Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 128000/128000KB (Java ...

  5. UESTC_Infected Land 2015 UESTC Training for Search Algorithm & String<Problem G>

    G - Infected Land Time Limit: 6000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  6. [置顶] 软件设计之道_读书纪要.doc

    本系列的文档都是我读书后的个人纪要,如想了解更多相关内容,请购买正版物.对应的图书可以从我的个人图书列表里找寻:个人毕业后图书列表 1.  每个写代码的人都是设计师,团队里每个人都有责任保证自己的代码 ...

  7. UVA 246 - 10-20-30 (模拟+STL)

    UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...

  8. protobuf NET使用

    首先,开源项目地址为: protobuf NET的GITHUB地址 下载下来后,打开项目,找到目录:Core/protobuf-net,生成一下,然后就可以在bin里得到protobuf-net.dl ...

  9. NPOI新建和读取EXCEL

    //基本NPOI 1.2.5.0 static void Main(string[] args) { string path = string.Format("E:\\export{0}.x ...

  10. pl_sql 报ora-12154 无法解析指定的连接标识符的问题

    情况一:连接本地的没有问题,连接远程服务器的时候报以上错误.那么在本地客户端下的TNSNames.ora设置中配置你的远程服务器连接,本人的如下: //mestest是远程服务器名 //172.18. ...