This commit is contained in:
syuilo 2018-03-06 07:39:47 +09:00
parent decde7497f
commit bd167b48d5
1 changed files with 17 additions and 12 deletions

View File

@ -170,23 +170,13 @@ export default class MiOS extends EventEmitter {
this.streams.messagingIndexStream = new MessagingIndexStreamManager(this.i); 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) { if (this.debug) {
(window as any).os = this; (window as any).os = this;
} }
} }
private googleMapsIniting = false;
public getGoogleMaps() { public getGoogleMaps() {
return new Promise((res, rej) => { return new Promise((res, rej) => {
if ((window as any).google && (window as any).google.maps) { 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', () => { this.once('init-google-maps', () => {
res((window as any).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
} }
}); });
} }