UNPKG

ng2-bingmaps

Version:
141 lines (139 loc) 5.98 kB
/** * ng2-bingmaps - Angular 2 components for Bing Maps * @version v0.2.0 * @link https://github.com/youjustgo/ng2-bingmaps * @license MIT */ "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var core_1 = require('@angular/core'); var maps_api_loader_1 = require('./maps-api-loader'); (function (ScriptProtocol) { ScriptProtocol[ScriptProtocol["HTTP"] = 0] = "HTTP"; ScriptProtocol[ScriptProtocol["HTTPS"] = 1] = "HTTPS"; ScriptProtocol[ScriptProtocol["AUTO"] = 2] = "AUTO"; })(exports.ScriptProtocol || (exports.ScriptProtocol = {})); var ScriptProtocol = exports.ScriptProtocol; var LazyMapsAPILoaderConfig = (function () { function LazyMapsAPILoaderConfig() { /** * The Bing Maps API Key (see: * https://developers.google.com/maps/documentation/javascript/get-api-key) */ this.apiKey = null; /** * The Google Maps client ID (for premium plans). * When you have a Google Maps APIs Premium Plan license, you must authenticate * your application with either an API key or a client ID. * The Google Maps API will fail to load if both a client ID and an API key are included. */ this.clientId = null; /** * The Google Maps channel name (for premium plans). * A channel parameter is an optional parameter that allows you to track usage under your client * ID by assigning a distinct channel to each of your applications. */ this.channel = null; /** * Google Maps API version. */ this.apiVersion = '3'; /** * Host and Path used for the `<script>` tag. */ this.hostAndPath = 'www.bing.com/api/maps/mapcontrol'; /** * Protocol used for the `<script>` tag. */ this.protocol = ScriptProtocol.HTTPS; /** * The branch to use: Release, Experimental, or Frozen. * Set to Experimental to use the newest features, or if it contains a bug fix you require. Otherwise leave blank or set to Release. */ this.branch = 'release'; } return LazyMapsAPILoaderConfig; }()); exports.LazyMapsAPILoaderConfig = LazyMapsAPILoaderConfig; var DEFAULT_CONFIGURATION = new LazyMapsAPILoaderConfig(); var LazyMapsAPILoader = (function (_super) { __extends(LazyMapsAPILoader, _super); function LazyMapsAPILoader(_config) { _super.call(this); this._config = _config; if (this._config === null || this._config === undefined) { this._config = DEFAULT_CONFIGURATION; } } LazyMapsAPILoader.prototype.load = function () { if (this._scriptLoadingPromise) { return this._scriptLoadingPromise; } var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true; script.defer = true; var callbackName = "angular2bingmaps" + new Date().getMilliseconds(); script.src = this._getScriptSrc(callbackName); this._scriptLoadingPromise = new Promise(function (resolve, reject) { window[callbackName] = function () { resolve(); }; script.onerror = function (error) { reject(error); }; }); document.body.appendChild(script); return this._scriptLoadingPromise; }; LazyMapsAPILoader.prototype._getScriptSrc = function (callbackName) { var protocolType = (this._config && this._config.protocol) || DEFAULT_CONFIGURATION.protocol; var protocol; switch (protocolType) { case ScriptProtocol.AUTO: protocol = ''; break; case ScriptProtocol.HTTP: protocol = 'http:'; break; case ScriptProtocol.HTTPS: protocol = 'https:'; break; } var hostAndPath = this._config.hostAndPath || DEFAULT_CONFIGURATION.hostAndPath; var branch = this._config.branch || DEFAULT_CONFIGURATION.branch; var queryParams = { callback: callbackName }; if (branch) { queryParams['branch'] = branch; } var params = Object.keys(queryParams) .map(function (k, i) { var param = (i === 0) ? '?' : '&'; return param += k + "=" + queryParams[k]; }) .join(''); return protocol + "//" + hostAndPath + params; }; LazyMapsAPILoader = __decorate([ core_1.Injectable(), __param(0, core_1.Optional()), __metadata('design:paramtypes', [LazyMapsAPILoaderConfig]) ], LazyMapsAPILoader); return LazyMapsAPILoader; }(maps_api_loader_1.MapsAPILoader)); exports.LazyMapsAPILoader = LazyMapsAPILoader; //# sourceMappingURL=lazy-maps-api-loader.js.map