diff --git a/lib/OpenLayers/Protocol.js b/lib/OpenLayers/Protocol.js index f4fd833360..9a2829bc1a 100755 --- a/lib/OpenLayers/Protocol.js +++ b/lib/OpenLayers/Protocol.js @@ -29,6 +29,12 @@ OpenLayers.Protocol = OpenLayers.Class({ */ autoDestroy: true, + /** + * Property: defaultFilter + * {OpenLayers.Filter} Optional default filter to read requests + */ + defaultFilter: null, + /** * Constructor: OpenLayers.Protocol * Abstract class for vector protocols. Create instances of a subclass. @@ -43,6 +49,28 @@ OpenLayers.Protocol = OpenLayers.Class({ this.options = options; }, + /** + * Method: mergeWithDefaultFilter + * Merge filter passed to the read method with the default one + * + * Parameters: + * filter - {OpenLayers.Filter} + */ + mergeWithDefaultFilter: function(filter) { + if(filter) { + if(this.defaultFilter) { + filter = new OpenLayers.Filter.Logical({ + type: OpenLayers.Filter.Logical.AND, + filters: [this.defaultFilter, filter] + }); + } + } else { + filter = this.defaultFilter; + } + return filter; + }, + + /** * APIMethod: destroy * Clean up the protocol. @@ -64,7 +92,9 @@ OpenLayers.Protocol = OpenLayers.Class({ * object, the same object will be passed to the callback function passed * if one exists in the options object. */ - read: function() { + read: function(options) { + options = options || {}; + options.filter = this.mergeWithDefaultFilter(options.filter); }, diff --git a/lib/OpenLayers/Protocol/HTTP.js b/lib/OpenLayers/Protocol/HTTP.js index cb34d58372..337c9aa1d9 100644 --- a/lib/OpenLayers/Protocol/HTTP.js +++ b/lib/OpenLayers/Protocol/HTTP.js @@ -136,6 +136,7 @@ OpenLayers.Protocol.HTTP = OpenLayers.Class(OpenLayers.Protocol, { * is then populated with the the features received from the server. */ read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); options = OpenLayers.Util.applyDefaults(options, this.options); var readWithPOST = (options.readWithPOST !== undefined) ? options.readWithPOST : this.readWithPOST; diff --git a/lib/OpenLayers/Protocol/SQL/Gears.js b/lib/OpenLayers/Protocol/SQL/Gears.js index efd4ef0b61..57eef38629 100644 --- a/lib/OpenLayers/Protocol/SQL/Gears.js +++ b/lib/OpenLayers/Protocol/SQL/Gears.js @@ -154,6 +154,7 @@ OpenLayers.Protocol.SQL.Gears = OpenLayers.Class(OpenLayers.Protocol.SQL, { * object. */ read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); options = OpenLayers.Util.applyDefaults(options, this.options); var feature, features = []; diff --git a/lib/OpenLayers/Protocol/WFS/v1.js b/lib/OpenLayers/Protocol/WFS/v1.js index a6a8e7b99f..6de8a671a3 100644 --- a/lib/OpenLayers/Protocol/WFS/v1.js +++ b/lib/OpenLayers/Protocol/WFS/v1.js @@ -147,6 +147,7 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, { * responses). */ read: function(options) { + OpenLayers.Protocol.prototype.read.apply(this, arguments); options = OpenLayers.Util.extend({}, options); OpenLayers.Util.applyDefaults(options, this.options || {}); var response = new OpenLayers.Protocol.Response({requestType: "read"}); diff --git a/tests/Protocol.html b/tests/Protocol.html index e3ef06db70..90391aa5e0 100644 --- a/tests/Protocol.html +++ b/tests/Protocol.html @@ -4,16 +4,36 @@