mapbox / mapbox/mapbox-gl-js

Tile Layer progress bar / get amount of tiles loaded

Open
#12,066 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

There is a plugin for Leaflet called [leaflet-tile-loading-progress-control](https://github.com/jbccollins/leaflet-tile-loading-progress-control), and it does exactly what the title suggests. When a Tile Layer with `{z} {x} {y}` are loaded, or a `WMS` tile layer is loaded, a progress bar will show up on the map indicating the percentage of tiles loaded.

My question is if there is a similar functionality in GL JS, or if not directly, how I could implement this.

Ideally there would be a way to get the total amount of tiles that the browser will request, and this would probably fire after a `moveend` or a `zoomend` event, as that is when the tiles are "reloaded," or rather, new ones are fetched. You would then also have to know how many tiles the browser had already loaded, and then just do `tilesAlreadyLoaded / numberOfTotalTiles` to get your decimal percentage.

If this is not possible, is there a way to ONLY get the amount of tiles the browser has loaded? This could also show the user that the map is actually loading tiles, as all I have right now is showing a spinner on the `dataloading` event, and hiding it on `idle`:
```javascript
map.on('dataloading', () => {
toggleSpinner(true);
});
map.on('idle', () => {
toggleSpinner(false);
});
```

Here are the tile layers that I would be using this functionality with:
```javascript
// WMS layer
map.addLayer({
'id': `wms-test-layer`,
'type': 'raster',
'source': {
'type': 'raster',
'tiles': [
`https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0q.cgi?service=WMS&request=GetMap&layers=nexrad-n0q-900913&styles=&format=image%2Fpng&transparent=true&version=1.1.1&width=256&height=256&srs=EPSG:3857&bbox={bbox-epsg-3857}`
],
'tileSize': 256
},
'paint': {
'raster-opacity': opacity,
"raster-fade-duration": 0
}
});

// Tile layer
map.addLayer({
id: 'rpv',
type: "raster",
source: {
type: "raster",
tiles: [
`https://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/ridge::LWX-N0B-0/{z}/{x}/{y}.png`
],
tileSize: 256
},
});
```

Any ideas on how to do this would be awesome, because I don't think there is a way to do it with the information the documentation provides.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing dataloading and idle events, along with the moveend and zoomend events mentioned in the issue, for raster and WMS sources. Determine whether GL JS can expose total and loaded tile counts, or whether the limitation should be documented; done means a clear supported approach or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.