From 62dd64c1c9a60b4a30aa14206b271dc7cbf67565 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 3 Apr 2011 04:58:49 +0000 Subject: [PATCH] Simplifying hit detection for external graphics rendered with canvas. With this change, events within the graphic bounds will be considered hits (previously only events over visible pixels in the external graphic were considered hits). This simplification gets around same origin limitations. r=erilem (closes #3238) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11859 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Renderer/Canvas.js | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/lib/OpenLayers/Renderer/Canvas.js b/lib/OpenLayers/Renderer/Canvas.js index 12a3c2e532..d4111a18ee 100644 --- a/lib/OpenLayers/Renderer/Canvas.js +++ b/lib/OpenLayers/Renderer/Canvas.js @@ -60,8 +60,6 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { if (this.hitDetection) { this.hitCanvas = document.createElement("canvas"); this.hitContext = this.hitCanvas.getContext("2d"); - this.hitGraphicCanvas = document.createElement("canvas"); - this.hitGraphicContext = this.hitGraphicCanvas.getContext("2d"); } }, @@ -113,11 +111,6 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { hitCanvas.style.height = size.h + "px"; hitCanvas.width = size.w; hitCanvas.height = size.h; - var hitGraphicCanvas = this.hitGraphicCanvas; - hitGraphicCanvas.style.width = size.w + "px"; - hitGraphicCanvas.style.height = size.h + "px"; - hitGraphicCanvas.width = size.w; - hitGraphicCanvas.height = size.h; } }, @@ -232,26 +225,8 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { img, x, y, width, height ); if (this.hitDetection) { - var hitGraphicContext = this.hitGraphicContext; - var hitContext = this.hitContext; - hitGraphicContext.clearRect(0, 0, numRows, numCols); - hitGraphicContext.drawImage( - img, 0, 0, width, height - ); - var imagePixels = hitGraphicContext.getImageData(0, 0, width, height).data; - var indexData = hitContext.createImageData(width, height); - var indexPixels = indexData.data; - var pixelIndex; - for (var i=0, len=imagePixels.length; i 0) { - indexData[i] = red; - indexPixels[i+1] = green; - indexPixels[i+2] = blue; - indexPixels[i+3] = 255; - } - } - hitContext.putImageData(indexData, x, y); + this.setHitContextStyle("fill", featureId); + this.hitContext.fillRect(x, y, width, height); } };