* startAsync * Called after all core objects have been initialized. * @return {Promise} Promise resolved when this component has completed startup
()
| 90 | * @return {Promise} Promise resolved when this component has completed startup |
| 91 | */ |
| 92 | startAsync() { |
| 93 | if (this._startPromise) return this._startPromise; |
| 94 | |
| 95 | const context = this.context; |
| 96 | const gfx = context.systems.gfx; |
| 97 | const ui = context.systems.ui; |
| 98 | |
| 99 | const prerequisites = Promise.all([ |
| 100 | ui.startAsync(), // wait for UI to be started, so the container will exist |
| 101 | this._loadMapLibreAsync() |
| 102 | ]); |
| 103 | |
| 104 | return this._startPromise = prerequisites |
| 105 | .then(() => { |
| 106 | const maplibregl = window.maplibregl; |
| 107 | if (!maplibregl) throw new Error('maplibre-gl not loaded'); |
| 108 | |
| 109 | const maplibre = this.maplibre = new maplibregl.Map({ |
| 110 | container: this.containerID, |
| 111 | minZoom: 12, |
| 112 | pitch: 60, |
| 113 | scrollZoom: { around: 'center' }, |
| 114 | style: { |
| 115 | version: 8, |
| 116 | sources: {}, |
| 117 | layers: [{ |
| 118 | id: 'background-layer', |
| 119 | type: 'background', |
| 120 | layout: { 'visibility': 'visible' }, |
| 121 | paint: { 'background-color': 'white' } |
| 122 | }] |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | // Setup event handlers.. |
| 127 | gfx.on('draw', this.deferredRedraw); // respond to changes in the main map |
| 128 | gfx.on('move', this.deferredRedraw); |
| 129 | maplibre.on('move', this._map3dmoved); // respond to changes in the 3d map |
| 130 | maplibre.on('moveend', this._map3dmoved); |
| 131 | |
| 132 | // Add zoom and rotation controls to the map. |
| 133 | const navOptions = { showCompass: true, showZoom: true, visualizePitch: false }; |
| 134 | maplibre.addControl(new maplibregl.NavigationControl(navOptions)); |
| 135 | |
| 136 | return new Promise(resolve => { |
| 137 | maplibre.on('load', () => { |
| 138 | maplibre.setLight({ |
| 139 | anchor: 'viewport', |
| 140 | color: '#ff00ff', |
| 141 | position: [1, 200, 30], |
| 142 | intensity: 0.3, |
| 143 | }); |
| 144 | |
| 145 | // Setup Sources.. Empty for now, we will fill them in later |
| 146 | const EMPTY = { type: 'FeatureCollection', features: [] }; |
| 147 | maplibre.addSource('osmareas', { type: 'geojson', data: EMPTY }); |
| 148 | maplibre.addSource('osmroads', { type: 'geojson', data: EMPTY }); |
| 149 | maplibre.addSource('osmbuildings', {type: 'geojson', data: EMPTY }); |
no test coverage detected