Avoid pixel->coord->pixel conversion
This commit is contained in:
+1
-2
@@ -616,13 +616,12 @@ ol.Map.prototype.forEachLayerAtPixel =
|
|||||||
if (goog.isNull(this.frameState_)) {
|
if (goog.isNull(this.frameState_)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var coordinate = this.getCoordinateFromPixel(pixel);
|
|
||||||
var thisArg = goog.isDef(opt_this) ? opt_this : null;
|
var thisArg = goog.isDef(opt_this) ? opt_this : null;
|
||||||
var layerFilter = goog.isDef(opt_layerFilter) ?
|
var layerFilter = goog.isDef(opt_layerFilter) ?
|
||||||
opt_layerFilter : goog.functions.TRUE;
|
opt_layerFilter : goog.functions.TRUE;
|
||||||
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
|
var thisArg2 = goog.isDef(opt_this2) ? opt_this2 : null;
|
||||||
return this.renderer_.forEachLayerAtPixel(
|
return this.renderer_.forEachLayerAtPixel(
|
||||||
coordinate, this.frameState_, callback, thisArg,
|
pixel, this.frameState_, callback, thisArg,
|
||||||
layerFilter, thisArg2);
|
layerFilter, thisArg2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
|
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(pixel, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.getImage())) {
|
if (goog.isNull(this.getImage())) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -87,6 +87,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
|
|||||||
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
||||||
// for ImageVector sources use the original hit-detection logic,
|
// for ImageVector sources use the original hit-detection logic,
|
||||||
// so that for example also transparent polygons are detected
|
// so that for example also transparent polygons are detected
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
var hasFeature = this.forEachFeatureAtPixel(
|
var hasFeature = this.forEachFeatureAtPixel(
|
||||||
coordinate, frameState, goog.functions.TRUE, this);
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
@@ -103,7 +104,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pixelOnCanvas =
|
var pixelOnCanvas =
|
||||||
this.getPixelFromCoordinates(coordinate, this.imageTransformInv_);
|
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
|
||||||
|
|
||||||
if (goog.isNull(this.hitCanvasContext_)) {
|
if (goog.isNull(this.hitCanvasContext_)) {
|
||||||
this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
|
this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);
|
||||||
|
|||||||
@@ -217,15 +217,14 @@ ol.renderer.canvas.Layer.prototype.prepareFrame = goog.abstractMethod;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Pixel} pixelOnMap Pixel.
|
||||||
* @param {goog.vec.Mat4.Number} imageTransformInv The transformation matrix
|
* @param {goog.vec.Mat4.Number} imageTransformInv The transformation matrix
|
||||||
* to convert from a map pixel to a canvas pixel.
|
* to convert from a map pixel to a canvas pixel.
|
||||||
* @return {ol.Pixel}
|
* @return {ol.Pixel}
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.Layer.prototype.getPixelFromCoordinates =
|
ol.renderer.canvas.Layer.prototype.getPixelOnCanvas =
|
||||||
function(coordinate, imageTransformInv) {
|
function(pixelOnMap, imageTransformInv) {
|
||||||
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
|
|
||||||
var pixelOnCanvas = [0, 0];
|
var pixelOnCanvas = [0, 0];
|
||||||
ol.vec.Mat4.multVec2(imageTransformInv, pixelOnMap, pixelOnCanvas);
|
ol.vec.Mat4.multVec2(imageTransformInv, pixelOnMap, pixelOnCanvas);
|
||||||
return pixelOnCanvas;
|
return pixelOnCanvas;
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
|
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(pixel, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.context_)) {
|
if (goog.isNull(this.context_)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -435,7 +435,7 @@ ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pixelOnCanvas =
|
var pixelOnCanvas =
|
||||||
this.getPixelFromCoordinates(coordinate, this.imageTransformInv_);
|
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
|
||||||
|
|
||||||
var imageData = this.context_.getImageData(
|
var imageData = this.context_.getImageData(
|
||||||
pixelOnCanvas[0], pixelOnCanvas[1], 1, 1).data;
|
pixelOnCanvas[0], pixelOnCanvas[1], 1, 1).data;
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ ol.renderer.Layer.prototype.forEachFeatureAtPixel = goog.nullFunction;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @param {olx.FrameState} frameState Frame state.
|
* @param {olx.FrameState} frameState Frame state.
|
||||||
* @param {function(this: S, ol.layer.Layer): T} callback Layer callback.
|
* @param {function(this: S, ol.layer.Layer): T} callback Layer callback.
|
||||||
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
* @param {S} thisArg Value to use as `this` when executing `callback`.
|
||||||
@@ -65,7 +65,8 @@ ol.renderer.Layer.prototype.forEachFeatureAtPixel = goog.nullFunction;
|
|||||||
* @template S,T
|
* @template S,T
|
||||||
*/
|
*/
|
||||||
ol.renderer.Layer.prototype.forEachLayerAtPixel =
|
ol.renderer.Layer.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(pixel, frameState, callback, thisArg) {
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
var hasFeature = this.forEachFeatureAtPixel(
|
var hasFeature = this.forEachFeatureAtPixel(
|
||||||
coordinate, frameState, goog.functions.TRUE, this);
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Pixel} pixel Pixel.
|
||||||
* @param {olx.FrameState} frameState FrameState.
|
* @param {olx.FrameState} frameState FrameState.
|
||||||
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
* @param {function(this: S, ol.layer.Layer): T} callback Layer
|
||||||
* callback.
|
* callback.
|
||||||
@@ -184,7 +184,7 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
|
|||||||
* @template S,T,U
|
* @template S,T,U
|
||||||
*/
|
*/
|
||||||
ol.renderer.Map.prototype.forEachLayerAtPixel =
|
ol.renderer.Map.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg,
|
function(pixel, frameState, callback, thisArg,
|
||||||
layerFilter, thisArg2) {
|
layerFilter, thisArg2) {
|
||||||
var result;
|
var result;
|
||||||
var viewState = frameState.viewState;
|
var viewState = frameState.viewState;
|
||||||
@@ -192,6 +192,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel =
|
|||||||
var viewRotation = viewState.rotation;
|
var viewRotation = viewState.rotation;
|
||||||
|
|
||||||
if (!goog.isNull(this.replayGroup)) {
|
if (!goog.isNull(this.replayGroup)) {
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
var hasFeature = this.replayGroup.forEachFeatureAtPixel(coordinate,
|
var hasFeature = this.replayGroup.forEachFeatureAtPixel(coordinate,
|
||||||
viewResolution, viewRotation, {}, goog.functions.TRUE);
|
viewResolution, viewRotation, {}, goog.functions.TRUE);
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel =
|
|||||||
layerFilter.call(thisArg2, layer)) {
|
layerFilter.call(thisArg2, layer)) {
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
result = layerRenderer.forEachLayerAtPixel(
|
result = layerRenderer.forEachLayerAtPixel(
|
||||||
coordinate, frameState, callback, thisArg);
|
pixel, frameState, callback, thisArg);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtPixel =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
|
ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(pixel, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.image_) || goog.isNull(this.image_.getImage())) {
|
if (goog.isNull(this.image_) || goog.isNull(this.image_.getImage())) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -234,6 +234,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
|
|||||||
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
|
||||||
// for ImageVector sources use the original hit-detection logic,
|
// for ImageVector sources use the original hit-detection logic,
|
||||||
// so that for example also transparent polygons are detected
|
// so that for example also transparent polygons are detected
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
var hasFeature = this.forEachFeatureAtPixel(
|
var hasFeature = this.forEachFeatureAtPixel(
|
||||||
coordinate, frameState, goog.functions.TRUE, this);
|
coordinate, frameState, goog.functions.TRUE, this);
|
||||||
|
|
||||||
@@ -251,10 +252,9 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
|
|||||||
frameState.size, imageSize);
|
frameState.size, imageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
|
|
||||||
var pixelOnFrameBuffer = [0, 0];
|
var pixelOnFrameBuffer = [0, 0];
|
||||||
ol.vec.Mat4.multVec2(
|
ol.vec.Mat4.multVec2(
|
||||||
this.hitTransformationMatrix_, pixelOnMap, pixelOnFrameBuffer);
|
this.hitTransformationMatrix_, pixel, pixelOnFrameBuffer);
|
||||||
|
|
||||||
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
|
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
|
||||||
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
|
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
|
ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg,
|
function(pixel, frameState, callback, thisArg,
|
||||||
layerFilter, thisArg2) {
|
layerFilter, thisArg2) {
|
||||||
if (this.getGL().isContextLost()) {
|
if (this.getGL().isContextLost()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -664,6 +664,7 @@ ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
|
|||||||
if (!goog.isNull(this.replayGroup)) {
|
if (!goog.isNull(this.replayGroup)) {
|
||||||
// use default color values
|
// use default color values
|
||||||
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
|
|
||||||
var hasFeature = this.replayGroup.hasFeatureAtPixel(coordinate,
|
var hasFeature = this.replayGroup.hasFeatureAtPixel(coordinate,
|
||||||
context, viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
@@ -686,7 +687,7 @@ ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
|
|||||||
layerFilter.call(thisArg, layer)) {
|
layerFilter.call(thisArg, layer)) {
|
||||||
var layerRenderer = this.getLayerRenderer(layer);
|
var layerRenderer = this.getLayerRenderer(layer);
|
||||||
result = layerRenderer.forEachLayerAtPixel(
|
result = layerRenderer.forEachLayerAtPixel(
|
||||||
coordinate, frameState, callback, thisArg);
|
pixel, frameState, callback, thisArg);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,16 +333,15 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel =
|
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel =
|
||||||
function(coordinate, frameState, callback, thisArg) {
|
function(pixel, frameState, callback, thisArg) {
|
||||||
if (goog.isNull(this.framebuffer)) {
|
if (goog.isNull(this.framebuffer)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
var mapSize = this.getMap().getSize();
|
var mapSize = this.getMap().getSize();
|
||||||
|
|
||||||
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
|
|
||||||
var pixelOnMapScaled = [
|
var pixelOnMapScaled = [
|
||||||
pixelOnMap[0] / mapSize[0],
|
pixel[0] / mapSize[0],
|
||||||
(mapSize[1] - pixelOnMap[1]) / mapSize[1]];
|
(mapSize[1] - pixel[1]) / mapSize[1]];
|
||||||
|
|
||||||
var pixelOnFrameBufferScaled = [0, 0];
|
var pixelOnFrameBufferScaled = [0, 0];
|
||||||
ol.vec.Mat4.multVec2(
|
ol.vec.Mat4.multVec2(
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtPixel =
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
|
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
|
||||||
function(coordinate, frameState) {
|
function(pixel, frameState) {
|
||||||
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -151,6 +151,7 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
|
|||||||
var context = mapRenderer.getContext();
|
var context = mapRenderer.getContext();
|
||||||
var viewState = frameState.viewState;
|
var viewState = frameState.viewState;
|
||||||
var layerState = this.layerState_;
|
var layerState = this.layerState_;
|
||||||
|
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
|
||||||
return this.replayGroup_.hasFeatureAtPixel(coordinate,
|
return this.replayGroup_.hasFeatureAtPixel(coordinate,
|
||||||
context, viewState.center, viewState.resolution, viewState.rotation,
|
context, viewState.center, viewState.resolution, viewState.rotation,
|
||||||
frameState.size, frameState.pixelRatio,
|
frameState.size, frameState.pixelRatio,
|
||||||
|
|||||||
Reference in New Issue
Block a user