OpenLayers OpenLayers

Changeset 281

Show
Ignore:
Timestamp:
05/23/06 11:39:07 (3 years ago)
Author:
sderle
Message:

Some improvements to Control.PanZoomBar, mostly to make it work with the new graphics.

Files:

Legend:

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

    r277 r281  
    99OpenLayers.Control.PanZoomBar.prototype =  
    1010  Object.extend( new OpenLayers.Control.PanZoom(), { 
    11     // Array(...) 
     11    /** @type Array(...) */ 
    1212    buttons: null, 
     13 
     14    /** @type int */ 
     15    zoomStopWidth: 18, 
     16 
     17    /** @type int */ 
     18    zoomStopHeight: 11, 
    1319 
    1420    initialize: function() { 
     
    2329    draw: function(px) { 
    2430        // initialize our internal div 
    25         OpenLayers.Control.prototype.draw.apply(this); 
    26         this.map.events.register("zoomend", this, this.moveZoomBar)
     31        OpenLayers.Control.prototype.draw.apply(this, arguments); 
     32        px = this.position
    2733 
    2834        // place the controls 
     
    4450    }, 
    4551    _addZoomBar:function(centered,sz) { 
    46         var zoomStopSize = 15; 
     52        /*** THIS METHOD IS A HAIRBALL AND SHOULD BE REFACTORED ***/ 
     53        var zoomStopSize = this.zoomStopHeight; 
    4754        var slider = OpenLayers.Util.createImage("img/slider.png", 
    48                        new OpenLayers.Pixel(22,9),  
    49                        centered.add(0, (this.map.getZoomLevels())*zoomStopSize), "absolute", 
     55                       new OpenLayers.Pixel(20,9),  
     56                       centered.add(-1, (this.map.getZoomLevels())*zoomStopSize), "absolute", 
    5057                       "OpenLayers_Control_PanZoomBar_Slider"); 
    5158        sz.h = zoomStopSize*(this.map.getZoomLevels()+1); 
    52         sz.w = 17; 
     59        sz.w = this.zoomStopWidth; 
     60 
    5361        var div = OpenLayers.Util.createDiv('OpenLayers_Control_PanZoomBar_Zoombar',centered,sz); 
    5462        div.style.backgroundImage = "url(img/zoombar.png)"; 
    55         div.onmousedown  = this.divClick.bindAsEventListener(div); 
    56         div.onmousemove  = this.zoomBarDivDrag.bindAsEventListener(div); 
     63        div.onmousedown = this.divClick.bindAsEventListener(div); 
    5764        div.ondblclick  = this.doubleClick.bindAsEventListener(div); 
    5865        div.slider = slider; 
     
    6168        div.div = this.div; 
    6269        this.div.appendChild(div); 
    63         slider.startTop = div.style.top; 
     70 
     71        slider.startTop = parseInt(div.style.top); 
    6472        slider.getMousePosition = this.getMousePosition; 
    6573        slider.onmousedown = this.zoomBarDown.bindAsEventListener(slider); 
     
    6977        slider.div = this.div; 
    7078        slider.map = this.map; 
     79        slider.zoomStopHeight = this.zoomStopHeight; 
    7180        slider.moveZoomBar = this.moveZoomBar; 
    7281        slider.zIndex = this.div.zIndex + 5; 
    7382        this.div.appendChild(slider); 
    7483        this.buttons.append(slider); 
     84 
     85        this.map.events.register("zoomend", slider, this.moveZoomBar); 
     86 
    7587        centered = centered.add(0, zoomStopSize*(this.map.getZoomLevels()+1)); 
    7688        return centered;  
     
    8092        var y = evt.xy.y; 
    8193        var top = this.style.top; 
    82         var levels = Math.floor((y - parseInt(top))/15); 
     94        var levels = Math.floor((y - parseInt(top))/this.zoomStopHeight); 
    8395        this.map.zoomTo(this.map.getZoomLevels() - levels); 
    8496        Event.stop(evt); 
     
    111123        evt.xy = this.getMousePosition(evt); 
    112124        var deltaY = this.zoomStart.y - evt.xy.y 
    113         this.map.zoomTo(this.map.zoom + Math.round(deltaY/15)); 
     125        this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 
    114126        this.moveZoomBar(); 
    115127        this.div.style.cursor="default"; 
     
    118130    }, 
    119131    moveZoomBar:function() { 
    120         var slider = $('OpenLayers_Control_PanZoomBar_Slider'); 
    121         slider.style.top = (this.map.getZoomLevels() - this.map.getZoom())*15+ 
    122                           parseInt(document.getElementById("OpenLayers_Control_PanZoomBar_Zoombar").style.top) + 3; 
     132        /*** `this` is actually slider... that should be fixed at some point */ 
     133        var newTop =  
     134            (this.map.getZoomLevels() - this.map.getZoom()) * this.zoomStopHeight 
     135            + this.startTop + 1; 
     136        this.style.top = newTop + "px"; 
    123137    },     
    124138