Search code examples
openlayers

Openlayers 4.6.4, Can't get BingMap attributions using source.getAttributions()


We use BingMap in our application and call the source.getAttributions() to print the bing attributions on the pdf. After upgrading to OL4.6.4, source.getattributions() return null. Post https://github.com/openlayers/openlayers/pull/7329 explains why getattributions() for bing map is returning null.

Is there any workaround to get the Bing attriibutions in the code ?


Solution

  • This will work again in v5.0, but what you get from getAttributions() will be a function which you call with the FrameState. Something like

    var getAttribution = bingSource().getAttributions();
    var attribution = getAttribution({
      extent: map.getView().calculateExtent(),
      viewState: map.getView().getState()
    });
    

    Or even easier in a listener for the map's 'postcompose' or 'postrender' event:

    var getAttribution = bingSource().getAttributions();
    map.on('postcompose', function(e) {
      var attribution = getAttribution(e.frameState);
    });