From d62e91023931f8dd0796ce6aedce77496d22c653 Mon Sep 17 00:00:00 2001 From: tsauerwein Date: Fri, 19 Dec 2014 14:46:54 +0100 Subject: [PATCH] Implement hasFeatureAtPixel for canvas --- src/ol/renderer/layerrenderer.js | 8 ++++++++ src/ol/renderer/maprenderer.js | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/ol/renderer/layerrenderer.js b/src/ol/renderer/layerrenderer.js index 14a64db3cb..bb74eb2a3b 100644 --- a/src/ol/renderer/layerrenderer.js +++ b/src/ol/renderer/layerrenderer.js @@ -54,6 +54,14 @@ goog.inherits(ol.renderer.Layer, goog.Disposable); ol.renderer.Layer.prototype.forEachFeatureAtPixel = goog.nullFunction; +/** + * @param {ol.Coordinate} coordinate Coordinate. + * @param {olx.FrameState} frameState Frame state. + * @return {boolean} Is there a feature at the given pixel? + */ +ol.renderer.Layer.prototype.hasFeatureAtPixel = goog.functions.FALSE; + + /** * @protected * @return {ol.layer.Layer} Layer. diff --git a/src/ol/renderer/maprenderer.js b/src/ol/renderer/maprenderer.js index 7dd9bc0025..bc681472f5 100644 --- a/src/ol/renderer/maprenderer.js +++ b/src/ol/renderer/maprenderer.js @@ -169,6 +169,26 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel = }; +/** + * @param {ol.Coordinate} coordinate Coordinate. + * @param {olx.FrameState} frameState FrameState. + * @param {function(this: U, ol.layer.Layer): boolean} 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. + * @param {U} thisArg Value to use as `this` when executing `layerFilter`. + * @return {boolean} Is there a feature at the given pixel? + * @template U + */ +ol.renderer.Map.prototype.hasFeatureAtPixel = + function(coordinate, frameState, layerFilter, thisArg) { + var hasFeature = this.forEachFeatureAtPixel( + coordinate, frameState, goog.functions.TRUE, this, layerFilter, thisArg); + + return goog.isDef(hasFeature) ? hasFeature : false; +}; + + /** * @param {ol.layer.Layer} layer Layer. * @protected