Source: map/tools/Attribution.js

import { UiElement } from '../../ui/UiElement.js';
import "./Attribution.css";

/**
 * Represents a simple map attribution tool.
 * @memberof vef.map.tools
 * @extends UiElement
 */
class Attribution extends UiElement {

    /**
     * Creates an instance of the Attribution tool.
     * @constructor
     * @param {Map} map - The map instance.
     * @param {string} [position="bottom-right"] - The position of the attribution element on the map.
     */
    constructor(map, position) {
        super();

        this.map = map;
        this.position = position || "bottom-right";

        this.update();

        this.map.addTool(this, this.position);
        this.map.on("baselayer_change", () => this.update());
    }

    /**
     * Updates the attribution element with the current base layer's attribution.
     */
    update() {
        const element = this.getElement();
        element.classList.add("vef-map-attribution");
        element.innerHTML = (this.map.baseLayer_ && this.map.baseLayer_.attribution) ? this.map.baseLayer_.attribution : "";
    }
}

export { Attribution };