[OpenLayers-Commits] r10955 - in trunk/openlayers: lib/OpenLayers/Protocol/WFS tests/Protocol

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue Dec 7 18:56:32 EST 2010


Author: ahocevar
Date: 2010-12-07 15:56:32 -0800 (Tue, 07 Dec 2010)
New Revision: 10955

Modified:
   trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
   trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js
   trunk/openlayers/tests/Protocol/WFS.html
Log:
auto-create the GetFeature readFormat for known outputFormats. r=tschaub (closes #2968) 


Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2010-12-07 23:48:20 UTC (rev 10954)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2010-12-07 23:56:32 UTC (rev 10955)
@@ -77,7 +77,7 @@
      *     the response with the default format (WFST) and we need a different 
      *     format for reading. 
      */ 
-    readFormat: null,     
+    readFormat: null,
     
     /**
      * Property: readOptions

Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js	2010-12-07 23:48:20 UTC (rev 10954)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1_1_0.js	2010-12-07 23:56:32 UTC (rev 10955)
@@ -42,7 +42,27 @@
      * featurePrefix - {String} Feature namespace alias (optional - only used
      *     if featureNS is provided).  Default is 'feature'.
      * geometryName - {String} Name of geometry attribute.  Default is 'the_geom'.
+     * outputFormat - {String} Optional output format to use for WFS GetFeature
+     *     requests. This can be any format advertized by the WFS's
+     *     GetCapabilities response. If set, an appropriate readFormat also
+     *     has to be provided, unless outputFormat is GML3, GML2 or JSON.
+     * readFormat - {<OpenLayers.Format>} An appropriate format parser if
+     *     outputFormat is none of GML3, GML2 or JSON.
      */
+    initialize: function(options) {
+        OpenLayers.Protocol.WFS.v1.prototype.initialize.apply(this, arguments);
+        if (this.outputFormat && !this.readFormat) {
+            if (this.outputFormat.toLowerCase() == "gml2") {
+                this.readFormat = new OpenLayers.Format.GML.v2({
+                    featureType: this.featureType,
+                    featureNS: this.featureNS,
+                    geometryName: this.geometryName
+                });
+            } else if (this.outputFormat.toLowerCase() == "json") {
+                this.readFormat = new OpenLayers.Format.GeoJSON();
+            }
+        }
+    },
    
     CLASS_NAME: "OpenLayers.Protocol.WFS.v1_1_0"
 });

Modified: trunk/openlayers/tests/Protocol/WFS.html
===================================================================
--- trunk/openlayers/tests/Protocol/WFS.html	2010-12-07 23:48:20 UTC (rev 10954)
+++ trunk/openlayers/tests/Protocol/WFS.html	2010-12-07 23:56:32 UTC (rev 10955)
@@ -228,6 +228,30 @@
         t.eq(features.length, 1, "the right format is used to read the request (GeoJSON)");
  	}
 
+    function test_outputFormat(t) {
+        t.plan(2);
+
+        var protocol = new OpenLayers.Protocol.WFS({
+            version: "1.1.0",
+            url: "http://some.url.org",
+            featureNS: "http://namespace.org",
+            featureType: "type",
+            outputFormat: 'json'
+        });
+
+        t.ok(protocol.readFormat instanceof OpenLayers.Format.GeoJSON, "the correct readFormat is used for outputFormat JSON");
+
+        protocol = new OpenLayers.Protocol.WFS({
+            version: "1.1.0",
+            url: "http://some.url.org",
+            featureNS: "http://namespace.org",
+            featureType: "type",
+            outputFormat: 'GML2'
+        });
+
+        t.ok(protocol.readFormat instanceof OpenLayers.Format.GML.v2, "the correct readFormat is used for outputFormat GML2");
+ 	}
+
     function test_readOptions(t) {
         t.plan(1);
 



More information about the Commits mailing list