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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sat Dec 4 08:44:26 EST 2010


Author: ahocevar
Date: 2010-12-04 05:44:26 -0800 (Sat, 04 Dec 2010)
New Revision: 10947

Modified:
   trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
   trunk/openlayers/tests/Protocol/WFS.html
Log:
Let the read method respect readOptions and pass them to the format's read method. r=bartvde (closes #2957)


Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2010-12-03 07:09:36 UTC (rev 10946)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js	2010-12-04 13:44:26 UTC (rev 10947)
@@ -142,12 +142,26 @@
     },
 
     /**
-     * Method: read
+     * APIMethod: read
      * Construct a request for reading new features.  Since WFS splits the
      *     basic CRUD operations into GetFeature requests (for read) and
      *     Transactions (for all others), this method does not make use of the
      *     format's read method (that is only about reading transaction
      *     responses).
+     *
+     * To use a configured protocol to get e.g. a WFS hit count, applications
+     * could do the following:
+     *
+     * (code)
+     * protocol.read({
+     *     readOptions: {output: "object"},
+     *     resultType: "hits",
+     *     maxFeatures: null,
+     *     callback: function(resp) {
+     *         // process resp.numberOfFeatures here
+     *     }
+     * });
+     * (end)
      */
     read: function(options) {
         OpenLayers.Protocol.prototype.read.apply(this, arguments);
@@ -180,15 +194,18 @@
      * options - {Object} The user options passed to the read call.
      */
     handleRead: function(response, options) {
+        options = OpenLayers.Util.extend({}, options);
+        OpenLayers.Util.applyDefaults(options, this.options);
+
         if(options.callback) {
             var request = response.priv;
             if(request.status >= 200 && request.status < 300) {
                 // success
-                if (this.readOptions && this.readOptions.output == "object") {
+                if (options.readOptions && options.readOptions.output == "object") {
                     OpenLayers.Util.extend(response, 
-                        this.parseResponse(request, this.readOptions));
+                        this.parseResponse(request, options.readOptions));
                 } else {
-                    response.features = this.parseResponse(request);
+                    response.features = this.parseResponse(request, options.readOptions);
                 }
                 response.code = OpenLayers.Protocol.Response.SUCCESS;
             } else {

Modified: trunk/openlayers/tests/Protocol/WFS.html
===================================================================
--- trunk/openlayers/tests/Protocol/WFS.html	2010-12-03 07:09:36 UTC (rev 10946)
+++ trunk/openlayers/tests/Protocol/WFS.html	2010-12-04 13:44:26 UTC (rev 10947)
@@ -25,14 +25,15 @@
     }
 
     function test_read(t) {
-        t.plan(6);
+        t.plan(7);
 
         var protocol = new OpenLayers.Protocol.WFS({
             url: "http://some.url.org",
             featureNS: "http://namespace.org",
             featureType: "type",
-            parseResponse: function(request) {
+            parseResponse: function(request, options) {
                 t.eq(request.responseText, "foo", "parseResponse called properly");
+                t.eq(options, {foo: "bar"}, "parseResponse receives readOptions");
                 return "foo";
             }
         });
@@ -44,14 +45,13 @@
             t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
             obj.status = status;
             obj.responseText = "foo";
-            obj.options = {};
             t.delay_call(0.1, function() {obj.callback.call(this)});
             return obj;
         };
 
         expected = readXML("GetFeature_1");
         status = 200;
-        var response = protocol.read({callback: function(response) {
+        var response = protocol.read({readOptions: {foo: "bar"}, callback: function(response) {
             t.eq(response.features, "foo", "user callback properly called with features");
             t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
         }});
@@ -95,7 +95,6 @@
         OpenLayers.Request.POST = function(obj) {
             t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "Transaction XML with Insert, Update and Delete created correctly");
             obj.responseText = "foo";
-            obj.options = {};
             t.delay_call(0.1, function() {obj.callback.call(this)});
             return obj;
         };
@@ -248,7 +247,6 @@
         OpenLayers.Request.POST = function(obj) {
             obj.status = 200;
             obj.responseText = "foo";
-            obj.options = {};
             t.delay_call(0.1, function() {obj.callback.call(this)});
             return obj;
         };



More information about the Commits mailing list