Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a added Graticule control in my OpenLayers map. Now I want to toggle this using a control button. This what I have written:

function init() { 
      graticuleCtl = new OpenLayers.Control.Graticule({
                    numPoints: 2, 
                    labelled: true,
                    displayInLayerSwitcher: true
      });

    map = new OpenLayers.Map('map', {controls: []});
    map.addControl(graticuleCtl);
.
.
.
      var GraticuleCtl = new OpenLayers.Control.Button({
            displayClass: "olGraticule",
            title: "Show Graticule",
            trigger: showGraticule});

        // Panel (toolbar)
        Panel = new OpenLayers.Control.Panel({
            defaultControl: DragPanCtrl
        });
        Panel.addControls([
            .
            .
            .
            .
            GraticuleCtl
        ]);
        map.addControl(Panel);
}

function showGraticule() {
   if (graticuleCtl.visible==true){  
       graticuleCtl.deactivate();
       return true;
       }   
   else if (graticuleCtl.visible==false){
       graticuleCtl.activate();
       return true;
       }
   else{}
}

But this works for once only, since the 'visible' property checks only for initial map load.

share|improve this question

1 Answer 1

visible is a parameter to the control. You should however be checking the active attribute to see if the control is on or not, and then you can toggle your control with something else (link/button/etc). API here.

share|improve this answer
    
Thank you for your kind reply. I have done it. –  Arunava Dey Aug 8 '11 at 5:00
    
Glad to hear it worked. Please accept my answer to close out the question as "answered". –  Vadim Aug 8 '11 at 15:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.