[OpenLayers-Commits] r12171 - in trunk/openlayers: lib/OpenLayers/Format/GML lib/OpenLayers/Format/WFST tests/Format/WFST

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jul 15 10:07:40 EDT 2011


Author: ahocevar
Date: 2011-07-15 07:07:39 -0700 (Fri, 15 Jul 2011)
New Revision: 12171

Modified:
   trunk/openlayers/lib/OpenLayers/Format/GML/Base.js
   trunk/openlayers/lib/OpenLayers/Format/GML/v3.js
   trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
   trunk/openlayers/tests/Format/WFST/v1.html
Log:
reassign writers instead of creating a different geometry instance. r=bartvde (closes #3407)

Modified: trunk/openlayers/lib/OpenLayers/Format/GML/Base.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/GML/Base.js	2011-07-15 09:44:08 UTC (rev 12170)
+++ trunk/openlayers/lib/OpenLayers/Format/GML/Base.js	2011-07-15 14:07:39 UTC (rev 12171)
@@ -502,8 +502,9 @@
             },
             "MultiPoint": function(geometry) {
                 var node = this.createElementNSPlus("gml:MultiPoint");
-                for(var i=0; i<geometry.components.length; ++i) {
-                    this.writeNode("pointMember", geometry.components[i], node);
+                var components = geometry.components || [geometry];
+                for(var i=0, ii=components.length; i<ii; ++i) {
+                    this.writeNode("pointMember", components[i], node);
                 }
                 return node;
             },
@@ -514,8 +515,9 @@
             },
             "MultiLineString": function(geometry) {
                 var node = this.createElementNSPlus("gml:MultiLineString");
-                for(var i=0; i<geometry.components.length; ++i) {
-                    this.writeNode("lineStringMember", geometry.components[i], node);
+                var components = geometry.components || [geometry];
+                for(var i=0, ii=components.length; i<ii; ++i) {
+                    this.writeNode("lineStringMember", components[i], node);
                 }
                 return node;
             },
@@ -526,9 +528,10 @@
             },
             "MultiPolygon": function(geometry) {
                 var node = this.createElementNSPlus("gml:MultiPolygon");
-                for(var i=0; i<geometry.components.length; ++i) {
+                var components = geometry.components || [geometry];
+                for(var i=0, ii=components.length; i<ii; ++i) {
                     this.writeNode(
-                        "polygonMember", geometry.components[i], node
+                        "polygonMember", components[i], node
                     );
                 }
                 return node;

Modified: trunk/openlayers/lib/OpenLayers/Format/GML/v3.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/GML/v3.js	2011-07-15 09:44:08 UTC (rev 12170)
+++ trunk/openlayers/lib/OpenLayers/Format/GML/v3.js	2011-07-15 14:07:39 UTC (rev 12171)
@@ -378,8 +378,9 @@
             },
             "MultiCurve": function(geometry) {
                 var node = this.createElementNSPlus("gml:MultiCurve");
-                for(var i=0, len=geometry.components.length; i<len; ++i) {
-                    this.writeNode("curveMember", geometry.components[i], node);
+                var components = geometry.components || [geometry];
+                for(var i=0, len=components.length; i<len; ++i) {
+                    this.writeNode("curveMember", components[i], node);
                 }
                 return node;
             },
@@ -394,8 +395,9 @@
             },
             "MultiSurface": function(geometry) {
                 var node = this.createElementNSPlus("gml:MultiSurface");
-                for(var i=0, len=geometry.components.length; i<len; ++i) {
-                    this.writeNode("surfaceMember", geometry.components[i], node);
+                var components = geometry.components || [geometry];
+                for(var i=0, len=components.length; i<len; ++i) {
+                    this.writeNode("surfaceMember", components[i], node);
                 }
                 return node;
             },

Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-07-15 09:44:08 UTC (rev 12170)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1.js	2011-07-15 14:07:39 UTC (rev 12171)
@@ -71,7 +71,7 @@
      * {Object} Maps feature states to node names.
      */
     stateName: null,
-
+    
     /**
      * Constructor: OpenLayers.Format.WFST.v1
      * Instances of this class are not created directly.  Use the
@@ -241,42 +241,43 @@
                 return node;
             },
             "Transaction": function(obj) {
-                var options = obj && obj.options;
+                obj = obj || {};
+                var options = obj.options || {};
                 var node = this.createElementNSPlus("wfs:Transaction", {
                     attributes: {
                         service: "WFS",
                         version: this.version,
-                        handle: options && options.handle
+                        handle: options.handle
                     }
                 });
                 var i, len;
-                var features = obj && obj.features;
+                var features = obj.features;
                 if(features) {
-                    var name, feature, geometry;
+                    // temporarily re-assigning geometry types
+                    if (options.multi === true) {
+                        OpenLayers.Util.extend(this.geometryTypes, {
+                            "OpenLayers.Geometry.Point": "MultiPoint",
+                            "OpenLayers.Geometry.LineString": (this.multiCurve === true) ? "MultiCurve": "MultiLineString",
+                            "OpenLayers.Geometry.Polygon": (this.multiSurface === true) ? "MultiSurface" : "MultiPolygon"
+                        });
+                    }
+                    var name, feature;
                     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: feature, 
                                 options: options
                             }, node);
                         }
                     }
+                    // switch back to original geometry types assignment
+                    if (options.multi === true) {
+                        this.setGeometryTypes();
+                    }
                 }
-                if (options && options.nativeElements) {
+                if (options.nativeElements) {
                     for (i=0, len=options.nativeElements.length; i<len; ++i) {
                         this.writeNode("wfs:Native", 
                             options.nativeElements[i], node);

Modified: trunk/openlayers/tests/Format/WFST/v1.html
===================================================================
--- trunk/openlayers/tests/Format/WFST/v1.html	2011-07-15 09:44:08 UTC (rev 12170)
+++ trunk/openlayers/tests/Format/WFST/v1.html	2011-07-15 14:07:39 UTC (rev 12171)
@@ -176,7 +176,7 @@
     }
     
     function test_write_multi(t) {
-        t.plan(1);
+        t.plan(2);
         var format = new OpenLayers.Format.WFST({
             featureNS: "http://www.openplans.org/topp",
             featureType: "states",
@@ -203,11 +203,13 @@
         var features = [insertFeature, updateFeature];
 
         var expected = readXML("TransactionMulti");
+        var geomTypes = OpenLayers.Util.extend({}, format.geometryTypes);
         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");
+        t.eq(format.geometryTypes, geomTypes, "geometry types unchanged after write with multi option");
     }
 
     function readXML(id) {



More information about the Commits mailing list