OpenLayers OpenLayers

Ticket #341: 341.patch

File 341.patch, 2.9 kB (added by sderle, 2 years ago)

see http://trac.openlayers.org/ticket/341#comment:18 for description

  • lib/OpenLayers/Control/Navigation.js

    old new  
    5959        return false; 
    6060    }, 
    6161 
     62    wheelChange: function(evt, deltaZ) { 
     63        var newZoom = this.map.getZoom() + deltaZ; 
     64        if (!this.map.isValidZoomLevel(newZoom)) return; 
     65 
     66        var size    = this.map.getSize(); 
     67        var deltaX  = size.w/2 - evt.xy.x; 
     68        var deltaY  = evt.xy.y - size.h/2; 
     69        var newRes  = this.map.baseLayer.resolutions[newZoom]; 
     70        var zoomPoint = this.map.getLonLatFromPixel(evt.xy); 
     71        var newCenter = new OpenLayers.LonLat( 
     72                            zoomPoint.lon + deltaX * newRes, 
     73                            zoomPoint.lat + deltaY * newRes ); 
     74        this.map.setCenter( newCenter, newZoom ); 
     75    }, 
     76 
    6277    /** User spun scroll wheel up 
    6378     *  
    6479     */ 
    6580    wheelUp: function(evt) { 
    66         this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    67                            this.map.getZoom() + 1); 
     81        this.wheelChange(evt, 1); 
    6882    }, 
    6983 
    7084    /** User spun scroll wheel down 
    7185     *  
    7286     */ 
    7387    wheelDown: function(evt) { 
    74         this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    75                            this.map.getZoom() - 1); 
     88        this.wheelChange(evt, -1); 
    7689    }, 
    7790     
    7891    /** @final @type String */ 
  • lib/OpenLayers/Handler/MouseWheel.js

    old new  
    1313    /** @type function **/ 
    1414    wheelListener: null, 
    1515 
     16    /** @type OpenLayers.Pixel 
     17     *  @private 
     18     *  
     19     *  mousePosition is necessary because evt.clientX/Y is buggy in Moz on 
     20     *  wheel events, so we cache and use the value from the last mousemove. 
     21     **/ 
     22    mousePosition: null, 
     23 
    1624    /** 
    1725     * @constructor 
    1826     * 
     
    6876                // add the mouse position to the event because mozilla has a bug 
    6977                // with clientX and clientY (see https://bugzilla.mozilla.org/show_bug.cgi?id=352179) 
    7078                // getLonLatFromViewPortPx(e) returns wrong values 
    71                 // TODO FIXME FIXME this might not be the right way to port the 2.3 behavior 
    72                 e.xy = this.map.events.getMousePosition(e); 
     79                e.xy = this.mousePosition; 
    7380                if (delta < 0) { 
    7481                   this.callback("down", [e, delta]); 
    7582                } else { 
     
    8289        } 
    8390    }, 
    8491 
     92    mousemove: function (evt) { 
     93        this.mousePosition = evt.xy; 
     94    }, 
     95 
    8596    activate: function (evt) { 
    8697        OpenLayers.Handler.prototype.activate.apply(this, arguments); 
    8798        //register mousewheel events specifically on the window and document