OpenLayers OpenLayers

Ticket #1283: Switch.patch

File Switch.patch, 5.2 kB (added by enjahova, 1 year ago)

Switch control + test + fix for redraw in Panel.js

  • tests/Control/test_Switch.html

    old new  
     1<html> 
     2<head> 
     3  <script src="../../lib/OpenLayers.js"></script> 
     4  <script type="text/javascript"> 
     5    var map, control, layer;  
     6 
     7    function init_map() { 
     8        control = new OpenLayers.Control.Identify(null); 
     9        map = new OpenLayers.Map("map", {controls:[control]}); 
     10        layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     11                    "http://labs.metacarta.com/wms/vmap0", 
     12                    {layers: 'basic'} ); 
     13        map.addLayer(layer);  
     14        return [map, control]; 
     15    }     
     16    function test_Control_Switch_constructor (t) { 
     17        t.plan( 1 ); 
     18     
     19        control = new OpenLayers.Control.Switch(); 
     20        t.ok( control instanceof OpenLayers.Control.Switch, "new OpenLayers.Control returns object" ); 
     21    } 
     22     
     23    function test_Control_Switch_toggle(t) { 
     24        t.plan(2); 
     25         
     26        var user_on_function = function() { 
     27            t.ok(true, "user on function called successfully"); 
     28        }; 
     29        var user_off_function = function() { 
     30            t.ok(true, "user off function called successfully"); 
     31        }; 
     32 
     33        var control = new OpenLayers.Control.Switch(user_on_function, user_off_function); 
     34        var map = new OpenLayers.Map("map", {controls:[control]}); 
     35        var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",  
     36                                        "http://labs.metacarta.com/wms/vmap0", 
     37                                        {layers: 'basic'}); 
     38        control.activate(); 
     39        control.deactivate();  
     40    } 
     41     
     42 
     43  </script> 
     44</head> 
     45<body> 
     46    <a id="scale" href="">Switch</a> <br /> 
     47    <div id="map" style="width: 1024px; height: 512px;"/> 
     48</body> 
     49</html> 
  • tests/list-tests.html

    old new  
    8686    <li>Control/test_Permalink.html</li> 
    8787    <li>Control/test_Scale.html</li> 
    8888    <li>Control/test_SelectFeature.html</li> 
     89    <li>Control/test_Switch.html</li> 
    8990    <li>test_Handler.html</li> 
    9091    <li>Handler/test_Click.html</li> 
    9192    <li>Handler/test_Hover.html</li> 
  • lib/OpenLayers/Control/Switch.js

    old new  
     1/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD 
     2 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the 
     3 * full text of the license. */ 
     4 
     5/** 
     6 * @requires OpenLayers/Control.js 
     7 * 
     8 * Class: OpenLayers.Control.Switch 
     9 * 
     10 * Inherits from: 
     11 *  - <OpenLayers.Control> 
     12 */ 
     13OpenLayers.Control.Switch = OpenLayers.Class(OpenLayers.Control, { 
     14    /** 
     15     * Property: type 
     16     * {OpenLayers.Control.TYPE} 
     17     */ 
     18    type: OpenLayers.Control.TYPE_TOGGLE, 
     19     
     20    /** 
     21     * Constructor: OpenLayers.Control.Switch  
     22     * Fires a user defined function when toggled on/off 
     23     * 
     24     * Parameters: 
     25     * options - {func} An optional object whose properties will be used 
     26     *     to extend the control. 
     27     */ 
     28    initialize: function(on, off, options) { 
     29        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
     30        this.userOn = on; 
     31        this.userOff = off; 
     32    }, 
     33     
     34    /** 
     35     * Method: activate 
     36     * Override OpenLayers.Control.activate to call user defined "on" function 
     37     */ 
     38    activate: function () { 
     39        if (this.active) { 
     40            return false; 
     41        } 
     42        if (this.handler) { 
     43            this.handler.activate(); 
     44        } 
     45        this.active = true; 
     46        this.userOn(); 
     47        return true; 
     48    }, 
     49      
     50    /** 
     51     * Method: deactivate 
     52     * Override OpenLayers.Control.deactivate to call user defined "off" function 
     53     */  
     54    deactivate: function () { 
     55        if (this.active) { 
     56            if (this.handler) { 
     57                this.handler.deactivate(); 
     58            } 
     59            this.active = false; 
     60            this.userOff(); 
     61            return true; 
     62        } 
     63        return false; 
     64    }, 
     65 
     66     
     67    /** 
     68     * Method: userOn 
     69     * placeholder for the user defined function that will be fired when Switch is activated 
     70     */ 
     71    userOn: function(){ 
     72    }, 
     73    /** 
     74     * Method: userOn 
     75     * placeholder for the user defined function that will be fired when Switch is activated 
     76     */ 
     77    userOff: function(){ 
     78    }, 
     79 
     80    CLASS_NAME: "OpenLayers.Control.Switch" 
     81}); 
  • lib/OpenLayers.js

    old new  
    148148            "OpenLayers/Control/ModifyFeature.js", 
    149149            "OpenLayers/Control/Panel.js", 
    150150            "OpenLayers/Control/SelectFeature.js", 
     151            "OpenLayers/Control/Switch.js", 
    151152            "OpenLayers/Geometry.js", 
    152153            "OpenLayers/Geometry/Rectangle.js", 
    153154            "OpenLayers/Geometry/Collection.js",