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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Mar 30 17:19:40 EDT 2011


Author: tschaub
Date: 2011-03-30 14:19:39 -0700 (Wed, 30 Mar 2011)
New Revision: 11809

Modified:
   sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
Log:
Setting hitDetection true by default.  Removing the check on xy values as this is now properly handled when offsets are calculated.

Modified: sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-03-30 20:54:41 UTC (rev 11808)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Renderer/Canvas.js	2011-03-30 21:19:39 UTC (rev 11809)
@@ -20,8 +20,16 @@
      * APIProperty: hitDetection
      * {Boolean} Allow for hit detection of features.  Default is false.
      */
-    hitDetection: false,
+    hitDetection: true,
     
+    /**
+     * Property: hitOverflow
+     * {Number} The method for converting feature identifiers to color values
+     *     supports 16777215 sequential values.  Two features cannot be 
+     *     predictably detected if their identifiers differ by more than this
+     *     value.  The hitOverflow allows for bigger numbers (but the 
+     *     difference in values is still limited).
+     */
     hitOverflow: 0,
 
     /**
@@ -586,21 +594,14 @@
             // this dragging check should go in the feature handler
             if (!this.map.dragging) {
                 var xy = evt.xy;
-                var x = xy.x;
-                var y = xy.y;
-                if (x < this.root.width && y < this.root.height) {
-                    // This check is required because the map listens for browser
-                    // events on the viewport container instead of the viewport.
-                    // Because the container might have border, padding, or margin,
-                    // it's dimensions may be different than the canvas dimensions.
-                    // TODO: Fix Map.js and remove this check.
-                    var data = this.hitContext.getImageData(xy.x, xy.y, 1, 1).data;
-                    if (data[3] === 255) { // antialiased
-                        var id = data[2] + (256 * (data[1] + (256 * data[0])));
-                        if (id) {
-                            feature = this.features["OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow)][0];
-                        }
-                    }                
+                var x = xy.x | 0;
+                var y = xy.y | 0;
+                var data = this.hitContext.getImageData(x, y, 1, 1).data;
+                if (data[3] === 255) { // antialiased
+                    var id = data[2] + (256 * (data[1] + (256 * data[0])));
+                    if (id) {
+                        feature = this.features["OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow)][0];
+                    }
                 }
             }
         }



More information about the Commits mailing list