Add forEachLayerAtPixel

This commit is contained in:
tsauerwein
2015-01-23 16:16:06 +01:00
parent 7feb8b22f6
commit 225f0739ec
3 changed files with 112 additions and 0 deletions

View File

@@ -589,6 +589,44 @@ ol.Map.prototype.forEachFeatureAtPixel =
};
/**
* Detect layers that have a colour value at a pixel on the viewport, and
* execute a callback with each matching layer. Layers included in the
* detection can be configured through `opt_layerFilter`. Feature overlays will
* always be included in the detection.
* @param {ol.Pixel} pixel Pixel.
* @param {function(this: S, ol.layer.Layer): T} callback Layer
* callback. If the detected feature is not on a layer, but on a
* {@link ol.FeatureOverlay}, then the argument to this function will
* be `null`. To stop detection, callback functions can return a truthy
* value.
* @param {S=} opt_this Value to use as `this` when executing `callback`.
* @param {(function(this: U, ol.layer.Layer): boolean)=} opt_layerFilter Layer
* filter function, only layers which are visible and for which this
* function returns `true` will be tested for features. By default, all
* visible layers will be tested. Feature overlays will always be tested.
* @param {U=} opt_this2 Value to use as `this` when executing `layerFilter`.
* @return {T|undefined} Callback result, i.e. the return value of last
* callback execution, or the first truthy callback return value.
* @template S,T,U
* @api stable
*/
ol.Map.prototype.forEachLayerAtPixel =
function(pixel, callback, opt_this, opt_layerFilter, opt_this2) {
if (goog.isNull(this.frameState_)) {
return;
}
var coordinate = this.getCoordinateFromPixel(pixel);
var thisArg = goog.isDef(opt_this) ? opt_this : null;
var layerFilter = goog.isDef(opt_layerFilter) ?
opt_layerFilter : goog.functions.TRUE;
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
return this.renderer_.forEachLayerAtPixel(
coordinate, this.frameState_, callback, thisArg,
layerFilter, thisArg2);
};
/**
* Detect if features intersect a pixel on the viewport. Layers included in the
* detection can be configured through `opt_layerFilter`. Feature overlays will