Adding OpenLayers.Array.filter to mimic Array.prototype.filter. Adding panel.getControlsBy and related methods that use filter. Reworking map.getBy to use filter as well. r=elemoine (closes #1203)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5532 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -192,6 +192,71 @@ OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.activateControl(ctrl);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getControlsBy
|
||||
* Get a list of controls with properties matching the given criteria.
|
||||
*
|
||||
* Parameter:
|
||||
* property - {String} A control property to be matched.
|
||||
* match - {String | Object} A string to match. Can also be a regular
|
||||
* expression literal or object. In addition, it can be any object
|
||||
* with a method named test. For reqular expressions or other, if
|
||||
* match.test(control[property]) evaluates to true, the control will be
|
||||
* included in the array returned. If no controls are found, an empty
|
||||
* array is returned.
|
||||
*
|
||||
* Returns:
|
||||
* {Array(<OpenLayers.Control>)} A list of controls matching the given criteria.
|
||||
* An empty array is returned if no matches are found.
|
||||
*/
|
||||
getControlsBy: function(property, match) {
|
||||
var test = (typeof match.test == "function");
|
||||
var found = OpenLayers.Array.filter(this.controls, function(item) {
|
||||
return item[property] == match || (test && match.test(item[property]));
|
||||
});
|
||||
return found;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getControlsByName
|
||||
* Get a list of contorls with names matching the given name.
|
||||
*
|
||||
* Parameter:
|
||||
* match - {String | Object} A control name. The name can also be a regular
|
||||
* expression literal or object. In addition, it can be any object
|
||||
* with a method named test. For reqular expressions or other, if
|
||||
* name.test(control.name) evaluates to true, the control will be included
|
||||
* in the list of controls returned. If no controls are found, an empty
|
||||
* array is returned.
|
||||
*
|
||||
* Returns:
|
||||
* {Array(<OpenLayers.Control>)} A list of controls matching the given name.
|
||||
* An empty array is returned if no matches are found.
|
||||
*/
|
||||
getControlsByName: function(match) {
|
||||
return this.getControlsBy("name", match);
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getControlsByClass
|
||||
* Get a list of controls of a given type (CLASS_NAME).
|
||||
*
|
||||
* Parameter:
|
||||
* match - {String | Object} A control class name. The type can also be a
|
||||
* regular expression literal or object. In addition, it can be any
|
||||
* object with a method named test. For reqular expressions or other,
|
||||
* if type.test(control.CLASS_NAME) evaluates to true, the control will
|
||||
* be included in the list of controls returned. If no controls are
|
||||
* found, an empty array is returned.
|
||||
*
|
||||
* Returns:
|
||||
* {Array(<OpenLayers.Control>)} A list of controls matching the given type.
|
||||
* An empty array is returned if no matches are found.
|
||||
*/
|
||||
getControlsByClass: function(match) {
|
||||
return this.getControlsBy("CLASS_NAME", match);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.Panel"
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user