diff --git a/externs/olx.js b/externs/olx.js index 3ce37eb603..f642f94bfe 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -1324,7 +1324,8 @@ olx.format.WFSWriteGetFeatureOptions.prototype.bbox; * featureType: string, * srsName: (string|undefined), * handle: (string|undefined), - * nativeElements: Array.}} + * nativeElements: Array., + * gmlOptions: (olx.format.GMLOptions|undefined)}} * @todo api */ olx.format.WFSWriteTransactionOptions; @@ -1373,6 +1374,13 @@ olx.format.WFSWriteTransactionOptions.prototype.handle; olx.format.WFSWriteTransactionOptions.prototype.nativeElements; +/** + * GML options for the WFS transaction writer. + * @type {olx.format.GMLOptions|undefined} + */ +olx.format.WFSWriteTransactionOptions.prototype.gmlOptions; + + /** * Interactions for the map. Default is `true` for all options. * @typedef {{altShiftDragRotate: (boolean|undefined), diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 6969ae31f8..dc4fcfd183 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -612,7 +612,9 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, 'Transaction'); node.setAttribute('service', 'WFS'); node.setAttribute('version', '1.1.0'); + var baseObj, obj; if (goog.isDef(options)) { + baseObj = goog.isDef(options.gmlOptions) ? options.gmlOptions : {}; if (goog.isDef(options.handle)) { node.setAttribute('handle', options.handle); } @@ -620,18 +622,22 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes, ol.xml.setAttributeNS(node, 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', this.schemaLocation_); if (goog.isDefAndNotNull(inserts)) { - ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, - featureType: options.featureType}, - ol.format.WFS.TRANSACTION_SERIALIZERS_, - ol.xml.makeSimpleNodeFactory('Insert'), inserts, - objectStack); + obj = {node: node, featureNS: options.featureNS, + featureType: options.featureType, featurePrefix: options.featurePrefix}; + goog.object.extend(obj, baseObj); + ol.xml.pushSerializeAndPop(obj, + ol.format.WFS.TRANSACTION_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('Insert'), inserts, + objectStack); } if (goog.isDefAndNotNull(updates)) { - ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, - featureType: options.featureType, featurePrefix: options.featurePrefix}, - ol.format.WFS.TRANSACTION_SERIALIZERS_, - ol.xml.makeSimpleNodeFactory('Update'), updates, - objectStack); + obj = {node: node, featureNS: options.featureNS, + featureType: options.featureType, featurePrefix: options.featurePrefix}; + goog.object.extend(obj, baseObj); + ol.xml.pushSerializeAndPop(obj, + ol.format.WFS.TRANSACTION_SERIALIZERS_, + ol.xml.makeSimpleNodeFactory('Update'), updates, + objectStack); } if (goog.isDefAndNotNull(deletes)) { ol.xml.pushSerializeAndPop({node: node, featureNS: options.featureNS, diff --git a/test/spec/ol/format/wfs/TransactionSrs.xml b/test/spec/ol/format/wfs/TransactionSrs.xml new file mode 100644 index 0000000000..14d109046e --- /dev/null +++ b/test/spec/ol/format/wfs/TransactionSrs.xml @@ -0,0 +1 @@ +-5178372.1885436 1992365.7775042 -4434792.7774889 1601008.1927386 -4043435.1927233 2148908.8114105xyz diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index e4bf1c1d29..0e3ea8c184 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -192,6 +192,36 @@ describe('ol.format.WFS', function() { }); + describe('when writing out a Transaction request', function() { + var text; + before(function(done) { + afterLoadText('spec/ol/format/wfs/TransactionSrs.xml', function(xml) { + text = xml; + done(); + }); + }); + it('creates the correct srsName', function() { + var format = new ol.format.WFS(); + var insertFeature = new ol.Feature({ + the_geom: new ol.geom.MultiLineString([[ + [-5178372.1885436, 1992365.7775042], + [-4434792.7774889, 1601008.1927386], + [-4043435.1927233, 2148908.8114105] + ]]), + TYPE: 'xyz' + }); + insertFeature.setGeometryName('the_geom'); + var inserts = [insertFeature]; + var serialized = format.writeTransaction(inserts, null, null, { + featureNS: 'http://foo', + featureType: 'FAULTS', + featurePrefix: 'feature', + gmlOptions: {multiCurve: true, srsName: 'EPSG:900913'} + }); + expect(serialized).to.xmleql(ol.xml.load(text)); + }); + }); + describe('when writing out a Transaction request', function() { var text; before(function(done) { @@ -317,6 +347,7 @@ describe('ol.format.WFS', function() { goog.require('ol.xml'); goog.require('ol.Feature'); +goog.require('ol.geom.MultiLineString'); goog.require('ol.geom.MultiPoint'); goog.require('ol.geom.MultiPolygon'); goog.require('ol.geom.Polygon');