3

Using OpenLayers 0.6.5, I want to be able to copy the attributions from one source, and set the same value for the attributions of another source. But I can't find any way to extract the attributions from a source. I'm testing with the simplest case - an OSM source.

var origSource = new ol.source.OSM();
console.log(origSource.attributions);

Just logs "Undefined".

I've tried a few other variations, such as origSource.get('attributions');, but I can't find any method that works. There does not appear to be any getAttributions() method either.

Is there any way to get this to work?

2
  • There is an undocumented getAttributions() method which returns a function, and calling the function getAttributions()() returns an array of attributions. Some sources (e.g. Bing) expect the function to have a frameState parameter, but most do not.
    – Mike
    Commented Jun 1, 2021 at 9:04
  • @Mike This deserves to be put into answer.
    – TomazicM
    Commented Jun 1, 2021 at 14:54

1 Answer 1

3

There is an undocumented getAttributions() method which returns a function, and calling the function getAttributions()() returns an array of attributions. Some sources (e.g. Bing) expect the function to have a frameState parameter, but most do not.

The function itself can also be used as an attribution https://openlayers.org/en/latest/apidoc/module-ol_source_Source.html#~AttributionLike for another source.

1
  • This works! Thanks for pointing this one out to me. Commented Jun 1, 2021 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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