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

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue May 3 19:44:15 EDT 2011


Author: tschaub
Date: 2011-05-03 16:44:14 -0700 (Tue, 03 May 2011)
New Revision: 11946

Modified:
   sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
   sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js
   sandbox/tschaub/editing/lib/OpenLayers/Handler/Polygon.js
Log:
Methods for programmatically inserting vertices while digitizing.

Modified: sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-05-03 16:59:58 UTC (rev 11945)
+++ sandbox/tschaub/editing/lib/OpenLayers/Control/DrawFeature.js	2011-05-03 23:44:14 UTC (rev 11946)
@@ -121,6 +121,44 @@
             this.events.triggerEvent("featureadded",{feature : feature});
         }
     },
+    
+    /**
+     * APIMethod: insertXY
+     * Insert a point in the current sketch given x & y coordinates.
+     *
+     * Parameters:
+     * x - {Number} The x-coordinate of the point.
+     * y - {Number} The y-coordinate of the point.
+     */
+    insertXY: function(x, y) {
+        if (this.handler && this.handler.line) {
+            this.handler.insertXY(x, y);
+        }
+    },
 
+    /**
+     * APIMethod: insertDirectionLength
+     * Insert a point in the current sketch given a direction and a length.
+     *
+     * Parameters:
+     * direction - {Number} Degrees clockwise from the positive x-axis.
+     * length - {Number} Distance from the previously drawn point.
+     */
+    insertDirectionLength: function(direction, length) {
+        if (this.handler && this.handler.line) {
+            this.handler.insertDirectionLength(direction, length);
+        }
+    },
+
+    /**
+     * APIMethod: finishSketch
+     * Finishes the sketch without including the currently drawn point.
+     *     This method can be called to terminate drawing programmatically
+     *     instead of waiting for the user to end the sketch.
+     */
+    finishSketch: function() {
+        this.handler.finishGeometry();
+    },
+
     CLASS_NAME: "OpenLayers.Control.DrawFeature"
 });

Modified: sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js	2011-05-03 16:59:58 UTC (rev 11945)
+++ sandbox/tschaub/editing/lib/OpenLayers/Handler/Path.js	2011-05-03 23:44:14 UTC (rev 11946)
@@ -164,6 +164,50 @@
     },
     
     /**
+     * Method: insertXY
+     * Insert a point in the current sketch given x & y coordinates.  The new
+     *     point is inserted immediately before the most recently drawn point.
+     *
+     * Parameters:
+     * x - {Number} The x-coordinate of the point.
+     * y - {Number} The y-coordinate of the point.
+     */
+    insertXY: function(x, y) {
+        this.line.geometry.addComponent(
+            new OpenLayers.Geometry.Point(x, y), 
+            this.getCurrentPointIndex()
+        );
+        this.drawFeature();
+    },
+
+    /**
+     * Method: insertDirectionLength
+     * Insert a point in the current sketch given a direction and a length.
+     *
+     * Parameters:
+     * direction - {Number} Degrees clockwise from the positive x-axis.
+     * length - {Number} Distance from the previously drawn point.
+     */
+    insertDirectionLength: function(direction, length) {
+        direction *= Math.PI / 180;
+        var dx = length * Math.cos(direction);
+        var dy = length * Math.sin(direction);
+        var previousIndex = this.getCurrentPointIndex() - 1;
+        var p0 = this.line.geometry.components[previousIndex];
+        this.insertXY(p0.x + dx, p0.y + dy);
+    },
+
+    /**
+     * Method: getCurrentPointIndex
+     * 
+     * Returns:
+     * {Number} The index of the most recently drawn point.
+     */
+    getCurrentPointIndex: function() {
+        return this.line.geometry.components.length - 1;
+    },
+    
+    /**
      * Method: freehandMode
      * Determine whether to behave in freehand mode or not.
      *

Modified: sandbox/tschaub/editing/lib/OpenLayers/Handler/Polygon.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Handler/Polygon.js	2011-05-03 16:59:58 UTC (rev 11945)
+++ sandbox/tschaub/editing/lib/OpenLayers/Handler/Polygon.js	2011-05-03 23:44:14 UTC (rev 11946)
@@ -130,8 +130,18 @@
         }
         OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments);
     },
-    
+
     /**
+     * Method: getCurrentPointIndex
+     * 
+     * Returns:
+     * {Number} The index of the most recently drawn point.
+     */
+    getCurrentPointIndex: function() {
+        return this.line.geometry.components.length - 2;
+    },
+
+    /**
      * Method: enforceTopology
      * Simple topology enforcement for drawing interior rings.  Ensures vertices
      *     of interior rings are contained by exterior ring.  Other topology 



More information about the Commits mailing list