OpenLayers OpenLayers

Changeset 6462

Show
Ignore:
Timestamp:
03/07/08 18:04:32 (6 months ago)
Author:
crschmidt
Message:

Add improved navigation control support for disabling zooming with the
mousewheel. Original from sbenthall (yay), example and more code from me, tests
from elem. r=elemoine. (Closes #1339)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Control/Navigation.js

    r6418 r6462  
    3838 
    3939    /** 
     40     * APIProperty: zoomWheelEnabled 
     41     * {Boolean} Whether the mousewheel should zoom the map 
     42     */ 
     43    zoomWheelEnabled: true,  
     44 
     45    /** 
    4046     * Constructor: OpenLayers.Control.Navigation 
    4147     * Create a new navigation control 
     
    7682    activate: function() { 
    7783        this.dragPan.activate(); 
    78         this.handlers.wheel.activate(); 
     84        if (this.zoomWheelEnabled) { 
     85            this.handlers.wheel.activate(); 
     86        }     
    7987        this.handlers.click.activate(); 
    8088        this.zoomBox.activate(); 
     
    169177        this.wheelChange(evt, -1); 
    170178    }, 
     179     
     180    /** 
     181     * Method: disableZoomWheel 
     182     */ 
     183     
     184    disableZoomWheel : function() { 
     185        this.zoomWheelEnabled = false; 
     186        this.handlers.wheel.deactivate();        
     187    }, 
     188     
     189    /** 
     190     * Method: enableZoomWheel 
     191     */ 
     192     
     193    enableZoomWheel : function() { 
     194        this.zoomWheelEnabled = true; 
     195        if (this.active) { 
     196            this.handlers.wheel.activate(); 
     197        }     
     198    }, 
    171199 
    172200    CLASS_NAME: "OpenLayers.Control.Navigation" 
  • trunk/openlayers/tests/Control/test_Navigation.html

    r6167 r6462  
    7070    } 
    7171 
     72    function test_Control_Navigation_disableZoomWheel(t) { 
     73        t.plan(2); 
     74        var nav = new OpenLayers.Control.Navigation(); 
     75        var wheel = new OpenLayers.Handler.MouseWheel(nav, {}); 
     76        nav.handlers.wheel = wheel; 
     77        wheel.register = function() {}; 
     78        wheel.unregister = function() {}; 
     79        wheel.activate(); 
     80        nav.disableZoomWheel(); 
     81        t.eq(nav.zoomWheelEnabled, false, "mouse wheel deactivated"); 
     82        t.eq(wheel.active, false, "mouse wheel handler deactivated"); 
     83    } 
     84 
     85    function test_Control_Navigation_enableZoomWheel(t) { 
     86        t.plan(2); 
     87        var nav = new OpenLayers.Control.Navigation({zoomWheelEnabled: false}); 
     88        nav.active = true; 
     89        var wheel = new OpenLayers.Handler.MouseWheel(nav, {}); 
     90        wheel.register = function() {}; 
     91        wheel.unregister = function() {}; 
     92        nav.handlers.wheel = wheel; 
     93        nav.enableZoomWheel(); 
     94        t.eq(nav.zoomWheelEnabled, true, "mouse wheel activated"); 
     95        t.eq(wheel.active, true, "mouse wheel handler activated"); 
     96    } 
     97 
    7298  </script> 
    7399</head>