Skip to main content
Known Participant
July 22, 2019
Question

JavaScript Help

  • July 22, 2019
  • 1 reply
  • 977 views

Hi there, Could someone help me correctly write a javascript. What i want to do is get the layers to switch between themselves when another layer is toggled on. So when toggling through the layers they don't all stay on but rather switch between them.

This is the script I have so far,

var docOCGs = this.getOCGs();

for (var x=0; x < docOCGs.length; x++)

{

          if(docOCGs.name == "Layer 1" ||

     docOCGs.name == "Layer 1")

          {

                    docOCGs.state = !docOCGs.state;

          }

}

Thank you.

This topic has been closed for replies.

1 reply

BarlaeDC
Community Expert
Community Expert
July 22, 2019

Hi,

I have not been able to test this, but could you not do something like.

var docOCGs = this.getOCGs();

for (var x=0; x < docOCGs.length; x++)

{

     // make then all hidden

     docOCGs.state =false;

     if (docOCGs.name == "LayerNameWeAreLookingFor") {

          docOCGs.state = true;

     }

}

Hope this helps

try67
Community Expert
Community Expert
July 22, 2019

This should work, but you can improve and simplify the code a bit by replacing these lines:

     docOCGs.state =false;

     if (docOCGs.name == "LayerNameWeAreLookingFor") {

          docOCGs.state = true;

     }

With just:

docOCGs.state = (docOCGs.name == "LayerNameWeAreLookingFor");