all files / src/olHelpers/ mapInteractionBase.ts

59.26% Statements 16/27
0% Branches 0/4
28.57% Functions 2/7
57.69% Lines 15/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                                                                                                                               
/**
 * Created by gavorhes on 12/8/2015.
 */
import provide from '../util/provide';
import ol = require('custom-ol');
const nm = provide('olHelpers');
 
 
 
/**
 * base interaction
 */
export class MapInteractionBase {
    _map: ol.Map;
    _initialized: boolean;
    _subtype: string;
 
    /**
     * map interaction base
     * @param subtype - the interaction subtype
     */
    constructor(subtype: string) {
        this._map = null;
        this._initialized = false;
        this._subtype = subtype;
    }
 
    /**
     * base initializer, returns true for already initialized
     * @param theMap - the ol Map
     * @returns true for already initialized
     */
    init(theMap: ol.Map){
        if (!this._initialized){
            this._map = theMap;
            this._initialized = true;
        }
    }
 
    /**
     * get reference to the ol map object
     * @returns {ol.Map} the map object
     */
    get map() {
        return this._map;
    }
 
    /**
     * get if is initialized
     * @returns {boolean} is initialized
     */
    get initialized() {
        return this._initialized;
    }
 
    /**
     * Check the initialization status and throw exception if not valid yet
     * @protected
     */
    _checkInit() {
        if (!this.initialized) {
            let msg = `${this._subtype} object not initialized`;
            alert(msg);
            console.log(msg);
            throw msg;
        }
    }
 
    /**
     * Check the initialization status and throw exception if not valid yet
     */
    checkInit(){
        this._checkInit();
    }
}
 
nm.MapInteractionBase = MapInteractionBase;
export default MapInteractionBase;