allow protocols to be configured with a default filter, p=aabt, r=me (closes #2292)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9702 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-10-05 12:14:37 +00:00
parent 2633f9ba88
commit 86bd389152
5 changed files with 55 additions and 2 deletions

View File

@@ -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);
},