* initAsync * Called after all core objects have been constructed. * @return {Promise} Promise resolved when this component has completed initialization
()
| 68 | * @return {Promise} Promise resolved when this component has completed initialization |
| 69 | */ |
| 70 | initAsync() { |
| 71 | if (this._initPromise) return this._initPromise; |
| 72 | |
| 73 | for (const id of this.dependencies) { |
| 74 | if (!this.context.systems[id]) { |
| 75 | return Promise.reject(`Cannot init: ${this.id} requires ${id}`); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | const context = this.context; |
| 80 | const editor = context.systems.editor; |
| 81 | const filters = context.systems.filters; |
| 82 | const gfx = context.systems.gfx; |
| 83 | const imagery = context.systems.imagery; |
| 84 | const l10n = context.systems.l10n; |
| 85 | const photos = context.systems.photos; |
| 86 | const rapid = context.systems.rapid; |
| 87 | const storage = context.systems.storage; |
| 88 | const styles = context.systems.styles; |
| 89 | const urlhash = context.systems.urlhash; |
| 90 | |
| 91 | // Note: We want MapSystem's hashchange listener registered as early as possible |
| 92 | // because so many other parts of Rapid rely on the map location being set correctly. |
| 93 | // Other systems should register their hashchange listener after MapSystem.initAsync. |
| 94 | urlhash.on('hashchange', this._hashchange); |
| 95 | |
| 96 | const prerequisites = Promise.all([ |
| 97 | gfx.initAsync(), |
| 98 | l10n.initAsync(), |
| 99 | storage.initAsync(), |
| 100 | ]); |
| 101 | |
| 102 | return this._initPromise = prerequisites |
| 103 | .then(() => { |
| 104 | this._currFillMode = storage.getItem('area-fill') || 'partial'; // the current fill mode |
| 105 | this._toggleFillMode = storage.getItem('area-fill-toggle') || 'partial'; // the previous *non-wireframe* fill mode |
| 106 | |
| 107 | // Scene will exist after gfx init |
| 108 | const scene = gfx.scene; |
| 109 | |
| 110 | // Setup Event Handlers.. |
| 111 | // Forward the 'move' and 'draw' events from the GraphicsSystem |
| 112 | gfx |
| 113 | .on('move', () => this.emit('move')) |
| 114 | .on('draw', () => { |
| 115 | this._updateHash(); |
| 116 | this.emit('draw', { full: true }); // pass {full: true} for legacy receivers |
| 117 | }); |
| 118 | |
| 119 | editor |
| 120 | .on('merge', entityIDs => { |
| 121 | if (entityIDs) { |
| 122 | scene.dirtyData('osm', entityIDs); |
| 123 | } |
| 124 | gfx.deferredRedraw(); |
| 125 | }) |
| 126 | .on('stagingchange', difference => { |
| 127 | // todo - maybe only do this if difference.didChange.geometry? |
nothing calls this directly
no test coverage detected