2

I'm fairly new to OpenLayers, and have written a little function to switch the legend image for WMS layers on and off if the layer is visible or not. This is all much neater if I can define my own custom property for the WMS layer object, e.g legendurl: 'http//....'

While this works, I'm wondering if it is ok/advisable to create custom properties on the fly in this way?

2

I believe what you want to do is add your custom properties to the WMS options. It is certainly OK to do this. You can do it directly in the the second set of braces when defining the layer or use something like this after the layer definition.

mylayer.addOptions({myoption: option value});

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.