[fusion-commits] r2397 - trunk/lib/OpenLayers

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Jun 2 13:31:21 EDT 2011


Author: madair
Date: 2011-06-02 10:31:21 -0700 (Thu, 02 Jun 2011)
New Revision: 2397

Modified:
   trunk/lib/OpenLayers/OpenLayers.js
Log:
closes #458: adds a keypress watcher to cancel multipoint sketches by the ESC key

Modified: trunk/lib/OpenLayers/OpenLayers.js
===================================================================
--- trunk/lib/OpenLayers/OpenLayers.js	2011-06-02 17:25:58 UTC (rev 2396)
+++ trunk/lib/OpenLayers/OpenLayers.js	2011-06-02 17:31:21 UTC (rev 2397)
@@ -25457,6 +25457,12 @@
     freehandToggle: 'shiftKey',
 
     /**
+     * Property: cancelKey
+     * {integer constant} The key to use to cancel a sketch
+     */
+    cancelKey: OpenLayers.Event.KEY_ESC,
+
+    /**
      * Constructor: OpenLayers.Handler.Path
      * Create a new path hander
      *
@@ -25480,9 +25486,54 @@
      */
     initialize: function(control, callbacks, options) {
         OpenLayers.Handler.Point.prototype.initialize.apply(this, arguments);
+        
+        this.keypressWatcher = OpenLayers.Function.bind(this.keypressHandler, this);
     },
         
     /**
+     * APIMethod: activate
+     * turn on the handler
+     */
+    activate: function() {
+        if(!OpenLayers.Handler.Point.prototype.activate.apply(this, arguments)) {
+            return false;
+        }
+        
+        //add in an observer to be able to cancel the sketch on a keypress
+        OpenLayers.Event.observe(document, 'keypress', this.keypressWatcher);
+        
+        return true;
+    },
+    
+    /**
+     * APIMethod: deactivate
+     * turn off the handler
+     */
+    deactivate: function() {
+        if(!OpenLayers.Handler.Point.prototype.deactivate.apply(this, arguments)) {
+            return false;
+        }
+        
+        //remove the keypress observer
+        OpenLayers.Event.stopObserving(document, 'keypress', this.keypressWatcher);
+        return true;
+    },
+    
+    /**
+     * Method: keypressHandler 
+     * An event listener to be able to cancel a drawing in progress 
+     * 
+     * Parameters:
+     * evt - {Event} The browser event
+     */
+    keypressHandler: function(evt) {
+        var charCode = (evt.charCode) ? evt.charCode : evt.keyCode;
+        if (charCode == this.cancelKey) {
+            this.cancel();
+        }
+    },
+    
+    /**
      * Method: createFeature
      * Add temporary geometries
      *



More information about the fusion-commits mailing list