()
| 23 | } |
| 24 | |
| 25 | load() { |
| 26 | if (this._window.AMap) { |
| 27 | return Promise.resolve(); |
| 28 | } |
| 29 | |
| 30 | if (this._scriptLoadingPromise) return this._scriptLoadingPromise; |
| 31 | const script = this._document.createElement('script'); |
| 32 | script.type = 'text/javascript'; |
| 33 | script.async = true; |
| 34 | script.defer = true; |
| 35 | script.src = this._getScriptSrc(); |
| 36 | |
| 37 | this._scriptLoadingPromise = new Promise((resolve, reject) => { |
| 38 | this._window['amapInitComponent'] = () => { |
| 39 | this._queueEvents.forEach(event => event()); |
| 40 | while (this._queueEvents.length) { |
| 41 | this._queueEvents.pop().apply(); |
| 42 | } |
| 43 | return resolve(); |
| 44 | }; |
| 45 | script.onerror = error => reject(error); |
| 46 | }); |
| 47 | this._document.head.appendChild(script); |
| 48 | return this._scriptLoadingPromise; |
| 49 | } |
| 50 | |
| 51 | _getScriptSrc() { |
| 52 | // amap plugin prefix reg |
no test coverage detected