[OpenLayers-Commits] r11859 -
	trunk/openlayers/lib/OpenLayers/Renderer
    commits-20090109 at openlayers.org 
    commits-20090109 at openlayers.org
       
    Sun Apr  3 00:58:53 EDT 2011
    
    
  
Author: tschaub
Date: 2011-04-02 21:58:49 -0700 (Sat, 02 Apr 2011)
New Revision: 11859
Modified:
   trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js
Log:
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)
Modified: trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js	2011-04-01 23:10:04 UTC (rev 11858)
+++ trunk/openlayers/lib/OpenLayers/Renderer/Canvas.js	2011-04-03 04:58:49 UTC (rev 11859)
@@ -60,8 +60,6 @@
         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 @@
             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 @@
                 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<len; i+=4) {
-                    // look for visible pixels
-                    if (imagePixels[i+3] > 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);
             }
         };
 
    
    
More information about the Commits
mailing list