[OpenLayers-Commits] r11027 - in sandbox/elemoine/draw-feature: examples lib/OpenLayers/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Jan 12 05:47:28 EST 2011


Author: erilem
Date: 2011-01-12 02:47:28 -0800 (Wed, 12 Jan 2011)
New Revision: 11027

Modified:
   sandbox/elemoine/draw-feature/examples/draw-feature.html
   sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
   sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js
Log:
allow "pan while drawing" for point and path, freehand mode broken

Modified: sandbox/elemoine/draw-feature/examples/draw-feature.html
===================================================================
--- sandbox/elemoine/draw-feature/examples/draw-feature.html	2011-01-12 08:01:00 UTC (rev 11026)
+++ sandbox/elemoine/draw-feature/examples/draw-feature.html	2011-01-12 10:47:28 UTC (rev 11027)
@@ -62,6 +62,14 @@
                     }
                 }
             }
+
+            function allowPan(element) {
+                var stop = !element.checked;
+                for(var key in drawControls) {
+                    drawControls[key].handler.stopDown = stop;
+                    drawControls[key].handler.stopUp = stop;
+                }
+            }
         </script>
     </head>
     <body onload="init()">
@@ -95,6 +103,10 @@
                 <input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
                 <label for="polygonToggle">draw polygon</label>
             </li>
+            <li>
+                <input type="checkbox" name="allow-pan" value="allow-pan" id="allowPanCheckbox" checked=true onclick="allowPan(this);" />
+                <label for="allowPanCheckbox">allow pan while drawing</label>
+            </li>
         </ul>
 
         <div id="docs">

Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-01-12 08:01:00 UTC (rev 11026)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js	2011-01-12 10:47:28 UTC (rev 11027)
@@ -79,6 +79,9 @@
      *     feature.
      */
     createFeature: function(pixel) {
+        if(this.persist) {
+            this.destroyFeature();
+        }
         var lonlat = this.control.map.getLonLatFromPixel(pixel);
         this.point = new OpenLayers.Feature.Vector(
             new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
@@ -213,18 +216,9 @@
         if (this.lastDown && this.lastDown.equals(evt.xy)) {
             return false;
         }
-        if(this.lastDown == null) {
-            if(this.persist) {
-                this.destroyFeature();
-            }
-            this.createFeature(evt.xy);
-        } else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
-            this.addPoint(evt.xy);
-        }
         this.mouseDown = true;
         this.lastDown = evt.xy;
-        this.drawing = true;
-        return false;
+        return !this.stopDown;
     },
 
     /**
@@ -261,18 +255,22 @@
      * {Boolean} Allow event propagation
      */
     mouseup: function (evt) {
-        this.mouseDown = false;
-        if(this.drawing) {
+        if(this.mouseDown) {
             if(this.freehandMode(evt)) {
                 this.removePoint();
                 this.finalize();
             } else {
-                if(this.lastUp == null) {
-                   this.addPoint(evt.xy);
+                if(this.lastDown.equals(evt.xy)) {
+                    if(this.lastUp == null) {
+                        this.createFeature(evt.xy);
+                    }
+                    this.addPoint(evt.xy);
+                    this.drawing = true;
+                    this.lastUp = evt.xy;
                 }
-                this.lastUp = evt.xy;
             }
-            return false;
+            this.mouseDown = false;
+            return !this.stopUp;
         }
         return true;
     },

Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js	2011-01-12 08:01:00 UTC (rev 11026)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js	2011-01-12 10:47:28 UTC (rev 11027)
@@ -76,6 +76,20 @@
     persist: false,
 
     /**
+     * APIProperty: stopDown
+     * {Boolean} Stop event propagation on mousedown. Must be false to
+     *     allow "pan while drawing". Defaults to false.
+     */
+    stopDown: false,
+
+    /**
+     * APIPropery: stopUp
+     * {Boolean} Stop event propagation on mouse. Must be false to
+     *     allow "pan while dragging". Defaults to fase.
+     */
+    stopUp: false,
+
+    /**
      * Property: layerOptions
      * {Object} Any optional properties to be set on the sketch layer.
      */
@@ -328,7 +342,7 @@
             this.modifyFeature(evt.xy);
         }
         this.lastDown = evt.xy;
-        return false;
+        return !this.stopDown;
     },
 
     /**
@@ -363,7 +377,7 @@
     mouseup: function (evt) {
         if(this.drawing) {
             this.finalize();
-            return false;
+            return !this.stopUp;
         } else {
             return true;
         }



More information about the Commits mailing list