Allow forEachRecursive to work on a collection/array.

This commit is contained in:
Oliver Jowett 2016-07-03 13:36:32 +01:00
parent 4862010d42
commit 6676bc8172

View file

@ -225,17 +225,23 @@ ol.control.LayerSwitcher.prototype.renderLayers_ = function(lyr, elm) {
/**
* **Static** Call the supplied function for each layer in the passed layer group
* recursing nested groups.
* @param {ol.layer.Group} lyr The layer group to start iterating from.
* @param {ol.layer.Group} lyr The layer group or collection/array to start iterating from.
* @param {Function} fn Callback which will be called for each `ol.layer.Base`
* found under `lyr`. The signature for `fn` is the same as `ol.Collection#forEach`
*/
ol.control.LayerSwitcher.forEachRecursive = function(lyr, fn) {
lyr.getLayers().forEach(function(lyr, idx, a) {
var traverse = function(lyr, idx, a) {
fn(lyr, idx, a);
if (lyr.getLayers) {
ol.control.LayerSwitcher.forEachRecursive(lyr, fn);
}
});
};
if (lyr.getLayers) {
lyr.getLayers().forEach(traverse);
} else {
lyr.forEach(traverse);
}
};
/**