[OpenLayers-Commits] r11965 - in trunk/openlayers: lib/OpenLayers/Control tests/Control

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Tue May 10 03:13:26 EDT 2011


Author: erilem
Date: 2011-05-10 00:13:22 -0700 (Tue, 10 May 2011)
New Revision: 11965

Modified:
   trunk/openlayers/lib/OpenLayers/Control/Panel.js
   trunk/openlayers/tests/Control/Panel.html
Log:
allow toggling TYPE_TOOL controls in panels, p=jorix, r=me (closes #3294)

Modified: trunk/openlayers/lib/OpenLayers/Control/Panel.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/Panel.js	2011-05-10 07:09:17 UTC (rev 11964)
+++ trunk/openlayers/lib/OpenLayers/Control/Panel.js	2011-05-10 07:13:22 UTC (rev 11965)
@@ -47,6 +47,14 @@
     saveState: false,
       
     /**
+     * APIProperty: allowDepress
+     * {Boolean} If is true the <OpenLayers.Control.TYPE_TOOL> controls can 
+     *     be deactivated by clicking the icon that represents them.  Default 
+     *     is false.
+     */
+    allowDepress: false,
+    
+    /**
      * Property: activeState
      * {Object} stores the active state of this panel's controls.
      */
@@ -199,15 +207,19 @@
             }
             return;
         }
-        var c;
-        for (var i=0, len=this.controls.length; i<len; i++) {
-            c = this.controls[i];
-            if (c != control &&
-               (c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
-                c.deactivate();
+        if (this.allowDepress && control.active) {
+            control.deactivate();
+        } else {
+            var c;
+            for (var i=0, len=this.controls.length; i<len; i++) {
+                c = this.controls[i];
+                if (c != control &&
+                   (c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) {
+                    c.deactivate();
+                }
             }
+            control.activate();
         }
-        control.activate();
     },
 
     /**

Modified: trunk/openlayers/tests/Control/Panel.html
===================================================================
--- trunk/openlayers/tests/Control/Panel.html	2011-05-10 07:09:17 UTC (rev 11964)
+++ trunk/openlayers/tests/Control/Panel.html	2011-05-10 07:13:22 UTC (rev 11965)
@@ -247,6 +247,7 @@
         t.ok(!controlNoDeactive.active, "Tool control autoActivate:true is not active");
         
     }
+
     function test_Control_Panel_deactivate (t) {
         t.plan(2);
         var map = new OpenLayers.Map('map');
@@ -262,6 +263,31 @@
 
         map.destroy();
     }
+
+    function test_allowDepress (t) { 
+        t.plan(2); 
+        var map = new OpenLayers.Map('map');
+
+        var panel = new OpenLayers.Control.Panel();
+        panel.addControls([new OpenLayers.Control(),new OpenLayers.Control()]);
+        map.addControl(panel);
+        
+        var control1 = panel.controls[1]
+        
+        panel.activateControl(control1);
+        
+        panel.allowDepress = false;
+        panel.activateControl(control1);
+        t.eq(control1.active, true,
+            "control1 remains active after calling again activateControl when allowDepress = false");
+        panel.allowDepress = true;
+        panel.activateControl(control1);
+        t.eq(control1.active, false,
+            "control1 is inactive after calling again activateControl when allowDepress = true");
+
+        // panel.deactivate();
+        map.destroy();
+    }
   </script>
 </head>
 <body>



More information about the Commits mailing list