ionic-coreo
Version:
Ionic2 module for integration with Coreo
62 lines • 2.16 kB
JavaScript
;
var core_1 = require('@angular/core');
var ionic_angular_1 = require('ionic-angular');
var config_1 = require('./config');
var CoreoGoogleMaps = (function () {
function CoreoGoogleMaps(platform, config) {
this.platform = platform;
this.config = config;
this.isLoadingMap = false;
this.win = platform.win();
this.doc = platform.doc();
}
CoreoGoogleMaps.prototype.initialise = function () {
var _this = this;
if (this.maps) {
return Promise.resolve(this.maps);
}
if (this.isLoadingMap) {
return Promise.resolve();
}
this.isLoadingMap = true;
return this
.loadGoogleMapsAPI(this.config.googleMapsKey)
.then(function () {
_this.maps = _this.win.google.maps;
return _this.maps;
})
.finally(function () { return _this.isLoadingMap = false; });
};
CoreoGoogleMaps.prototype.loadGoogleMapsAPI = function (key) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.win.__mapInitCallback__ = function () {
delete _this.win.__mapInitCallback__;
resolve();
};
var script = document.createElement("script");
script.async = true;
script.defer = true;
script.src = 'https://maps.google.com/maps/api/js?callback=__mapInitCallback__';
if (key) {
script.src += "&key=" + key;
}
script.addEventListener('error', function () {
delete _this.win.__mapInitCallback__;
reject();
});
_this.doc.body.appendChild(script);
});
};
CoreoGoogleMaps.decorators = [
{ type: core_1.Injectable },
];
/** @nocollapse */
CoreoGoogleMaps.ctorParameters = function () { return [
{ type: ionic_angular_1.Platform, },
{ type: config_1.CoreoConfig, },
]; };
return CoreoGoogleMaps;
}());
exports.CoreoGoogleMaps = CoreoGoogleMaps;
//# sourceMappingURL=google-map.js.map