Created
December 31, 2013 15:50
-
-
Save acanimal/8198685 to your computer and use it in GitHub Desktop.
OpenLayers3, given an initial layer (a group or a single layer) finds recursively a layer with the specified key-value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Finds recursively the layer with the specified key and value. | |
* @param {ol.layer.Base} layer | |
* @param {String} key | |
* @param {any} value | |
* @returns {ol.layer.Base} | |
*/ | |
function findBy(layer, key, value) { | |
if (layer.get(key) === value) { | |
return layer; | |
} | |
// Find recursively if it is a group | |
if (layer.getLayers) { | |
var layers = layer.getLayers().getArray(), | |
len = layers.length, result; | |
for (var i = 0; i < len; i++) { | |
result = findBy(layers[i], key, value); | |
if (result) { | |
return result; | |
} | |
} | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment