OpenLayers OpenLayers

Ticket #1486: panzoombar.patch

File panzoombar.patch, 2.1 kB (added by crschmidt, 9 months ago)
  • tests/Control/PanZoomBar.html

    old new  
    3333        map.addControl(control2, new OpenLayers.Pixel(100,100)); 
    3434        t.eq( control2.div.style.top, "100px", "2nd control div is located correctly"); 
    3535    } 
     36    function test_Control_PanZoomBar_divClick (t) { 
     37        t.plan(2); 
     38        map = new OpenLayers.Map('map', {controls:[]}); 
     39        var layer = new OpenLayers.Layer.WMS("Test Layer",  
     40            "http://octo.metacarta.com/cgi-bin/mapserv?", 
     41            {map: "/mapdata/vmap_wms.map", layers: "basic"}); 
     42        map.addLayer(layer); 
     43        control = new OpenLayers.Control.PanZoomBar(); 
     44        map.addControl(control); 
     45        control.divClick({'xy': {'x': 0, 'y': 50}, which: 1}); 
     46        t.eq(map.zoom, 11, "zoom is correct on standard map"); 
    3647 
     48        map.fractionalZoom = true; 
     49        control.divClick({'xy': {'x': 0, 'y': 49}, which: 1}); 
     50        t.eq(map.zoom.toFixed(3), '10.545', "zoom is correct on fractional zoom map"); 
     51     
     52    } 
     53 
    3754  </script> 
    3855</head> 
    3956<body> 
  • lib/OpenLayers/Control/PanZoomBar.js

    old new  
    242242        var y = evt.xy.y; 
    243243        var top = OpenLayers.Util.pagePosition(evt.object)[1]; 
    244244        var levels = (y - top)/this.zoomStopHeight; 
    245         var zoom = (this.map.getNumZoomLevels() - 1) - levels;  
    246         if(this.map.fractionalZoom) { 
    247            zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); 
    248         } else { 
    249             zoom = Math.floor(zoom); 
     245        if(!this.map.fractionalZoom) { 
     246            levels = Math.floor(levels); 
    250247        }     
     248        var zoom = (this.map.getNumZoomLevels() - 1) - levels;  
     249        zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); 
    251250        this.map.zoomTo(zoom); 
    252251        OpenLayers.Event.stop(evt); 
    253252    },