OpenLayers OpenLayers

Ticket #1288: frac_bar.patch

File frac_bar.patch, 2.7 kB (added by crschmidt, 1 year ago)
  • lib/OpenLayers/Control/PanZoomBar.js

    old new  
    241241        } 
    242242        var y = evt.xy.y; 
    243243        var top = OpenLayers.Util.pagePosition(evt.object)[1]; 
    244         var levels = Math.floor((y - top)/this.zoomStopHeight); 
    245         this.map.zoomTo((this.map.getNumZoomLevels() -1) -  levels); 
     244        var levels = (y - top)/this.zoomStopHeight; 
     245        var zoom = (this.map.getNumZoomLevels() - 1) - levels;  
     246        if (map.fractionalZoom) { 
     247           zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels()); 
     248        } else { 
     249            zoom = Math.floor(zoom); 
     250        }     
     251        this.map.zoomTo(zoom); 
    246252        OpenLayers.Event.stop(evt); 
    247253    }, 
    248254     
     
    314320                scope: this 
    315321            }); 
    316322            var deltaY = this.zoomStart.y - evt.xy.y; 
    317             this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 
     323            var zoomLevel = this.map.zoom; 
     324            if (this.map.fractionalZoom) { 
     325                zoomLevel += deltaY/this.zoomStopHeight; 
     326                zoomLevel = Math.min(Math.max(zoomLevel, 0),  
     327                                     this.map.getNumZoomLevels()); 
     328            } else { 
     329                zoomLevel += Math.round(deltaY/this.zoomStopHeight); 
     330            } 
     331            this.map.zoomTo(zoomLevel); 
    318332            this.moveZoomBar(); 
    319333            this.mouseDragStart = null; 
    320334            OpenLayers.Event.stop(evt); 
  • examples/fractional-zoom.html

    old new  
    1313        var map; 
    1414 
    1515        function init() { 
    16             map = new OpenLayers.Map('map'); 
     16            map = new OpenLayers.Map('map',  
     17                 {controls: [new OpenLayers.Control.Navigation(),  
     18                             new OpenLayers.Control.PanZoomBar()],  
     19                  numZoomLevels: 10 }); 
    1720            var wms = new OpenLayers.Layer.WMS( 
    1821                "OpenLayers WMS", 
    1922                "http://labs.metacarta.com/wms/vmap0", 
     
    2225            map.addLayers([wms]); 
    2326 
    2427            map.events.register("moveend", null, displayZoom); 
    25             map.addControl( new OpenLayers.Control.LayerSwitcher() ); 
    2628 
    2729            map.zoomToMaxExtent(); 
    2830             
     
    3638         
    3739        function update(input) { 
    3840            map.fractionalZoom = input.checked; 
     41            map.zoomTo(Math.round(map.zoom)); 
    3942        } 
    4043    </script> 
    4144  </head>