Skip to main content
Known Participant
July 22, 2019
Pregunta

JavaScript Help

  • July 22, 2019
  • 11 respuestas
  • 1014 visualizaciones

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.

Este tema ha sido cerrado para respuestas.

11 respuestas

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