[OpenLayers-Commits] r1767 - sandbox/bertil/lib/OpenLayers/Control

commits at openlayers.org commits at openlayers.org
Tue Nov 7 10:25:26 EST 2006


Author: bertil
Date: 2006-11-07 10:25:25 -0500 (Tue, 07 Nov 2006)
New Revision: 1767

Modified:
   sandbox/bertil/lib/OpenLayers/Control/Edition.js
Log:
snappingModeB

Modified: sandbox/bertil/lib/OpenLayers/Control/Edition.js
===================================================================
--- sandbox/bertil/lib/OpenLayers/Control/Edition.js	2006-11-07 14:57:43 UTC (rev 1766)
+++ sandbox/bertil/lib/OpenLayers/Control/Edition.js	2006-11-07 15:25:25 UTC (rev 1767)
@@ -99,15 +99,17 @@
      * @param {Event} evt
      */
     defaultEdition: function (evt) {
-        //this.snappingMode = true;   
+        this.snappingModeB = true;   
         
         var lonlat = this.map.getLonLatFromLayerPx(evt.xy);
-        var tmpPoint = new OpenLayers.Feature.Geometry.Point(lonlat.lon, lonlat.lat);
+        evt.point = new OpenLayers.Feature.Geometry.Point(lonlat.lon, lonlat.lat);
+        
         //calculate snapping point        
-        if (this.snappingMode) {
+        if (this.snappingModeB) {
             
             if (evt.geometry && evt.geometry.isSnappingElement) {
                 // return calculated point
+                console.log("test");
                 
             } else if (evt.geometry) {
                 // draw snapping element and return calculated point
@@ -136,13 +138,15 @@
                             var x = (p2 - p1) / (2 * m1);
                             var y = (m1 * x + p1);
                             
-                            var segPoint3 = new OpenLayers.Feature.Geometry.Point(x, y);
+                            evt.point = new OpenLayers.Feature.Geometry.Point(x, y);
                             
-                            var tmpDelta = Math.sqrt(Math.pow((segPoint3.x - tmpPoint.x), 2) + Math.pow((segPoint3.y - tmpPoint.y), 2));
+                            var tmpDelta = Math.sqrt(Math.pow((evt.point.x - tmpPoint.x), 2) + Math.pow((evt.point.y - tmpPoint.y), 2));
                             
-                            if((tmpDelta < delta || !delta) && Math.min(segPoint1.x, segPoint2.x) < segPoint3.x && segPoint3.x < Math.max(segPoint1.x, segPoint2.x)){
+                            if((tmpDelta < delta || !delta) && Math.min(segPoint1.x, segPoint2.x) < evt.point.x && evt.point.x < Math.max(segPoint1.x, segPoint2.x)){
                                 var delta = tmpDelta;
                                 snappingElement = new OpenLayers.Feature.Geometry.LineSegment(segPoint1, segPoint2);
+                                snappingElement.m = m1;
+                                snappingElement.p = p1;
                             }
                         }           
                     }
@@ -156,23 +160,24 @@
                 this.layer.renderer.eraseElement("tmpSnappingElement");
             }
         //calculate controlled point
-        } else if (this.controllingMode && this.path.length > 0) {
-            
-            var lastPoint = this.path.last();
-            
-
-            var width = tmpPoint.x-lastPoint.x;
-            var height = tmpPoint.y-lastPoint.y;
-            var hyp = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
-            var alpha = Math.acos(width/(hyp)) * 180.0/Math.PI;
-
-            var step = 22.5;
-
-            for(var degree = 0; degree <= 180; degree += step ){
-                if((alpha > (degree-step/2)) && (alpha < (degree+step/2))){
-                    var y = (height<0)?-Math.sin(degree/180*Math.PI)*hyp+lastPoint.y:Math.sin(degree/180*Math.PI)*hyp+lastPoint.y;
-                    var x = Math.cos(degree/180*Math.PI)*hyp+lastPoint.x;
-                    evt.point = OpenLayers.Feature.Geometry.Point(x, y);
+        } else if (this.controlledMode) {
+            if (this.geometry && this.geometry.path.length > 0) { 
+                var lastPoint = this.geometry.path.last();
+                
+    
+                var width = evt.point.x-lastPoint.x;
+                var height = evt.point.y-lastPoint.y;
+                var hyp = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
+                var alpha = Math.acos(width/(hyp)) * 180.0/Math.PI;
+    
+                var step = 22.5;
+    
+                for(var degree = 0; degree <= 180; degree += step ){
+                    if((alpha > (degree-step/2)) && (alpha < (degree+step/2))){
+                        var y = (height<0)?-Math.sin(degree/180*Math.PI)*hyp+lastPoint.y:Math.sin(degree/180*Math.PI)*hyp+lastPoint.y;
+                        var x = Math.cos(degree/180*Math.PI)*hyp+lastPoint.x;
+                        evt.point = new OpenLayers.Feature.Geometry.Point(x, y);
+                    }
                 }
             }
         //calculate normal point



More information about the Commits mailing list