Hello, I have a minor problem with selecting layers using a variable because the variable is always interpreted as a string when i'm trying to refer to the name of a layer object.
Everytime I use the string to try and select a layer's property it returns undefined. Can anyone help me out with selecting variable layer properties?
In this case filterName.x would be undefined.
The problem is that your filterName is just a string. As such, it cannot be used to reference a layer. It's the same in simpler cases: If you write "ten = 10", and then later on: "myTen = 'ten'", it will *not* be the case that the value of myTen is 10, and you won't be able to use myTen to access the value of ten. So what you need is a variable that references the layer itself, rather than just mimicking its name. Couldn't you pass the layer you need to your filterHighlighter function?
Try passing the entire layer instead of just the index, or pushing the filters into an array and using the index to pull from that.
I currently have the layers defined globally, if I defined them within a function is there some kind of onLoad event that allows me to have them ready as soon as the browser loads?
The idea would be to define the layers wherever it works best, but use the layer as an argument for your function filterHighlighter, i.e., it would be filterHighlighter = (layer) -> ..., rather than filterHighlighter = (index) -> ...
Yep, that looks good. The layers I'm dealing with should appear from the second the browser loads though so should I have an initiating method that allows me to pass parameters? If so, how do I make make a method trigger from the moment the browser loads?
[P.S. Thanks so much for all the help.]
Hey Struan, to get something like onLoad, you could write Utils.domComplete -> theStuffThatsSupposedToHappen. I am not sure I understand the connection with your filterHighlighter, but I hope it helps :-)
Now you mention it, I think I need to do some restructuring. Talking this through has really helped clarify things in my head though. Thank you! I'll start passing objects around in no time :)