diff --git a/src/ol/format/wfs.js b/src/ol/format/wfs.js index 098021b943..c7147487f0 100644 --- a/src/ol/format/wfs.js +++ b/src/ol/format/wfs.js @@ -980,9 +980,10 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, var schemaLocation = ol.format.WFS.SCHEMA_LOCATIONS[version]; ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', schemaLocation); + var featurePrefix = options.featurePrefix ? options.featurePrefix : ol.format.WFS.FEATURE_PREFIX; if (inserts) { obj = {node: node, 'featureNS': options.featureNS, - 'featureType': options.featureType, 'featurePrefix': options.featurePrefix, + 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName}; ol.obj.assign(obj, baseObj); ol.xml.pushSerializeAndPop(obj, @@ -992,7 +993,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, } if (updates) { obj = {node: node, 'featureNS': options.featureNS, - 'featureType': options.featureType, 'featurePrefix': options.featurePrefix, + 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName}; ol.obj.assign(obj, baseObj); ol.xml.pushSerializeAndPop(obj, @@ -1002,7 +1003,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, } if (deletes) { ol.xml.pushSerializeAndPop({node: node, 'featureNS': options.featureNS, - 'featureType': options.featureType, 'featurePrefix': options.featurePrefix, + 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'srsName': options.srsName}, ol.format.WFS.TRANSACTION_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Delete'), deletes, @@ -1010,7 +1011,7 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, } if (options.nativeElements) { ol.xml.pushSerializeAndPop({node: node, 'featureNS': options.featureNS, - 'featureType': options.featureType, 'featurePrefix': options.featurePrefix, + 'featureType': options.featureType, 'featurePrefix': featurePrefix, 'gmlVersion': gmlVersion, 'srsName': options.srsName}, ol.format.WFS.TRANSACTION_SERIALIZERS_, ol.xml.makeSimpleNodeFactory('Native'), options.nativeElements, diff --git a/test/spec/ol/format/wfs.test.js b/test/spec/ol/format/wfs.test.js index 55d3ad751a..269e152b51 100644 --- a/test/spec/ol/format/wfs.test.js +++ b/test/spec/ol/format/wfs.test.js @@ -697,6 +697,29 @@ describe('ol.format.WFS', function() { }); }); + describe('when writing out a Transaction request', function() { + + it('creates the correct update with default featurePrefix', function() { + var format = new ol.format.WFS(); + var updateFeature = new ol.Feature(); + updateFeature.setGeometryName('the_geom'); + updateFeature.setGeometry(new ol.geom.MultiLineString([[ + [-12279454, 6741885], + [-12064207, 6732101], + [-11941908, 6595126], + [-12240318, 6507071], + [-12416429, 6604910] + ]])); + updateFeature.setId('FAULTS.4455'); + var serialized = format.writeTransaction(null, [updateFeature], null, { + featureNS: 'http://foo', + featureType: 'FAULTS', + gmlOptions: {srsName: 'EPSG:900913'} + }); + expect(serialized.firstChild.attributes.getNamedItem('xmlns:feature') !== null).to.equal(true); + }); + }); + describe('when writing out a Transaction request', function() { it('does not create an update if no fid', function() {