[OpenLayers-Commits] r11952 - in sandbox/tschaub/editing/lib/OpenLayers: Control Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed May 4 16:12:45 EDT 2011


Author: tschaub
Date: 2011-05-04 13:12:44 -0700 (Wed, 04 May 2011)
New Revision: 11952

Modified:
   sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
   sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js
Log:
Add method to insert point based on deflection from previous segment.

Modified: sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-05-04 19:02:41 UTC (rev 11951)
+++ sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-05-04 20:12:44 UTC (rev 11952)
@@ -165,6 +165,22 @@
     },
 
     /**
+     * APIMethod: insertDeflectionLength
+     * Insert a point in the current sketch given a deflection and a length.
+     *     The deflection should be degrees clockwise from the previously 
+     *     digitized segment.
+     *
+     * Parameters:
+     * deflection - {Number} Degrees clockwise from the previous segment.
+     * length - {Number} Distance from the previously drawn point.
+     */
+    insertDeflectionLength: function(deflection, length) {
+        if (this.handler && this.handler.line) {
+            this.handler.insertDeflectionLength(deflection, length);
+        }
+    },
+
+    /**
      * APIMethod: finishSketch
      * Finishes the sketch without including the currently drawn point.
      *     This method can be called to terminate drawing programmatically

Modified: sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js	2011-05-04 19:02:41 UTC (rev 11951)
+++ sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js	2011-05-04 20:12:44 UTC (rev 11952)
@@ -210,6 +210,28 @@
     },
 
     /**
+     * Method: insertDeflectionLength
+     * Insert a point in the current sketch given a deflection and a length.
+     *     The deflection should be degrees clockwise from the previously 
+     *     digitized segment.
+     *
+     * Parameters:
+     * deflection - {Number} Degrees clockwise from the previous segment.
+     * length - {Number} Distance from the previously drawn point.
+     */
+    insertDeflectionLength: function(deflection, length) {
+        var previousIndex = this.getCurrentPointIndex() - 1;
+        if (previousIndex > 0) {
+            var p1 = this.line.geometry.components[previousIndex];
+            var p0 = this.line.geometry.components[previousIndex-1];
+            var theta = Math.atan2(p1.y - p0.y, p1.x - p0.x);
+            this.insertDirectionLength(
+                (theta * 180 / Math.PI) + deflection, length
+            );
+        }
+    },
+
+    /**
      * Method: getCurrentPointIndex
      * 
      * Returns:



More information about the Commits mailing list