OpenLayers OpenLayers

Ticket #754: panzoombar.2.patch

File panzoombar.2.patch, 4.5 kB (added by kkempfer, 1 year ago)

better tests on child divs

  • tests/Control/test_PanZoomBar.html

    old new  
    44  <script type="text/javascript"> 
    55    var map;  
    66    function test_01_Control_PanZoomBar_constructor (t) { 
    7         t.plan( 4 ); 
     7         
     8        t.plan( 6 ); 
     9         
    810     
    9         control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100)}); 
     11        control = new OpenLayers.Control.PanZoomBar({position: new OpenLayers.Pixel(100,100), showPan: false, showZoomBar: false}); 
    1012        t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" ); 
    1113        t.eq( control.displayClass,  "olControlPanZoomBar", "displayClass is correct" ); 
    1214        t.eq( control.position.x, 100, "PanZoom X Set correctly.");  
    1315        t.eq( control.position.y, 100, "PanZoom y Set correctly.");  
     16        t.eq( control.showPan, false, "showPan Set correctly.");  
     17        t.eq( control.showZoomBar, false, "showZoomBar Set correctly.");  
     18         
    1419    } 
    1520    function test_02_Control_PanZoomBar_addControl (t) { 
    16         t.plan( 8 ); 
     21        t.plan( 10 ); 
    1722        map = new OpenLayers.Map('map', {controls:[]}); 
    1823        var layer = new OpenLayers.Layer.WMS("Test Layer",  
    1924            "http://octo.metacarta.com/cgi-bin/mapserv?", 
    2025            {map: "/mapdata/vmap_wms.map", layers: "basic"}); 
    2126        map.addLayer(layer); 
    22         control = new OpenLayers.Control.PanZoomBar(); 
     27        control = new OpenLayers.Control.PanZoomBar({showPan: false, showZoomBar: false}); 
    2328        t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" ); 
    2429        t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" ); 
    2530        map.addControl(control); 
     
    2833        t.eq( parseInt(control.div.style.zIndex), 1001, "Control div zIndexed properly" ); 
    2934        t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), 1001, "Viewport div contains control div" ); 
    3035        t.eq( control.div.style.top, "4px", "Control div top located correctly by default"); 
     36        t.eq( control.div.childNodes.length, 0, "showPan/showZoomBar work correctly"); 
    3137 
    3238        var control2 = new OpenLayers.Control.PanZoomBar(); 
    3339        map.addControl(control2, new OpenLayers.Pixel(100,100)); 
    3440        t.eq( control2.div.style.top, "100px", "2nd control div is located correctly"); 
     41        t.eq( control2.div.childNodes.length, 8, "showPan/showZoomBar work correctly on 2nd control div"); 
    3542    } 
    3643 
    3744  </script> 
  • lib/OpenLayers/Control/PanZoomBar.js

    old new  
    4646     * {<OpenLayers.Events>} 
    4747     */ 
    4848    divEvents: null, 
     49     
     50    /** Whether or not Pan icons will be displayed  
     51     *   Default is true 
     52     *  
     53     * @type Boolean 
     54     */ 
     55    showPan: true, 
     56     
     57    /** Whether or not ZoomBar will be displayed  
     58     *   Default is true 
     59     *  
     60     * @type Boolean 
     61     */ 
     62    showZoomBar: true, 
    4963 
    5064    /** 
    5165     * Constructor: <OpenLayers.Control.PanZoomBar> 
     
    115129 
    116130        var sz = new OpenLayers.Size(18,18); 
    117131        var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y); 
    118  
    119         this._addButton("panup", "north-mini.png", centered, sz); 
    120         px.y = centered.y+sz.h; 
    121         this._addButton("panleft", "west-mini.png", px, sz); 
    122         this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz); 
    123         this._addButton("pandown", "south-mini.png", centered.add(0, sz.h*2), sz); 
    124         this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h*3+5), sz); 
    125         centered = this._addZoomBar(centered.add(0, sz.h*4 + 5)); 
    126         this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); 
     132        if(this.showPan){ 
     133            this._addButton("panup", "north-mini.png", centered, sz); 
     134            px.y = centered.y+sz.h; 
     135            this._addButton("panleft", "west-mini.png", px, sz); 
     136            this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz); 
     137            this._addButton("pandown", "south-mini.png", centered.add(0, sz.h*2), sz); 
     138        } 
     139        if(this.showZoomBar){ 
     140            this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h*3+5), sz); 
     141            centered = this._addZoomBar(centered.add(0, sz.h*4 + 5)); 
     142            this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); 
     143        } 
    127144        return this.div; 
    128145    }, 
    129146