Search code examples
javascriptjqueryopenlayers-3geoserver

Saving Edits on a WFS using OpenLayers


So with an app that I've produced by taking this into account, I've managed to create a web map with editing function.

Problem is that, unlike in the working example, the edits are not being saved properly, so every time the page gets refreshed, it seems that the edits become lost.

Weird thing is that every time I draw a line, in my database there are new entries being created, but the geometry isn't being recorded.

The portion that saves it to the WFS layer is:

var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: 'http://geoserver.org/bftchamber',
featureType: 'bft',
srsName: 'EPSG:27700'
});
var transactWFS = function(p,f) {
switch(p) {
case 'insert':
    node = formatWFS.writeTransaction([f],null,null,formatGML);
    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);
$.ajax('http://localhost:8080/geoserver/wfs',{
    type: 'POST',
    dataType: 'xml',
    processData: false,
    contentType: 'text/xml',
    data: str
    }).done();
}

Fiddle is here https://jsfiddle.net/Luffydude/ex06jr1e/7/


Solution

  • Turns out that the problem lied in the fact that my geometry column needed to be called geometry and OpenLayers only works with with EPSG:3857.

    The code is correct