How to abort a fetch request when it is made using load method of loaders.gl

11 views Asked by At

When using deck.gl's TileLayer getTileData, if you want to abort the request for a tile that is not in the current viewport, how can it be done ?

1

There are 1 answers

0
Sairam Gourishetty On

load(loaders.gl)

fetch

If you are using deckgl's TileLayer, In getTileData, you can pass the second parameter to load as { fetch: { signal: tile.signal } } where tile is the parameter from getTileData

Here is the complete code

getTileData: (tile: any) => {
  const {
    west, south, east, north
  } = tile.bbox;

  if (tile.signal.aborted) {
    return null;
  }
  
  return load(`${tile.url}${south},${west},${north},${east}`, { fetch: { signal: tile.signal } });
},

Hence if the tile is not in the viewport, then it will be cancelled automatically.