[OpenLayers-Commits] r11858 - sandbox/tschaub/canvas/lib/OpenLayers/Renderer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Apr 1 19:10:05 EDT 2011


Author: tschaub
Date: 2011-04-01 16:10:04 -0700 (Fri, 01 Apr 2011)
New Revision: 11858

Modified:
   sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
Log:
Using rendered image rect to determine hit.

Modified: sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-04-01 22:40:36 UTC (rev 11857)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-04-01 23:10:04 UTC (rev 11858)
@@ -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