OpenLayers OpenLayers

Changeset 2548

Show
Ignore:
Timestamp:
03/08/07 17:29:10 (2 years ago)
Author:
sderle
Message:

Calculate new center for mouse wheel zooming. Fixes #341.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/vector-2.4/lib/OpenLayers/Control/MouseDefaults.js

    r2509 r2548  
    100100    }, 
    101101 
     102    zoomWithWheel: function (evt, direction) { 
     103        var mouse = this.map.getLonLatFromPixel(evt.xy); 
     104        var center = this.map.getCenter(); 
     105        var resolution = this.map.getResolution(); 
     106        var mouseToCenter = new OpenLayers.Pixel((mouse.lon - center.lon) / resolution, 
     107                                                 (mouse.lat - center.lat) / resolution); 
     108        var nextZoom = this.map.getZoom() + direction; 
     109        var nextResolution = this.map.baseLayer.resolutions[nextZoom]; 
     110        this.map.setCenter( 
     111            new OpenLayers.LonLat(center.lon + (mouseToCenter.x * nextResolution), 
     112                                  center.lat + (mouseToCenter.y * nextResolution)), 
     113            nextZoom);  
     114    }, 
     115 
    102116    /** User spun scroll wheel up 
    103      *  
    104117     */ 
    105118    wheelUp: function(evt) { 
    106         this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    107                            this.map.getZoom() + 1); 
     119        this.zoomWithWheel(+1); 
    108120    }, 
    109121 
    110122    /** User spun scroll wheel down 
    111      *  
    112123     */ 
    113124    wheelDown: function(evt) { 
    114         this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 
    115                            this.map.getZoom() - 1); 
     125        this.zoomWithWheel(-1); 
    116126    }, 
    117127