// tslint:disable:typedef
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/Rx';
window['mapsApi$'] = new BehaviorSubject({ ready: false });
window['mapsApiReady'] = function () {
    window['mapsApi$'].next({ ready: true });
    window['mapsApi$'].complete();
};
var GoogleMapService = (function () {
    function GoogleMapService() {
        var _this = this;
        this.apiKey = null;
        this.apiReady = false;
        this.loadingApi = false;
        this.mapsApi$ = window['mapsApi$'];
        this.mapsApi$.subscribe(function (gMapApi) {
            if (gMapApi != null) {
                _this.apiReady = true;
            }
        });
    }
    GoogleMapService.prototype.loadApi = function () {
        if (!this.loadingApi) {
            this.loadingApi = true;
            var url = void 0;
            if (this.apiKey) {
                url = "https://maps.googleapis.com/maps/api/js?key=" + this
                    .apiKey + "&callback=mapsApiReady";
            }
            else {
                url = "https://maps.googleapis.com/maps/api/js?callback=mapsApiReady";
            }
            this.addScript(url);
        }
    };
    GoogleMapService.prototype.addScript = function (url, callback) {
        var script = document.createElement('script');
        if (callback) {
            script.onload = callback;
        }
        script.type = 'text/javascript';
        script.src = url;
        document.body.appendChild(script);
    };
    return GoogleMapService;
}());
export { GoogleMapService };
GoogleMapService.decorators = [
    { type: Injectable },
];
/** @nocollapse */
GoogleMapService.ctorParameters = function () { return []; };
//# sourceMappingURL=GoogleMapService.js.map