[OpenLayers-Commits] r2360 - sandbox/vector-2.4/lib/OpenLayers

commits at openlayers.org commits at openlayers.org
Mon Mar 5 19:31:24 EST 2007


Author: euzuro
Date: 2007-03-05 19:31:18 -0500 (Mon, 05 Mar 2007)
New Revision: 2360

Modified:
   sandbox/vector-2.4/lib/OpenLayers/Geometry.js
Log:
rewrite atPoint() function to leverage containsLonLat() function from Bounds (readability)

Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry.js	2007-03-06 00:19:54 UTC (rev 2359)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry.js	2007-03-06 00:31:18 UTC (rev 2360)
@@ -30,8 +30,6 @@
 
     /**
      * @constructor
-     *
-     * @param {array} linearRings
      */
     initialize: function() {
         this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+ "_");
@@ -101,13 +99,18 @@
      */
     atPoint: function(lonlat, toleranceLon, toleranceLat) {
         var atPoint = false;
-		toleranceLon = (toleranceLon) ? toleranceLon : 0;
-		toleranceLat = (toleranceLat) ? toleranceLat : 0;
-        if (this.bounds) {
-            atPoint = ((this.bounds.bottom-toleranceLat) <= lonlat.lat)
-                        && (lonlat.lat <= (this.bounds.top+toleranceLat))
-                        && ((this.bounds.left-toleranceLon) <= lonlat.lon)
-                        && (lonlat.lon <= (this.bounds.right+toleranceLon));
+        if ((this.bounds != null) && (lonlat != null)) {
+
+    		var dX = (toleranceLon != null) ? toleranceLon : 0;
+    		var dY = (toleranceLat != null) ? toleranceLat : 0;
+    
+            var toleranceBounds = 
+                new OpenLayers.Bounds(this.bounds.left - dX,
+                                      this.bounds.bottom - dY,
+                                      this.bounds.right + dX,
+                                      this.bounds.top + dY);
+
+            atPoint = toleranceBounds.containsLonLat(lonlat);
         }
         return atPoint;
     },



More information about the Commits mailing list