OpenLayers OpenLayers

Changeset 2877

Show
Ignore:
Timestamp:
03/24/07 19:11:18 (2 years ago)
Author:
crschmidt
Message:

With Erik's approval on #341, I'm happy with this. This restores the
mousewheel functionality we had in earlier releases in a similar way, rewritten
for handlers. (The benefit of handlers in this case is that handlers are
write-once, use many, so the next mousewheel thing we get will *also* be able
to use this code.)

Files:

Legend:

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

    r2868 r2877  
    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 
     
    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     
  • trunk/openlayers/lib/OpenLayers/Handler/MouseWheel.js

    r2803 r2877  
    1313    /** @type function **/ 
    1414    wheelListener: null, 
     15 
     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, 
    1523 
    1624    /** 
     
    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]); 
     
    8188            OpenLayers.Event.stop(e); 
    8289        } 
     90    }, 
     91 
     92    mousemove: function (evt) { 
     93        this.mousePosition = evt.xy; 
    8394    }, 
    8495