diff --git a/lib/OpenLayers/Format/WFST/v1.js b/lib/OpenLayers/Format/WFST/v1.js index 7bc4dd4e4d..2e8c283eae 100644 --- a/lib/OpenLayers/Format/WFST/v1.js +++ b/lib/OpenLayers/Format/WFST/v1.js @@ -105,13 +105,31 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { }, /** - * Method: read + * APIMethod: read * Parse the response from a transaction. Because WFS is split into * Transaction requests (create, update, and delete) and GetFeature * requests (read), this method handles parsing of both types of * responses. + * + * Parameters: + * data - {String | Document} The WFST document to read + * options - {Object} Options for the reader + * + * Valid options properties: + * output - {String} either "features" or "object". The default is + * "features", which means that the method will return an array of + * features. If set to "object", an object with a "features" property + * and other properties read by the parser will be returned. + * + * Returns: + * {Array | Object} Output depending on the output option. */ - read: function(data) { + read: function(data, options) { + options = options || {}; + OpenLayers.Util.applyDefaults(options, { + output: "features" + }); + if(typeof data == "string") { data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); } @@ -122,7 +140,7 @@ OpenLayers.Format.WFST.v1 = OpenLayers.Class(OpenLayers.Format.XML, { if(data) { this.readNode(data, obj); } - if(obj.features) { + if(obj.features && options.output === "features") { obj = obj.features; } return obj; diff --git a/lib/OpenLayers/Format/WFST/v1_1_0.js b/lib/OpenLayers/Format/WFST/v1_1_0.js index 23b446caac..56b215aa6f 100644 --- a/lib/OpenLayers/Format/WFST/v1_1_0.js +++ b/lib/OpenLayers/Format/WFST/v1_1_0.js @@ -33,6 +33,12 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class( * Constructor: OpenLayers.Format.WFST.v1_1_0 * A class for parsing and generating WFS v1.1.0 transactions. * + * To read additional information like hit count (numberOfFeatures) from + * the FeatureCollection, call the method + * with {output: "object"} as 2nd argument. Note that it is possible to + * just request the hit count from a WFS 1.1.0 server with the + * resultType="hits" request parameter. + * * Parameters: * options - {Object} Optional object whose properties will be set on the * instance. @@ -59,6 +65,12 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class( */ readers: { "wfs": OpenLayers.Util.applyDefaults({ + "FeatureCollection": function(node, obj) { + obj.numberOfFeatures = parseInt(node.getAttribute( + "numberOfFeatures")); + OpenLayers.Format.WFST.v1.prototype.readers["wfs"]["FeatureCollection"].apply( + this, arguments); + }, "TransactionResponse": function(node, obj) { obj.insertIds = []; obj.success = false; diff --git a/tests/Format/WFST/v1_1_0.html b/tests/Format/WFST/v1_1_0.html index 78d7fe7bdf..c5ab632c63 100644 --- a/tests/Format/WFST/v1_1_0.html +++ b/tests/Format/WFST/v1_1_0.html @@ -22,7 +22,18 @@ t.eq(result.insertIds[0], "none", "InsertIds read correctly"); t.eq(result.success, true, "Success read correctly"); } - + + function test_read_hits(t) { + t.plan(1); + var data = readXML("NumberOfFeatures"); + var format = new OpenLayers.Format.WFST.v1_1_0({ + featureNS: "http://mapserver.gis.umn.edu/mapserver", + featureType: "AAA64" + }); + var result = format.read(data, {output: "object"}); + t.eq(result.numberOfFeatures, 625, "numberOfFeatures of FeatureCollection correctly read"); + } + function test_write(t) { var format = new OpenLayers.Format.WFST.v1_1_0({ @@ -70,6 +81,17 @@
+