all files / src/mixin/ RealEarthAnimateTile.ts

43.33% Statements 13/30
0% Branches 0/8
16.67% Functions 1/6
41.38% Lines 12/29
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                                                                                                         
/**
 * Created by gavorhes on 12/4/2015.
 */
import RealEarthAnimate from './RealEarthAnimate';
import provide from '../util/provide';
import ol = require('custom-ol');
import LayerRealEarthTile from "../layers/LayerRealEarthTile";
const nm = provide('mixin');
 
/**
 * Animate real earth tile
 * @augments RealEarthAnimate
 */
class RealEarthAnimateTile extends RealEarthAnimate {
    _sourceUrls: string[];
    _source: ol.source.XYZ;
    _olLayer: ol.layer.Tile;
 
    constructor(layer: LayerRealEarthTile, loadCallback?: (lyr: LayerRealEarthTile) => void){
        super(layer, loadCallback);
        this._source = layer.source;
        this._olLayer = layer.olLayer;
    }
 
 
 
    timeInit() {
        super.timeInit();
        this._sourceUrls = [];
    }
 
    _loadDates(inString: string): string {
        let rawDte = super._loadDates(inString);
        let dteProductUrl =
            `http://realearth.ssec.wisc.edu/api/image?products=${this._products}_${rawDte}&x={x}&y={y}&z={z}`;
        this._sourceUrls.push(dteProductUrl);
        return '';
    }
 
    /**
     * @protected
     */
    _loadLatest(): boolean {
        if (super._loadLatest()){
            this._source.setUrl(this._sourceUrls[this._sourceUrls.length - 1]);
        }
        return true;
    }
 
    setLayerTime(theTime: number): boolean {
        if (super.setLayerTime(theTime)) {
            if (this._olLayer.getZIndex() < 0){
                this._olLayer.setZIndex(0);
            }
            this._source.setUrl(this._sourceUrls[this._currentIndex]);
        } else {
            this._olLayer.setZIndex(-1);
        }
        return true;
    }
}
 
nm.RealEarthAnimateTile = RealEarthAnimateTile;
export default RealEarthAnimateTile;