all files / src/layers/ LayerRealEarthTile.ts

48.15% Statements 13/27
0% Branches 0/12
40% Functions 2/5
44% Lines 11/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                                                                                                                     
/**
 * Created by gavorhes on 11/4/2015.
 */
 
import {LayerBaseXyzTile} from './LayerBaseXyzTile';
import {LayerBaseOptions} from './LayerBase';
import RealEarthAnimateTile from '../mixin/RealEarthAnimateTile';
import provide from '../util/provide';
import {IRealEarthAnimate, timesLoadedCallback} from "../mixin/RealEarthAnimate";
const nm = provide('layers');
 
export interface LayerRealEarthTileOptions extends LayerBaseOptions {
    products: string;
    animate?: boolean;
    timeLoadCallback?: timesLoadedCallback;
}
 
 
/**
 * Real earth tile
 * @augments LayerBaseXyzTile
 */
export class LayerRealEarthTile extends LayerBaseXyzTile implements IRealEarthAnimate {
    _products: string;
    animator: RealEarthAnimateTile;
 
    /**
     * The base layer for all others
     * @param {object} options - config
     * @param {string} [options.id] - layer id
     * @param {string} [options.name=Unnamed Layer] - layer name
     * @param {number} [options.opacity=1] - opacity
     * @param {boolean} [options.visible=true] - default visible
     * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28
     * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28
     * @param {object} [options.params={}] the get parameters to include to retrieve the layer
     * @param {number} [options.zIndex=0] the z index for the layer
     * @param {function} [options.loadCallback] function to call on load, context this is the layer object
     * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed
     * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility
     * @param {boolean} [options.legendContent] additional content to add to the legend
     *
     * @param {string} options.products - the products to request
     * @param {boolean} [options.hasTimes=false] If the layer is time dependent, fixed set of dates
     * @param {boolean} [options.animate=false] if the layer should be animated
     */
    constructor(options: LayerRealEarthTileOptions) {
        options.animate = typeof options.animate == 'boolean' ? options.animate : false;
        if (options.animate) {
            super('', options);
            this._products = options.products;
            this.animator = new RealEarthAnimateTile(this, options.timeLoadCallback);
            this.animator.timeInit();
        } else {
            super(`http://realearth.ssec.wisc.edu/api/image?products=${options.products}&x={x}&y={y}&z={z}`, options);
            this._products = options.products;
        }
    }
 
    setLayerTime(theTime: number): boolean {
        if (this.animator) {
            return this.animator.setLayerTime(theTime);
        } else {
            return false;
        }
    }
 
    _load(): boolean {
        if (this.animator) {
            return false;
        }
        return super._load();
    }
}
 
nm.LayerRealEarthTile = LayerRealEarthTile;
export default LayerRealEarthTile;