Mapbox – Updating Source Property ‘Attribution’ in Mapbox GL

mapboxmapbox-gl

I am using mapbox gl library. First layer is getting added then under that layer source is getting added. like below shown :

sourceObj = {
      type: 'raster',
      tiles: tileUrls,
      attribution : "Copyright"
      scheme,
      style,
      styles,
    };
map.addSource(`${this.asset.uuid}-data`, source);
const layer = {
        id: `${this.asset.uuid}-label`,
        type: 'raster',
        source: `${this.asset.uuid}-data`,
        minzoom: 0,
        maxzoom: 22,
      };
      map.addLayer(layer, this.asset.uuid);

We are loading bing tiles under tileUrl. Tiles are working fine.
Now I have to update this attribution based on zoom level. Am using map zoom start and end event to update but how to update not getting.
setData only work with type Point and GeoJson not with Raster or vector.
I tried all documentation of mapbox but no luck.

Best Answer

After so many tried found this hacky solution. Using https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol property.

source.attribution = 'Text to be update';
map._controls[0]._updateAttributions(); // 

This can be iterate through _controls and get right customAttribution instance. I have use hack way.