From df4ef724b6f42a76355f5115ad44025a92b97031 Mon Sep 17 00:00:00 2001 From: Kevin Schmidt Date: Tue, 16 Oct 2018 10:30:09 -0600 Subject: [PATCH] Removed unused forEachFeatureAtCoordinate from ol/source/Source Fixes #8826. --- src/ol/renderer/canvas/IntermediateCanvas.js | 55 ++++----------- src/ol/renderer/webgl/ImageLayer.js | 72 ++++++++------------ src/ol/source/Source.js | 13 ---- 3 files changed, 43 insertions(+), 97 deletions(-) diff --git a/src/ol/renderer/canvas/IntermediateCanvas.js b/src/ol/renderer/canvas/IntermediateCanvas.js index 2b24b3e958..d90687cddd 100644 --- a/src/ol/renderer/canvas/IntermediateCanvas.js +++ b/src/ol/renderer/canvas/IntermediateCanvas.js @@ -4,7 +4,6 @@ import {scale as scaleCoordinate} from '../../coordinate.js'; import {createCanvasContext2D} from '../../dom.js'; import {containsExtent, intersects} from '../../extent.js'; -import {VOID} from '../../functions.js'; import CanvasLayerRenderer from '../canvas/Layer.js'; import {create as createTransform, apply as applyTransform} from '../../transform.js'; @@ -89,26 +88,6 @@ class IntermediateCanvasRenderer extends CanvasLayerRenderer { */ getImageTransform() {} - /** - * @inheritDoc - */ - forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg) { - const layer = this.getLayer(); - const source = layer.getSource(); - const resolution = frameState.viewState.resolution; - const rotation = frameState.viewState.rotation; - const skippedFeatureUids = frameState.skippedFeatureUids; - return source.forEachFeatureAtCoordinate( - coordinate, resolution, rotation, hitTolerance, skippedFeatureUids, - /** - * @param {import("../../Feature.js").FeatureLike} feature Feature. - * @return {?} Callback result. - */ - function(feature) { - return callback.call(thisArg, feature, layer); - }); - } - /** * @inheritDoc */ @@ -117,27 +96,21 @@ class IntermediateCanvasRenderer extends CanvasLayerRenderer { return undefined; } - if (this.getLayer().getSource().forEachFeatureAtCoordinate !== VOID) { - // for ImageCanvas sources use the original hit-detection logic, - // so that for example also transparent polygons are detected - return super.forEachLayerAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg); + const pixel = applyTransform(this.coordinateToCanvasPixelTransform, coordinate.slice()); + scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution); + + if (!this.hitCanvasContext_) { + this.hitCanvasContext_ = createCanvasContext2D(1, 1); + } + + this.hitCanvasContext_.clearRect(0, 0, 1, 1); + this.hitCanvasContext_.drawImage(this.getImage(), pixel[0], pixel[1], 1, 1, 0, 0, 1, 1); + + const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data; + if (imageData[3] > 0) { + return callback.call(thisArg, this.getLayer(), imageData); } else { - const pixel = applyTransform(this.coordinateToCanvasPixelTransform, coordinate.slice()); - scaleCoordinate(pixel, frameState.viewState.resolution / this.renderedResolution); - - if (!this.hitCanvasContext_) { - this.hitCanvasContext_ = createCanvasContext2D(1, 1); - } - - this.hitCanvasContext_.clearRect(0, 0, 1, 1); - this.hitCanvasContext_.drawImage(this.getImage(), pixel[0], pixel[1], 1, 1, 0, 0, 1, 1); - - const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data; - if (imageData[3] > 0) { - return callback.call(thisArg, this.getLayer(), imageData); - } else { - return undefined; - } + return undefined; } } } diff --git a/src/ol/renderer/webgl/ImageLayer.js b/src/ol/renderer/webgl/ImageLayer.js index 282fd34c1b..fa3c37e3f6 100644 --- a/src/ol/renderer/webgl/ImageLayer.js +++ b/src/ol/renderer/webgl/ImageLayer.js @@ -2,7 +2,7 @@ * @module ol/renderer/webgl/ImageLayer */ import {ENABLE_RASTER_REPROJECTION} from '../../reproj/common.js'; -import {TRUE, VOID} from '../../functions.js'; +import {TRUE} from '../../functions.js'; import LayerType from '../../LayerType.js'; import ViewHint from '../../ViewHint.js'; import {createCanvasContext2D} from '../../dom.js'; @@ -230,50 +230,36 @@ class WebGLImageLayerRenderer extends WebGLLayerRenderer { return undefined; } - if (this.getLayer().getSource().forEachFeatureAtCoordinate !== VOID) { - // for ImageCanvas sources use the original hit-detection logic, - // so that for example also transparent polygons are detected - const coordinate = applyTransform( - frameState.pixelToCoordinateTransform, pixel.slice()); - const hasFeature = this.forEachFeatureAtCoordinate(coordinate, frameState, 0, TRUE, this); + const imageSize = + [this.image_.getImage().width, this.image_.getImage().height]; - if (hasFeature) { - return callback.call(thisArg, this.getLayer(), null); - } else { - return undefined; - } + if (!this.hitTransformationMatrix_) { + this.hitTransformationMatrix_ = this.getHitTransformationMatrix_( + frameState.size, imageSize); + } + + const pixelOnFrameBuffer = applyTransform( + this.hitTransformationMatrix_, pixel.slice()); + + if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] || + pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) { + // outside the image, no need to check + return undefined; + } + + if (!this.hitCanvasContext_) { + this.hitCanvasContext_ = createCanvasContext2D(1, 1); + } + + this.hitCanvasContext_.clearRect(0, 0, 1, 1); + this.hitCanvasContext_.drawImage(this.image_.getImage(), + pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1); + + const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data; + if (imageData[3] > 0) { + return callback.call(thisArg, this.getLayer(), imageData); } else { - const imageSize = - [this.image_.getImage().width, this.image_.getImage().height]; - - if (!this.hitTransformationMatrix_) { - this.hitTransformationMatrix_ = this.getHitTransformationMatrix_( - frameState.size, imageSize); - } - - const pixelOnFrameBuffer = applyTransform( - this.hitTransformationMatrix_, pixel.slice()); - - if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] || - pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) { - // outside the image, no need to check - return undefined; - } - - if (!this.hitCanvasContext_) { - this.hitCanvasContext_ = createCanvasContext2D(1, 1); - } - - this.hitCanvasContext_.clearRect(0, 0, 1, 1); - this.hitCanvasContext_.drawImage(this.image_.getImage(), - pixelOnFrameBuffer[0], pixelOnFrameBuffer[1], 1, 1, 0, 0, 1, 1); - - const imageData = this.hitCanvasContext_.getImageData(0, 0, 1, 1).data; - if (imageData[3] > 0) { - return callback.call(thisArg, this.getLayer(), imageData); - } else { - return undefined; - } + return undefined; } } diff --git a/src/ol/source/Source.js b/src/ol/source/Source.js index ecc3230201..e04d661261 100644 --- a/src/ol/source/Source.js +++ b/src/ol/source/Source.js @@ -2,7 +2,6 @@ * @module ol/source/Source */ -import {VOID} from '../functions.js'; import BaseObject from '../Object.js'; import {get as getProjection} from '../proj.js'; import SourceState from './State.js'; @@ -173,18 +172,6 @@ class Source extends BaseObject { } } -/** - * @param {import("../coordinate.js").Coordinate} coordinate Coordinate. - * @param {number} resolution Resolution. - * @param {number} rotation Rotation. - * @param {number} hitTolerance Hit tolerance in pixels. - * @param {Object} skippedFeatureUids Skipped feature uids. - * @param {function(import("../Feature.js").FeatureLike): T} callback Feature callback. - * @return {T|void} Callback result. - * @template T - */ -Source.prototype.forEachFeatureAtCoordinate = VOID; - /** * Turns the attributions option into an attributions function.