Source: map/layer/TileLayer/TileLayer.js

import { Layer } from "../Layer/Layer.js";
import { TileLayerSchema } from "./TileLayer.schema.js";
import { TileLayerProxy } from "./TileLayer.proxy.js";
import { TileLayerProxyLeaflet } from "./TileLayer.proxy.leaflet.js";

export { TileLayer }

/**
 * WMS Layer Implementation
 * 
 * @author rhess <robin.hess@awi.de>
 * @author sjaswal <shahzeib.jaswal@awi.de>
 * @memberof vef.map.layer
 */
class TileLayer extends Layer {

    /**
     * Set all properties for the layer based on the options object.
     * 
     * @param {object} config 
     * @param {object} cache 
     * @param {string} id 
     */
    constructor(config, cache, id) {
        // calling parent constructor
        super(config, cache, id);

        // init default values and define getters and setters
        this.setSchema_(TileLayerSchema.getSchema());

        // internal properties
        this.zIndex_ = 0;

        this.activeLayer_ = new TileLayerProxy();

        // framework specific map implementations
        this.layerProxies_.leaflet = TileLayerProxyLeaflet;
    }

    /**
     * create a map layer based on the service options
     * 
     * @param {string} type e.g. "leaflet"
     * @private
     */
    createMapLayer_(type, options) {
        return super.createMapLayer_(type, {
            url: this.url,
            attribution: this.attribution
        });
    }

    /**
     * Helper method to update the mapLayer according to
     * the current state. Might be necessary after switching the map type
     * 
     * @private
     */
    updateMapLayer_(type) {
        // call setters to apply options to the active mapLayer
        if (Number.isFinite(this.opacity)) this.setOpacity(this.opacity);
        if (Number.isFinite(this.zIndex_)) this.setZIndex(this.zIndex_);
        this.setProjection(this.crs_);

        // reload was intentionally prevented in the setters to call it in the end
        this.reload();
    }

    /**
     * Set the z-index of a layer
     * @param {number} index 
     */
    setZIndex(index) {
        this.zIndex_ = index;
        this.activeLayer_.setZIndex(index);
    }

    /**
     * Get the bounding box as an object
     * 
     * @returns {object} { min: {x, y}, max: {x, y}, crs: "CRS:84" }
     */
    getBounds() {
        return {
            min: { y: -85, x: -180 },
            max: { y: 85, x: 180 },
            crs: "CRS:84"
        }
    }

}