OpenLayers OpenLayers

Ticket #601: mousedefaultsDestroy.patch

File mousedefaultsDestroy.patch, 2.7 kB (added by euzuro, 2 years ago)

we need to make a property to store the specially bound function with which we register the wheel bits (wheelObserver). then we can add a destroy() that unregisters all the map events and also those pesky window/document wheel bits.

  • lib/OpenLayers/Control/MouseDefaults.js

    old new  
    1818    /** @type Boolean */ 
    1919    performedDrag: false, 
    2020 
     21    /** @type function */ 
     22    wheelObserver: null, 
     23 
    2124    /**  
    2225     * @constructor 
    2326     */ 
     
    2831    /** 
    2932     *  
    3033     */     
     34    destroy: function() { 
     35         
     36        if (this.handler) { 
     37            this.handler.destroy(); 
     38        } 
     39        this.handler = null; 
     40 
     41        this.map.events.unregister( "click", this, this.defaultClick ); 
     42        this.map.events.unregister( "dblclick", this, this.defaultDblClick ); 
     43        this.map.events.unregister( "mousedown", this, this.defaultMouseDown ); 
     44        this.map.events.unregister( "mouseup", this, this.defaultMouseUp ); 
     45        this.map.events.unregister( "mousemove", this, this.defaultMouseMove ); 
     46        this.map.events.unregister( "mouseout", this, this.defaultMouseOut ); 
     47 
     48        //unregister mousewheel events specifically on the window and document 
     49        OpenLayers.Event.stopObserving(window, "DOMMouseScroll",  
     50                                        this.wheelObserver); 
     51        OpenLayers.Event.stopObserving(window, "mousewheel",  
     52                                        this.wheelObserver); 
     53        OpenLayers.Event.stopObserving(document, "mousewheel",  
     54                                        this.wheelObserver); 
     55        this.wheelObserver = null; 
     56                       
     57        OpenLayers.Control.prototype.destroy.apply(this, arguments);         
     58    }, 
     59 
     60    /** 
     61     *  
     62     */ 
    3163    draw: function() { 
    3264        this.map.events.register( "click", this, this.defaultClick ); 
    3365        this.map.events.register( "dblclick", this, this.defaultDblClick ); 
     
    4476     *  
    4577     */ 
    4678    registerWheelEvents: function() { 
     79 
     80        this.wheelObserver = this.onWheelEvent.bindAsEventListener(this); 
    4781         
    4882        //register mousewheel events specifically on the window and document 
    49         OpenLayers.Event.observe(window, "DOMMouseScroll",  
    50                       this.onWheelEvent.bindAsEventListener(this)); 
    51         OpenLayers.Event.observe(window, "mousewheel",  
    52                       this.onWheelEvent.bindAsEventListener(this)); 
    53         OpenLayers.Event.observe(document, "mousewheel",  
    54                       this.onWheelEvent.bindAsEventListener(this)); 
    55  
     83        OpenLayers.Event.observe(window, "DOMMouseScroll", this.wheelObserver); 
     84        OpenLayers.Event.observe(window, "mousewheel", this.wheelObserver); 
     85        OpenLayers.Event.observe(document, "mousewheel", this.wheelObserver); 
    5686    }, 
    5787 
    5888    /**