Avoid pixel->coord->pixel conversion

This commit is contained in:
tsauerwein
2015-01-29 11:33:57 +01:00
parent 054227fd26
commit 4d4bed454a
10 changed files with 27 additions and 25 deletions

View File

@@ -616,13 +616,12 @@ ol.Map.prototype.forEachLayerAtPixel =
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,
pixel, this.frameState_, callback, thisArg,
layerFilter, thisArg2);
};

View File

@@ -79,7 +79,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
* @inheritDoc
*/
ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
function(coordinate, frameState, callback, thisArg) {
function(pixel, frameState, callback, thisArg) {
if (goog.isNull(this.getImage())) {
return undefined;
}
@@ -87,6 +87,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
// for ImageVector sources use the original hit-detection logic,
// so that for example also transparent polygons are detected
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
var hasFeature = this.forEachFeatureAtPixel(
coordinate, frameState, goog.functions.TRUE, this);
@@ -103,7 +104,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachLayerAtPixel =
}
var pixelOnCanvas =
this.getPixelFromCoordinates(coordinate, this.imageTransformInv_);
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
if (goog.isNull(this.hitCanvasContext_)) {
this.hitCanvasContext_ = ol.dom.createCanvasContext2D(1, 1);

View File

@@ -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
* to convert from a map pixel to a canvas pixel.
* @return {ol.Pixel}
* @protected
*/
ol.renderer.canvas.Layer.prototype.getPixelFromCoordinates =
function(coordinate, imageTransformInv) {
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
ol.renderer.canvas.Layer.prototype.getPixelOnCanvas =
function(pixelOnMap, imageTransformInv) {
var pixelOnCanvas = [0, 0];
ol.vec.Mat4.multVec2(imageTransformInv, pixelOnMap, pixelOnCanvas);
return pixelOnCanvas;

View File

@@ -424,7 +424,7 @@ ol.renderer.canvas.TileLayer.prototype.prepareFrame =
* @inheritDoc
*/
ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
function(coordinate, frameState, callback, thisArg) {
function(pixel, frameState, callback, thisArg) {
if (goog.isNull(this.context_)) {
return undefined;
}
@@ -435,7 +435,7 @@ ol.renderer.canvas.TileLayer.prototype.forEachLayerAtPixel =
}
var pixelOnCanvas =
this.getPixelFromCoordinates(coordinate, this.imageTransformInv_);
this.getPixelOnCanvas(pixel, this.imageTransformInv_);
var imageData = this.context_.getImageData(
pixelOnCanvas[0], pixelOnCanvas[1], 1, 1).data;

View File

@@ -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 {function(this: S, ol.layer.Layer): T} callback Layer 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
*/
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(
coordinate, frameState, goog.functions.TRUE, this);

View File

@@ -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 {function(this: S, ol.layer.Layer): T} callback Layer
* callback.
@@ -184,7 +184,7 @@ ol.renderer.Map.prototype.forEachFeatureAtPixel =
* @template S,T,U
*/
ol.renderer.Map.prototype.forEachLayerAtPixel =
function(coordinate, frameState, callback, thisArg,
function(pixel, frameState, callback, thisArg,
layerFilter, thisArg2) {
var result;
var viewState = frameState.viewState;
@@ -192,6 +192,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel =
var viewRotation = viewState.rotation;
if (!goog.isNull(this.replayGroup)) {
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
var hasFeature = this.replayGroup.forEachFeatureAtPixel(coordinate,
viewResolution, viewRotation, {}, goog.functions.TRUE);
@@ -212,7 +213,7 @@ ol.renderer.Map.prototype.forEachLayerAtPixel =
layerFilter.call(thisArg2, layer)) {
var layerRenderer = this.getLayerRenderer(layer);
result = layerRenderer.forEachLayerAtPixel(
coordinate, frameState, callback, thisArg);
pixel, frameState, callback, thisArg);
if (result) {
return result;
}

View File

@@ -226,7 +226,7 @@ ol.renderer.webgl.ImageLayer.prototype.hasFeatureAtPixel =
* @inheritDoc
*/
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())) {
return undefined;
}
@@ -234,6 +234,7 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
if (this.getLayer().getSource() instanceof ol.source.ImageVector) {
// for ImageVector sources use the original hit-detection logic,
// so that for example also transparent polygons are detected
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
var hasFeature = this.forEachFeatureAtPixel(
coordinate, frameState, goog.functions.TRUE, this);
@@ -251,10 +252,9 @@ ol.renderer.webgl.ImageLayer.prototype.forEachLayerAtPixel =
frameState.size, imageSize);
}
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
var pixelOnFrameBuffer = [0, 0];
ol.vec.Mat4.multVec2(
this.hitTransformationMatrix_, pixelOnMap, pixelOnFrameBuffer);
this.hitTransformationMatrix_, pixel, pixelOnFrameBuffer);
if (pixelOnFrameBuffer[0] < 0 || pixelOnFrameBuffer[0] > imageSize[0] ||
pixelOnFrameBuffer[1] < 0 || pixelOnFrameBuffer[1] > imageSize[1]) {

View File

@@ -650,7 +650,7 @@ ol.renderer.webgl.Map.prototype.hasFeatureAtPixel =
* @inheritDoc
*/
ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
function(coordinate, frameState, callback, thisArg,
function(pixel, frameState, callback, thisArg,
layerFilter, thisArg2) {
if (this.getGL().isContextLost()) {
return false;
@@ -664,6 +664,7 @@ ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
if (!goog.isNull(this.replayGroup)) {
// use default color values
var d = ol.renderer.webgl.Map.DEFAULT_COLOR_VALUES_;
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
var hasFeature = this.replayGroup.hasFeatureAtPixel(coordinate,
context, viewState.center, viewState.resolution, viewState.rotation,
@@ -686,7 +687,7 @@ ol.renderer.webgl.Map.prototype.forEachLayerAtPixel =
layerFilter.call(thisArg, layer)) {
var layerRenderer = this.getLayerRenderer(layer);
result = layerRenderer.forEachLayerAtPixel(
coordinate, frameState, callback, thisArg);
pixel, frameState, callback, thisArg);
if (result) {
return result;
}

View File

@@ -333,16 +333,15 @@ ol.renderer.webgl.TileLayer.prototype.prepareFrame =
* @inheritDoc
*/
ol.renderer.webgl.TileLayer.prototype.forEachLayerAtPixel =
function(coordinate, frameState, callback, thisArg) {
function(pixel, frameState, callback, thisArg) {
if (goog.isNull(this.framebuffer)) {
return undefined;
}
var mapSize = this.getMap().getSize();
var pixelOnMap = this.getMap().getPixelFromCoordinate(coordinate);
var pixelOnMapScaled = [
pixelOnMap[0] / mapSize[0],
(mapSize[1] - pixelOnMap[1]) / mapSize[1]];
pixel[0] / mapSize[0],
(mapSize[1] - pixel[1]) / mapSize[1]];
var pixelOnFrameBufferScaled = [0, 0];
ol.vec.Mat4.multVec2(

View File

@@ -143,7 +143,7 @@ ol.renderer.webgl.VectorLayer.prototype.forEachFeatureAtPixel =
* @inheritDoc
*/
ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
function(coordinate, frameState) {
function(pixel, frameState) {
if (goog.isNull(this.replayGroup_) || goog.isNull(this.layerState_)) {
return false;
} else {
@@ -151,6 +151,7 @@ ol.renderer.webgl.VectorLayer.prototype.hasFeatureAtPixel =
var context = mapRenderer.getContext();
var viewState = frameState.viewState;
var layerState = this.layerState_;
var coordinate = this.getMap().getCoordinateFromPixel(pixel);
return this.replayGroup_.hasFeatureAtPixel(coordinate,
context, viewState.center, viewState.resolution, viewState.rotation,
frameState.size, frameState.pixelRatio,