Help! How to allow a user to toggle a layer ON/OFF

Hello! I hope someone can help me with this. I have created an interaction (see attached) where I want users to press a button that makes a layer visible - I was able to do that. Now I would like the user to click the same button to make the same layer invisible. Basically, I am looking to create an ON/OFF button. Is it possible to create this?

(I know I could create a second button that could say HIDE, and put a trigger on that to hide the layer), but that does not have the simplicity of the ON/OFF button. 

I would appreciate anyone who could help me with this. 

5 Replies
Teresa Vanderpost

Hi Michael, are you just wanting to not have the other layers images appear on top?  If yes, here is an example. I just went into the properties of each layer and selected hide other layers, this way when they click on each button they only see the one image from that layer.  Not sure if that is what you were looking for.

Russell Killips

Hello Michael,

To create an on/off button, you will need to use variables. I use True/False variables for this.

Create a True/False variable for your button with a default value of false.

Then you need 3 triggers for when clicking your button.

1. Show your layer if the variable = False

2. Hide your layer if the variable  = True

3. Toggle your variable
(If the variable = False it will become True,
If the variable  = True it will become False)

I did the first two buttons for you.

Teresa Vanderpost

The other thing you may want to do is have a selected state so the user knows which button they have clicked on.  I added it here, but you may want to use the trigger option Russell has provided.  In this version, i added a selected state (you would want to change the colour I used as it is not good with your font colour), and then I clicked on all buttons and did a right click to create a button set.  This way when they click around they can still see they visited them but when they are on the active one (selected) they can tell by the different colour of the button.