source.Vector

This commit is contained in:
simonseyock
2017-12-16 15:44:27 +01:00
parent 73deb49db1
commit 2276764951
2 changed files with 25 additions and 28 deletions
+1
View File
@@ -43,6 +43,7 @@ The following methods did get the optional this (i.e. opt_this) arguments remove
* geom/LineString#forEachSegment * geom/LineString#forEachSegment
* Observable#on, #once, #un * Observable#on, #once, #un
* source/TileUTFGrid#forDataAtCoordinateAndResolution * source/TileUTFGrid#forDataAtCoordinateAndResolution
* source/Vector#forEachFeature, #forEachFeatureInExtent, #forEachFeatureIntersectingExtent
### v4.6.0 ### v4.6.0
+24 -28
View File
@@ -379,18 +379,17 @@ _ol_source_Vector_.prototype.clear = function(opt_fast) {
* with each one. If the callback returns any "truthy" value, iteration will * with each one. If the callback returns any "truthy" value, iteration will
* stop and the function will return the same value. * 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. * on the source. Return a truthy value to stop iteration.
* @param {T=} opt_this The object to use as `this` in the callback. * @return {T|undefined} The return value from the last call to the callback.
* @return {S|undefined} The return value from the last call to the callback. * @template T
* @template T,S
* @api * @api
*/ */
_ol_source_Vector_.prototype.forEachFeature = function(callback, opt_this) { _ol_source_Vector_.prototype.forEachFeature = function(callback) {
if (this.featuresRtree_) { if (this.featuresRtree_) {
return this.featuresRtree_.forEach(callback, opt_this); return this.featuresRtree_.forEach(callback);
} else if (this.featuresCollection_) { } 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. * value.
* *
* @param {ol.Coordinate} coordinate Coordinate. * @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. * whose goemetry contains the provided coordinate.
* @param {T=} opt_this The object to use as `this` in the callback. * @return {T|undefined} The return value from the last call to the callback.
* @return {S|undefined} The return value from the last call to the callback. * @template T
* @template T,S
*/ */
_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]]; var extent = [coordinate[0], coordinate[1], coordinate[0], coordinate[1]];
return this.forEachFeatureInExtent(extent, function(feature) { return this.forEachFeatureInExtent(extent, function(feature) {
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();
if (geometry.intersectsCoordinate(coordinate)) { if (geometry.intersectsCoordinate(coordinate)) {
return callback.call(opt_this, feature); return callback(feature);
} else { } else {
return undefined; return undefined;
} }
@@ -435,18 +433,17 @@ _ol_source_Vector_.prototype.forEachFeatureAtCoordinateDirect = function(coordin
* features, equivalent to {@link ol.source.Vector#forEachFeature}. * features, equivalent to {@link ol.source.Vector#forEachFeature}.
* *
* @param {ol.Extent} extent Extent. * @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. * whose bounding box intersects the provided extent.
* @param {T=} opt_this The object to use as `this` in the callback. * @return {T|undefined} The return value from the last call to the callback.
* @return {S|undefined} The return value from the last call to the callback. * @template T
* @template T,S
* @api * @api
*/ */
_ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback, opt_this) { _ol_source_Vector_.prototype.forEachFeatureInExtent = function(extent, callback) {
if (this.featuresRtree_) { if (this.featuresRtree_) {
return this.featuresRtree_.forEachInExtent(extent, callback, opt_this); return this.featuresRtree_.forEachInExtent(extent, callback);
} else if (this.featuresCollection_) { } 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. * source.forEachFeatureInExtent()} method instead.
* *
* @param {ol.Extent} extent Extent. * @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. * whose geometry intersects the provided extent.
* @param {T=} opt_this The object to use as `this` in the callback. * @return {T|undefined} The return value from the last call to the callback.
* @return {S|undefined} The return value from the last call to the callback. * @template T
* @template T,S
* @api * @api
*/ */
_ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback, opt_this) { _ol_source_Vector_.prototype.forEachFeatureIntersectingExtent = function(extent, callback) {
return this.forEachFeatureInExtent(extent, return this.forEachFeatureInExtent(extent,
/** /**
* @param {ol.Feature} feature Feature. * @param {ol.Feature} feature Feature.
* @return {S|undefined} The return value from the last call to the callback. * @return {T|undefined} The return value from the last call to the callback.
* @template S * @template T
*/ */
function(feature) { function(feature) {
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();
if (geometry.intersectsExtent(extent)) { if (geometry.intersectsExtent(extent)) {
var result = callback.call(opt_this, feature); var result = callback(feature);
if (result) { if (result) {
return result; return result;
} }