Skip to main content
Known Participant
July 22, 2019
質問

JavaScript Help

  • July 22, 2019
  • 返信数 1.
  • 1010 ビュー

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.

このトピックへの返信は締め切られました。

返信数 1

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");