Make filter optional

This commit is contained in:
ahocevar
2013-11-11 21:52:19 +01:00
parent 467bcc8b62
commit 299d729936
+13 -7
View File
@@ -264,16 +264,22 @@ ol.layer.Vector.prototype.getStyle = function() {
/** /**
* Returns an array of features that match a filter. This will not fetch data, * Returns an array of features that match a filter. This will not fetch data,
* it only considers features that are loaded already. * it only considers features that are loaded already.
* @param {function(ol.Feature):boolean} filter Filter function. * @param {(function(ol.Feature):boolean)=} opt_filter Filter function.
* @return {Array.<ol.Feature>} Features that match the filter. * @return {Array.<ol.Feature>} Features that match the filter, or all features
* if no filter was provided.
*/ */
ol.layer.Vector.prototype.getFeatures = function(filter) { ol.layer.Vector.prototype.getFeatures = function(opt_filter) {
var result;
var features = this.featureCache_.getFeaturesObject(); var features = this.featureCache_.getFeaturesObject();
var result = []; if (goog.isDef(opt_filter)) {
for (var f in features) { result = [];
if (filter(features[f]) === true) { for (var f in features) {
result.push(features[f]); if (opt_filter(features[f]) === true) {
result.push(features[f]);
}
} }
} else {
result = goog.object.getValues(features);
} }
return result; return result;
}; };