Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: []});
      var GraticuleCtl = new OpenLayers.Control.Button({
            displayClass: "olGraticule",
            title: "Show Graticule",
            trigger: showGraticule});

        // Panel (toolbar)
        Panel = new OpenLayers.Control.Panel({
            defaultControl: DragPanCtrl

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

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

share|improve this question

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


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.