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

Method _getSourceAsync

modules/services/VectorTileService.js:191–228  ·  view source on GitHub ↗

* _getSourceAsync * Create a new cache to hold data for the given template * @param {string} template - A url template for fetching data (e.g. a z/x/y tileserver or .pmtiles) * @return Promise resolved to the source object once it is ready to use

(template)

Source from the content-addressed store, hash-verified

189 * @return Promise resolved to the source object once it is ready to use
190 */
191 _getSourceAsync(template) {
192 if (!template) return Promise.reject(new Error('No template'));
193
194 let source = this._sources.get(template);
195
196 if (!source) { // create it
197 const url = new URL(template);
198 const hostname = url.hostname;
199 const filename = url.pathname.split('/').at(-1);
200
201 source = {
202 id: utilHashcode(template).toString(),
203 displayName: hostname,
204 template: template,
205 inflight: new Map(), // Map(tileID -> AbortController)
206 loaded: new Map(), // Map(tileID -> Tile)
207 zoomCache: new Map(), // Map(zoom -> Object zoomCache)
208 lastv: null // viewport version last time we fetched data
209 };
210
211 this._sources.set(template, source);
212
213 // Special handling for PMTiles sources
214 // Create a PMTiles instance and fetch the header so we know more about the source.
215 if (filename && /\.pmtiles$/.test(filename)) {
216 source.displayName = filename;
217 source.pmtiles = new PMTiles(template);
218 source.readyPromise = source.pmtiles.getHeader()
219 .then(header => source.header = header)
220 .then(() => Promise.resolve(source));
221
222 } else {
223 source.readyPromise = Promise.resolve(source);
224 }
225 }
226
227 return source.readyPromise;
228 }
229
230
231 /**

Callers 1

loadTilesMethod · 0.95

Calls 2

getMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected