From 2276764951eb793bfed8cc868a664bcbd9d51850 Mon Sep 17 00:00:00 2001 From: simonseyock Date: Sat, 16 Dec 2017 15:44:27 +0100 Subject: [PATCH] source.Vector --- changelog/upgrade-notes.md | 1 + src/ol/source/Vector.js | 52 ++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index f8d68998e5..f6f55644b1 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -43,6 +43,7 @@ The following methods did get the optional this (i.e. opt_this) arguments remove * geom/LineString#forEachSegment * Observable#on, #once, #un * source/TileUTFGrid#forDataAtCoordinateAndResolution +* source/Vector#forEachFeature, #forEachFeatureInExtent, #forEachFeatureIntersectingExtent ### v4.6.0 diff --git a/src/ol/source/Vector.js b/src/ol/source/Vector.js index 4663256a7c..3f1fc64de6 100644 --- a/src/ol/source/Vector.js +++ b/src/ol/source/Vector.js @@ -379,18 +379,17 @@ _ol_source_Vector_.prototype.clear = function(opt_fast) { * with each one. If the callback returns any "truthy" value, iteration will * stop and the function will return the same value. * - * @param {function(this: T, ol.Feature): S} callback Called with each feature + * @param {function(ol.Feature): T} callback Called with each feature * on the source. Return a truthy value to stop iteration. - * @param {T=} opt_this The object to use as `this` in the callback. - * @return {S|undefined} The return value from the last call to the callback. - * @template T,S + * @return {T|undefined} The return value from the last call to the callback. + * @template T * @api */ -_ol_source_Vector_.prototype.forEachFeature = function(callback, opt_this) { +_ol_source_Vector_.prototype.forEachFeature = function(callback) { if (this.featuresRtree_) { - return this.featuresRtree_.forEach(callback, opt_this); + return this.featuresRtree_.forEach(callback); } else if (this.featuresCollection_) { - return this.featuresCollection_.forEach(callback.bind(opt_this)); + return this.featuresCollection_.forEach(callback); } }; @@ -402,18 +401,17 @@ _ol_source_Vector_.prototype.forEachFeature = function(callback, opt_this) { * value. * * @param {ol.Coordinate} coordinate Coordinate. - * @param {function(this: T, ol.Feature): S} callback Called with each feature + * @param {function(ol.Feature): T} callback Called with each feature * whose goemetry contains the provided coordinate. - * @param {T=} opt_this The object to use as `this` in the callback. - * @return {S|undefined} The return value from the last call to the callback. - * @template T,S + * @return {T|undefined} The return value from the last call to the callback. + * @template T */ -_ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback, opt_this) { +_ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordinate, callback) { var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]]; return this.forEachFeatureInExtent(extent, function(feature) { var geometry = feature.getGeometry(); if (geometry.intersectsCoordinate(coordinate)) { - return callback.call(opt_this, feature); + return callback(feature); } else { return undefined; } @@ -435,18 +433,17 @@ _ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordin * features, equivalent to {@link ol.source.Vector#forEachFeature}. * * @param {ol.Extent} extent Extent. - * @param {function(this: T, ol.Feature): S} callback Called with each feature + * @param {function(ol.Feature): T} callback Called with each feature * whose bounding box intersects the provided extent. - * @param {T=} opt_this The object to use as `this` in the callback. - * @return {S|undefined} The return value from the last call to the callback. - * @template T,S + * @return {T|undefined} The return value from the last call to the callback. + * @template T * @api */ -_ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback, opt_this) { +_ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback) { if (this.featuresRtree_) { - return this.featuresRtree_.forEachInExtent(extent, callback, opt_this); + return this.featuresRtree_.forEachInExtent(extent, callback); } else if (this.featuresCollection_) { - return this.featuresCollection_.forEach(callback.bind(opt_this)); + return this.featuresCollection_.forEach(callback); } }; @@ -461,24 +458,23 @@ _ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback, * source.forEachFeatureInExtent()} method instead. * * @param {ol.Extent} extent Extent. - * @param {function(this: T, ol.Feature): S} callback Called with each feature + * @param {function(ol.Feature): T} callback Called with each feature * whose geometry intersects the provided extent. - * @param {T=} opt_this The object to use as `this` in the callback. - * @return {S|undefined} The return value from the last call to the callback. - * @template T,S + * @return {T|undefined} The return value from the last call to the callback. + * @template T * @api */ -_ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback, opt_this) { +_ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback) { return this.forEachFeatureInExtent(extent, /** * @param {ol.Feature} feature Feature. - * @return {S|undefined} The return value from the last call to the callback. - * @template S + * @return {T|undefined} The return value from the last call to the callback. + * @template T */ function(feature) { var geometry = feature.getGeometry(); if (geometry.intersectsExtent(extent)) { - var result = callback.call(opt_this, feature); + var result = callback(feature); if (result) { return result; }