From bd167b48d5b521fad135f40f8cff080a9e7ffa18 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 6 Mar 2018 07:39:47 +0900 Subject: [PATCH] #1189 --- src/web/app/common/mios.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index bf04588bc..da1d9746a 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -170,23 +170,13 @@ export default class MiOS extends EventEmitter { this.streams.messagingIndexStream = new MessagingIndexStreamManager(this.i); }); - //#region load google maps api - (window as any).initGoogleMaps = () => { - this.emit('init-google-maps'); - }; - const head = document.getElementsByTagName('head')[0]; - const script = document.createElement('script'); - script.setAttribute('src', `https://maps.googleapis.com/maps/api/js?key=${googleMapsApiKey}&callback=initGoogleMaps`); - script.setAttribute('async', 'true'); - script.setAttribute('defer', 'true'); - head.appendChild(script); - //#endregion - if (this.debug) { (window as any).os = this; } } + private googleMapsIniting = false; + public getGoogleMaps() { return new Promise((res, rej) => { if ((window as any).google && (window as any).google.maps) { @@ -195,6 +185,21 @@ export default class MiOS extends EventEmitter { this.once('init-google-maps', () => { res((window as any).google.maps); }); + + //#region load google maps api + if (!this.googleMapsIniting) { + this.googleMapsIniting = true; + (window as any).initGoogleMaps = () => { + this.emit('init-google-maps'); + }; + const head = document.getElementsByTagName('head')[0]; + const script = document.createElement('script'); + script.setAttribute('src', `https://maps.googleapis.com/maps/api/js?key=${googleMapsApiKey}&callback=initGoogleMaps`); + script.setAttribute('async', 'true'); + script.setAttribute('defer', 'true'); + head.appendChild(script); + } + //#endregion } }); }