我有一个简单的网络 Map 应用程序,尝试通过带有openlayers 3的WFS-T层向 Map 添加点 . 对于后端我'm using geoserver v2.8.0 and a postGIS database. I'已经关注了dbauszus的精彩教程,我已经阅读了有关堆栈溢出的this问题,这指向了我正确的方向,但我仍然缺少一些观点 . 将's kind of strange because when i add a point to the map it get'转移到postGIS数据库中,设置了ID并设置了属性"test",但几何列为空 . 我'm assuming something with my transferred xml is not right but i can't弄明白了什么 .
啊,不知道它是否有帮助,但我的地理服务器上启用了CORS,我正在本地Web服务器上运行html站点 .
目前我的代码如下所示:
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: 'vm',
featurePrefix:'vm',
featureType: 'GT_Projects',
srsName: 'EPSG:3857'
});
var transactWFS = function(p,f) {
switch(p) {
case 'insert':
node = formatWFS.writeTransaction([f],null,null,formatGML);
console.log(node);
break;
case 'update':
node = formatWFS.writeTransaction(null,[f],null,formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null,null,[f],formatGML);
break;
}
s = new XMLSerializer();
str = s.serializeToString(node);
console.log(str);
$.ajax('http://geoserver-vmarquar.rhcloud.com:80/wfs',{
type: 'POST',
contentType: 'text/xml',
dataType: 'xml',
processData: false,
data: str
}).done();
}
$('.btnMenu').on('click', function(event) {
$('.btnMenu').removeClass('orange');
$(this).addClass('orange');
map.removeInteraction(interaction);
select.getFeatures().clear();
map.removeInteraction(select);
switch($(this).attr('id')) {
// DRAW POINT
case 'btnDrawPoint':
interaction = new ol.interaction.Draw({
type: 'Point',
source: layerVector.getSource()
});
map.addInteraction(interaction);
interaction.on('drawend', function(e) {
var feature = e.feature;
feature.set('name', "test");
// feature.set('geom', feature.getGeometry());
transactWFS('insert',feature);
});
break;
提前致谢!