[OpenLayers-Commits] r12168 - in trunk/openlayers: lib/OpenLayers/Format/WFST lib/OpenLayers/Protocol/WFS tests/Format/WFST

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Jul 13 09:48:32 EDT 2011


Author: ahocevar
Date: 2011-07-13 06:48:31 -0700 (Wed, 13 Jul 2011)
New Revision: 12168

Modified:
   trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
   trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
   trunk/openlayers/tests/Format/WFST/v1.html
Log:
giving the WFST format a multi option, which makes sure that Multi geometries are written in transactions. r=bartvde (closes #3407)

Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-07-12 16:48:39 UTC (rev 12167)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-07-13 13:48:31 UTC (rev 12168)
@@ -190,6 +190,10 @@
      *     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 @@
                 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<len; ++i) {
                         feature = features[i];
                         name = this.stateName[feature.state];
                         if(name) {
+                            geometry = feature.geometry;
+                            if (options && options.multi === true && geometry) {
+                                var type = geometry.CLASS_NAME.split(".").pop();
+                                if (type.indexOf("Multi") != 0) {
+                                    var Cls = OpenLayers.Geometry["Multi" + type];
+                                    if (Cls) {
+                                        feature = OpenLayers.Util.applyDefaults({
+                                            geometry: new Cls([geometry])
+                                        }, feature);
+                                    }
+                                }
+                            }
                             this.writeNode(name, feature, node);
                         }
                     }

Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2011-07-12 16:48:39 UTC (rev 12167)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2011-07-13 13:48:31 UTC (rev 12168)
@@ -105,6 +105,9 @@
      * geometryName - {String} Name of geometry attribute.  If featureNS is not
      *     configured, the default is null to avoid failing on BBOX filters,
      *     and it will be set on <read>. 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]);

Modified: trunk/openlayers/tests/Format/WFST/v1.html
===================================================================
--- trunk/openlayers/tests/Format/WFST/v1.html	2011-07-12 16:48:39 UTC (rev 12167)
+++ trunk/openlayers/tests/Format/WFST/v1.html	2011-07-13 13:48:31 UTC (rev 12168)
@@ -174,7 +174,42 @@
             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;
         return new OpenLayers.Format.XML().read(xml).documentElement;
@@ -243,6 +278,48 @@
 <div id="Transaction"><!--
 <wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0"/>
 --></div>
+<div id="TransactionMulti"><!--
+<wfs:Transaction xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0">
+    <wfs:Insert>
+        <feature:states xmlns:feature="http://www.openplans.org/topp">
+            <feature:the_geom>
+                <gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
+                    <gml:pointMember>
+                        <gml:Point>
+                            <gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
+                        </gml:Point>
+                    </gml:pointMember>
+                </gml:MultiPoint>
+            </feature:the_geom>
+            <feature:foo>bar</feature:foo>
+        </feature:states>
+    </wfs:Insert>
+    <wfs:Update xmlns:wfs="http://www.opengis.net/wfs" typeName="topp:states" xmlns:topp="http://www.openplans.org/topp">
+        <wfs:Property>
+            <wfs:Name>the_geom</wfs:Name>
+            <wfs:Value>
+                <gml:MultiPoint xmlns:gml="http://www.opengis.net/gml">
+                    <gml:pointMember>
+                        <gml:Point>
+                            <gml:coordinates decimal="." cs="," ts=" ">1,2</gml:coordinates>
+                        </gml:Point>
+                    </gml:pointMember>
+                </gml:MultiPoint>
+            </wfs:Value>
+        </wfs:Property>
+        <wfs:Property>
+            <wfs:Name>foo</wfs:Name>
+            <wfs:Value>bar</wfs:Value>
+        </wfs:Property>
+        <wfs:Property>
+            <wfs:Name>nul</wfs:Name>
+        </wfs:Property>
+        <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
+            <ogc:FeatureId fid="fid.42"/>
+        </ogc:Filter>
+    </wfs:Update>
+</wfs:Transaction>
+--></div>
 <div id="Insert"><!--
 <wfs:Insert xmlns:wfs="http://www.opengis.net/wfs">
     <feature:states xmlns:feature="http://www.openplans.org/topp">



More information about the Commits mailing list