[GIS] How to Change Attribution Parameter of WMS Layer Dynamically in Openlayers

openlayers-2

This might be a noob question. I have a wms layer in OpenLayers 2.13.1 with attribution: "some_text" set when it's added. This is working fine, the attribution shows up fine in the map div.

My question is how to change the content of the attribution param when the layer is already added. So far I have tried myWMS_layer.mergeNewParams({attribution: "some_updated_text"}); but no luck. I've also find updateAttribution function in OpenLayers docs, but don't really know how to use it. I've tried myAttributionControl.updateAttribution(); and nothing happened.

Thanks in advance!

Best Answer

Finally I found the trick. When an attribution control is created, OL actually creates a DOM element with class name .olControlAttribution.

So with simple jquery, we can update the content with: $(".olControlAttribution").html("some_updated_text"); Nice thing is, since it's DOM element, we can put any html tag inside it; including <img> which is pretty useful for showing map legend.

Anyway, I'm open for any other more proper ways to do this. Cheers!