I have this JSFiddle example that has two vector layers in it, 'Cities Layer 1' and 'Cities Layer 2'. As you can see from this example, cities layer 1 has a visibility set as the default of true and cities layer 2 has the visibility changed to false so it doesn't bring it in on load. This all works fine.

However, my question is that on load, I would like my glyphicon to be unchecked to show the user that the layer hasn't loaded. I'm guessing I could add some form of 'if' to the visible parameter of the layer in the last section of the JavaScript section?


When you're building the layer tree you need to check the layer.getVisible() value and assign the correct eye icon. See the example below:


Alternatively, you could use something like knockout or angular to support the binding.

Further to your comment, in order to persist the eye icon state recursively, you would need to apply an each() function, noting the state of the parent layer node:


There's probably room for improvement, but that should get you started.

  • Thanks @nagytech , for my reference how does + (layer.getVisible() ? 'open' : 'close') + then understand if visible is true/ false? – Joshua Dickerson Jun 26 '15 at 8:43
  • Read the API Docs and can now see you are querying the visibility parameters. – Joshua Dickerson Jun 26 '15 at 9:37
  • I'm looking at updating this example as per this question, any ideas? – Joshua Dickerson Aug 11 '15 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.