diff --git a/lib/OpenLayers/Format/WFST/v1.js b/lib/OpenLayers/Format/WFST/v1.js index 118888b463..2b68b0658b 100644 --- a/lib/OpenLayers/Format/WFST/v1.js +++ b/lib/OpenLayers/Format/WFST/v1.js @@ -190,6 +190,10 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { * in *modified.attributes* will be included. If *modified.geometry* * is not set, the geometry will not be included. * + * Valid options include: + * - *multi* {Boolean} If set to true, geometries will be casted to + * Multi geometries before writing. + * * Returns: * {String} A serialized WFS transaction. */ @@ -246,11 +250,23 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { var features = obj && obj.features; var options = obj && obj.options; if(features) { - var name, feature; + var name, feature, geometry; for(i=0, len=features.length; i. Otherwise, the default is 'the_geom'. + * multi - {Boolean} If set to true, geometries will be casted to Multi + * geometries before they are written in a transaction. No casting will + * be done when reading features. */ initialize: function(options) { OpenLayers.Protocol.prototype.initialize.apply(this, [options]); diff --git a/tests/Format/WFST/v1.html b/tests/Format/WFST/v1.html index 6833a2b7ca..55b6543407 100644 --- a/tests/Format/WFST/v1.html +++ b/tests/Format/WFST/v1.html @@ -174,6 +174,41 @@ t.xml_eq(got, expected, snippet + " request created correctly with multiple typenames"); } } + + function test_write_multi(t) { + t.plan(1); + var format = new OpenLayers.Format.WFST({ + featureNS: "http://www.openplans.org/topp", + featureType: "states", + featurePrefix: "topp", + geometryName: "the_geom" + }); + + var feature = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(1,2), + {foo: "bar"} + ); + + var insertFeature = feature.clone(); + // null value does not show up in insert + insertFeature.attributes.nul = null; + insertFeature.state = OpenLayers.State.INSERT; + var updateFeature = feature.clone(); + // undefined value means don't create a Property element + updateFeature.attributes.unwritten = undefined; + // null value gets Property element with no Value + updateFeature.attributes.nul = null; + updateFeature.fid = "fid.42"; + updateFeature.state = OpenLayers.State.UPDATE; + var features = [insertFeature, updateFeature]; + + var expected = readXML("TransactionMulti"); + var got = format.writers["wfs"]["Transaction"].apply(format, [{ + features: features, + options: {multi: true}} + ]); + t.xml_eq(got, expected, "Transaction request with multi option created correctly"); + } function readXML(id) { var xml = document.getElementById(id).firstChild.nodeValue; @@ -243,6 +278,48 @@
+