all files / src/layers/ LayerRealEarthVector.ts

46.43% Statements 13/28
0% Branches 0/12
40% Functions 2/5
42.31% Lines 11/26
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 79 80 81 82 83 84 85 86 87 88 89 90                                                                                                                                                             
/**
 * Created by gavorhes on 11/13/2015.
 */
 
import {LayerBaseVectorGeoJson, LayerBaseVectorGeoJsonOptions} from './LayerBaseVectorGeoJson';
import RealEarthAnimateVector from '../mixin/RealEarthAnimateVector';
import provide from '../util/provide';
import {IRealEarthAnimate, timesLoadedCallback} from "../mixin/RealEarthAnimate";
 
const nm = provide('layers');
 
export interface LayerVectorRealEarthOptions extends LayerBaseVectorGeoJsonOptions {
    products: string;
    animate?: boolean;
    timeLoadCallback?: timesLoadedCallback;
}
 
 
/**
 * Vector real earth vector
 * @augments LayerBaseVectorGeoJson
 */
export class LayerVectorRealEarth extends LayerBaseVectorGeoJson implements IRealEarthAnimate {
    _products: string;
    animator: RealEarthAnimateVector;
 
    /**
     * Real Earth vector layer
     * @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 {boolean} [options.autoLoad=false] if the layer should auto load if not visible
     * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined
     * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move
     * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called
     * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages
     *
     * @param {object} [options.transform={}] SR transform, set as false for no transform
     * @param {string} options.transform.dataProjection=EPSG:4326 the _data CRS
     * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS
     *
     * @param {string} options.products real earth products identifier
     * @param {boolean} [options.animate=false] if the layer should be animated
     */
    constructor(options: LayerVectorRealEarthOptions) {
        options.animate = typeof options.animate == 'boolean' ? options.animate : false;
        if (options.animate) {
            options.autoLoad = false;
            super('', options);
            this._products = options.products;
            this.animator = new RealEarthAnimateVector(this, options.timeLoadCallback);
            this.animator.timeInit();
        } else {
            options.params = {products: options.products};
            super('http://realearth.ssec.wisc.edu/api/shapes', options);
        }
    }
 
    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.LayerVectorRealEarth = LayerVectorRealEarth;
export default LayerVectorRealEarth;