MCPcopy Create free account
hub / github.com/facebook/Rapid / startAsync

Method startAsync

modules/core/Map3dSystem.js:92–168  ·  view source on GitHub ↗

* startAsync * Called after all core objects have been initialized. * @return {Promise} Promise resolved when this component has completed startup

()

Source from the content-addressed store, hash-verified

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 });

Callers 1

visibleMethod · 0.95

Calls 10

_loadMapLibreAsyncMethod · 0.95
_getAreaLayerMethod · 0.95
_getRoadSelectedLayerMethod · 0.95
_getRoadCasingLayerMethod · 0.95
_getRoadStrokeLayerMethod · 0.95
_getBuildingLayerMethod · 0.95
redrawMethod · 0.95
errorMethod · 0.80
resolveFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected