* initAsync * Called after all core objects have been constructed. * @return {Promise} Promise resolved when this component has completed initialization
()
| 54 | * @return {Promise} Promise resolved when this component has completed initialization |
| 55 | */ |
| 56 | initAsync() { |
| 57 | if (this._initPromise) return this._initPromise; |
| 58 | |
| 59 | for (const id of this.dependencies) { |
| 60 | if (!this.context.systems[id]) { |
| 61 | return Promise.reject(`Cannot init: ${this.id} requires ${id}`); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | const context = this.context; |
| 66 | const gfx = context.systems.gfx; |
| 67 | const map = context.systems.map; |
| 68 | const urlhash = context.systems.urlhash; |
| 69 | |
| 70 | const prerequisites = Promise.all([ |
| 71 | gfx.initAsync(), // `gfx.scene` will exist after `initAsync` |
| 72 | map.initAsync(), // `PhotoSystem` should listen for 'hashchange' after `MapSystem` |
| 73 | urlhash.initAsync() |
| 74 | ]); |
| 75 | |
| 76 | return this._initPromise = prerequisites |
| 77 | .then(() => { |
| 78 | // Setup event handlers.. |
| 79 | urlhash.on('hashchange', this._hashchange); |
| 80 | gfx.scene.on('layerchange', this._layerchange); |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | /** |