Add ol.source.Vector#forEachFeatureInExtent and #getAllFeaturesInExtent

This commit is contained in:
Tom Payne
2013-11-07 10:04:31 +01:00
parent 63a0219f3d
commit 67cd0597bb
2 changed files with 70 additions and 12 deletions
+22 -1
View File
@@ -68,11 +68,32 @@ ol.source.Vector.prototype.addFeature = function(feature) {
};
/**
* @param {ol.Extent} extent Extent.
* @param {function(this: T, ol.Feature): S} f Callback.
* @param {T=} opt_obj The object to be used a the value of 'this' within f.
* @return {S|undefined}
* @template T,S
*/
ol.source.Vector.prototype.forEachFeatureInExtent =
function(extent, f, opt_obj) {
var features = this.getAllFeaturesInExtent(extent);
var i, ii;
for (i = 0, ii = features.length; i < ii; ++i) {
var result = f.call(opt_obj, features[i]);
if (result) {
return result;
}
}
return undefined;
};
/**
* @param {ol.Extent} extent Extent.
* @return {Array.<ol.Feature>} Features.
*/
ol.source.Vector.prototype.getFeatures = function(extent) {
ol.source.Vector.prototype.getAllFeaturesInExtent = function(extent) {
return this.rTree_.search(extent);
};