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

Method _loadTileAsync

modules/services/VectorTileService.js:265–307  ·  view source on GitHub ↗

* _loadTileAsync * @param source * @param tile * @return {Promise} returns the fetch promise

(source, tile)

Source from the content-addressed store, hash-verified

263 * @return {Promise} returns the fetch promise
264 */
265 _loadTileAsync(source, tile) {
266 const tileID = tile.id;
267 if (source.loaded.has(tileID) || source.inflight.has(tileID)) return;
268
269 const controller = new AbortController();
270 source.inflight.set(tileID, controller);
271
272 const [x, y, z] = tile.xyz;
273 let _fetch;
274
275 if (source.pmtiles) {
276 _fetch = source.pmtiles
277 .getZxy(z, x, y, controller.signal)
278 .then(response => response?.data);
279
280 } else {
281 const url = source.template
282 .replace('{x}', x)
283 .replace('{y}', y)
284 .replace(/\{[t-]y\}/, Math.pow(2, z) - y - 1) // TMS-flipped y coordinate
285 .replace(/\{z(oom)?\}/, z)
286 .replace(/\{switch:([^}]+)\}/, function(s, r) {
287 const subdomains = r.split(',');
288 return subdomains[(x + y) % subdomains.length];
289 });
290
291 _fetch = fetch(url, { signal: controller.signal })
292 .then(utilFetchResponse);
293 }
294
295 return _fetch
296 .then(buffer => {
297 source.loaded.set(tileID, tile);
298 this._parseTileBuffer(source, tile, buffer);
299 })
300 .catch(err => {
301 if (err.name === 'AbortError') return; // ok
302 if (err instanceof Error) console.error(err); // eslint-disable-line no-console
303 })
304 .finally(() => {
305 source.inflight.delete(tileID);
306 });
307 }
308
309
310 /**

Callers 1

loadTilesMethod · 0.95

Calls 4

_parseTileBufferMethod · 0.95
replaceMethod · 0.80
splitMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected