[OpenLayers-Users] NavToolBar hide/show controls

Linda_Rawson linda.rawson at gmail.com
Wed Aug 8 14:06:16 EDT 2007


Okay.  Here is what I did to do this.  Don't make fun of me....it works!

In Control.js I added the following variable

hidden: null,

In Panel.js I added the following functions

    hide: function(controlName) {
        for (var i = 0; i < this.controls.length; i++) {
            var cName = "OpenLayers.Control." + controlName;
            if (this.controls[i].CLASS_NAME == cName) {
                this.controls[i].hidden = true;
            }
        }
        if (this.map) { // map.addControl() has already been called on the
panel
          this.redraw();
        }
    },
    
    show: function(controlName) {
        for (var i = 0; i < this.controls.length; i++) {
            var cName = "OpenLayers.Control." + controlName;
            if (this.controls[i].CLASS_NAME == cName) {
                this.controls[i].hidden = false;
            }
        }
        if (this.map) { // map.addControl() has already been called on the
panel
          this.redraw();
        }
    },


Then in Panel.js redraw....

        this.div.innerHTML = "";
        if (this.active) {
            for (var i = 0; i < this.controls.length; i++) {
                var element = this.controls[i].panel_div;
                if (this.controls[i].active) {
                    element.className = this.controls[i].displayClass +
"ItemActive";
                } else {    
                    element.className = this.controls[i].displayClass +
"ItemInactive";
                }
                if (this.controls[i].hidden) {
                    element.style.display = "none";
                } else {
                    element.style.display = "inline";
                }
                this.div.appendChild(element);
            }
        }

Then when I define a navbar I do the following:

    var myNavBar = new OpenLayers.Control.NavToolbar();
    if (kindOfPage == 0) {
      myNavBar.hide("WayPoint");
    } else {
      myNavBar.show("WayPoint");
    }


map.addControl(myNavBar);




Linda_Rawson wrote:
> 
> I have a custom control in the NavToolBar and on certain circumstances I
> want to hide the control from the user. How do you do that? 
> 
> Thanks, 
> Linda Rawson 
> http://www.sensorytech.net
> 
> 

-- 
View this message in context: http://www.nabble.com/NavToolBar-hide-show-controls-tf4233551.html#a12058840
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list