[OpenLayers-Commits] r4192 - sandbox/camptocamp/feature/lib/OpenLayers/Handler

commits at openlayers.org commits at openlayers.org
Thu Sep 6 05:10:16 EDT 2007


Author: fredj
Date: 2007-09-06 05:10:14 -0400 (Thu, 06 Sep 2007)
New Revision: 4192

Modified:
   sandbox/camptocamp/feature/lib/OpenLayers/Handler/Snapping.js
Log:
simplify the 'snap to edges' method

Modified: sandbox/camptocamp/feature/lib/OpenLayers/Handler/Snapping.js
===================================================================
--- sandbox/camptocamp/feature/lib/OpenLayers/Handler/Snapping.js	2007-09-05 22:32:28 UTC (rev 4191)
+++ sandbox/camptocamp/feature/lib/OpenLayers/Handler/Snapping.js	2007-09-06 09:10:14 UTC (rev 4192)
@@ -4,8 +4,8 @@
 
 /*
  * TBD:
- *   - snap to geometry's edges
  *   - snap to fixed grid with pixel or geographic size
+ *   - snap to self
  */
 
 /**
@@ -16,7 +16,7 @@
 OpenLayers.Handler.Snapping = OpenLayers.Class(OpenLayers.Handler, {
 
     /**
-     * Property: method
+     * Property: methods
      * {Array(String)} the snapping method
      */
     methods: ['vertex', 'edge'],
@@ -106,6 +106,7 @@
                 }
             }
         }
+
         for (var i = 0; i < vertices.length; i++) {
             if (vertices[i].atPoint(lonlat, this.toleranceGeo, this.toleranceGeo)) {
                 return new OpenLayers.LonLat(vertices[i].x, vertices[i].y);
@@ -126,33 +127,22 @@
                 }
             }
         }
-
-        var minimum = null;
         for (var i = 0; i < edges.length; i++) {
             var point = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
             var result = this.distanceToLine(point, edges[i]);
-
-            if (result) {
-                if (result.distance < this.toleranceGeo) {
-                    if (!minimum) {
-                        minimum = result;
-                    }
-                    if (result.distance < minimum.distance) {
-                        minimum = result;
-                    }
-                }
+            if (result && result.distance < this.toleranceGeo) {
+                return new OpenLayers.LonLat(result.cross.x, result.cross.y);
             }
         }
-        if (minimum) {
-            
-            return new OpenLayers.LonLat(minimum.cross.x, minimum.cross.y);
-        } else {
-            return null;
-        }
+        // no snapping point found
+        return null;
     },
 
 
     // see: http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/source.c
+    /*
+     * return the minimum distance (geo unit) between 'point' and 'line'
+     */
     distanceToLine: function(point, line) {
         var start = line.components[0];
         var stop = line.components[1];
@@ -224,5 +214,4 @@
         hoverPointUnit: "%",
         pointerEvents: "visiblePainted"
     }
-
 }



More information about the Commits mailing list