Let the read method respect readOptions and pass them to the format's read method. r=bartvde (closes #2957)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10947 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -142,12 +142,26 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: read
|
* APIMethod: read
|
||||||
* Construct a request for reading new features. Since WFS splits the
|
* Construct a request for reading new features. Since WFS splits the
|
||||||
* basic CRUD operations into GetFeature requests (for read) and
|
* basic CRUD operations into GetFeature requests (for read) and
|
||||||
* Transactions (for all others), this method does not make use of the
|
* Transactions (for all others), this method does not make use of the
|
||||||
* format's read method (that is only about reading transaction
|
* format's read method (that is only about reading transaction
|
||||||
* responses).
|
* 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) {
|
read: function(options) {
|
||||||
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
OpenLayers.Protocol.prototype.read.apply(this, arguments);
|
||||||
@@ -180,15 +194,18 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
|
|||||||
* options - {Object} The user options passed to the read call.
|
* options - {Object} The user options passed to the read call.
|
||||||
*/
|
*/
|
||||||
handleRead: function(response, options) {
|
handleRead: function(response, options) {
|
||||||
|
options = OpenLayers.Util.extend({}, options);
|
||||||
|
OpenLayers.Util.applyDefaults(options, this.options);
|
||||||
|
|
||||||
if(options.callback) {
|
if(options.callback) {
|
||||||
var request = response.priv;
|
var request = response.priv;
|
||||||
if(request.status >= 200 && request.status < 300) {
|
if(request.status >= 200 && request.status < 300) {
|
||||||
// success
|
// success
|
||||||
if (this.readOptions && this.readOptions.output == "object") {
|
if (options.readOptions && options.readOptions.output == "object") {
|
||||||
OpenLayers.Util.extend(response,
|
OpenLayers.Util.extend(response,
|
||||||
this.parseResponse(request, this.readOptions));
|
this.parseResponse(request, options.readOptions));
|
||||||
} else {
|
} else {
|
||||||
response.features = this.parseResponse(request);
|
response.features = this.parseResponse(request, options.readOptions);
|
||||||
}
|
}
|
||||||
response.code = OpenLayers.Protocol.Response.SUCCESS;
|
response.code = OpenLayers.Protocol.Response.SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,14 +25,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_read(t) {
|
function test_read(t) {
|
||||||
t.plan(6);
|
t.plan(7);
|
||||||
|
|
||||||
var protocol = new OpenLayers.Protocol.WFS({
|
var protocol = new OpenLayers.Protocol.WFS({
|
||||||
url: "http://some.url.org",
|
url: "http://some.url.org",
|
||||||
featureNS: "http://namespace.org",
|
featureNS: "http://namespace.org",
|
||||||
featureType: "type",
|
featureType: "type",
|
||||||
parseResponse: function(request) {
|
parseResponse: function(request, options) {
|
||||||
t.eq(request.responseText, "foo", "parseResponse called properly");
|
t.eq(request.responseText, "foo", "parseResponse called properly");
|
||||||
|
t.eq(options, {foo: "bar"}, "parseResponse receives readOptions");
|
||||||
return "foo";
|
return "foo";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -44,14 +45,13 @@
|
|||||||
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
|
t.xml_eq(new OpenLayers.Format.XML().read(obj.data).documentElement, expected, "GetFeature request is correct");
|
||||||
obj.status = status;
|
obj.status = status;
|
||||||
obj.responseText = "foo";
|
obj.responseText = "foo";
|
||||||
obj.options = {};
|
|
||||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
expected = readXML("GetFeature_1");
|
expected = readXML("GetFeature_1");
|
||||||
status = 200;
|
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.features, "foo", "user callback properly called with features");
|
||||||
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
|
t.eq(response.code, OpenLayers.Protocol.Response.SUCCESS, "success reported properly");
|
||||||
}});
|
}});
|
||||||
@@ -95,7 +95,6 @@
|
|||||||
OpenLayers.Request.POST = function(obj) {
|
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");
|
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.responseText = "foo";
|
||||||
obj.options = {};
|
|
||||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
@@ -248,7 +247,6 @@
|
|||||||
OpenLayers.Request.POST = function(obj) {
|
OpenLayers.Request.POST = function(obj) {
|
||||||
obj.status = 200;
|
obj.status = 200;
|
||||||
obj.responseText = "foo";
|
obj.responseText = "foo";
|
||||||
obj.options = {};
|
|
||||||
t.delay_call(0.1, function() {obj.callback.call(this)});
|
t.delay_call(0.1, function() {obj.callback.call(this)});
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user