Skip to content

Commit 2da6f8c

Browse files
stepankuzminibesora
authored andcommitted
Fix MRT tiles loaded state (internal-2321)
1 parent c52b5c3 commit 2da6f8c

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

debug/render-test.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,15 @@
131131
if (options.fadeDuration) map._isInitialLoad = false;
132132

133133
map.repaint = true;
134-
await map.once('load');
134+
135+
const event = await Promise.race([
136+
map.once('load'),
137+
new Promise((resolve) => setTimeout(resolve, 1000, {type: 'timeout'}))
138+
]);
139+
140+
if (event.type === 'timeout') {
141+
console.error('Map load timed out after 1 second');
142+
}
135143

136144
await applyOperations(map, style.metadata.test);
137145

src/source/raster_array_tile_source.ts

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class RasterArrayTileSource extends RasterTileSource<'raster-array'> implements
113113
if (this.partial) {
114114
tile.state = 'empty';
115115
} else {
116+
if (!data) return callback(null);
117+
118+
tile.state = 'loaded';
116119
tile._isHeaderLoaded = true;
117120
tile._mrt = data;
118121

src/source/source_cache.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ class SourceCache extends Evented {
131131
if (!this._source.loaded()) { return false; }
132132
for (const t in this._tiles) {
133133
const tile = this._tiles[t];
134-
if (tile.state !== 'loaded' && tile.state !== 'errored')
135-
return false;
134+
if (!tile.loaded()) return false;
136135
}
137136
return true;
138137
}

src/source/tile.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ import type {VectorTileLayer} from '@mapbox/vector-tile';
5757
import type {ImageId, StringifiedImageId} from '../style-spec/expression/types/image_id';
5858

5959
const CLOCK_SKEW_RETRY_TIMEOUT = 30000;
60-
export type TileState = // Tile data is in the process of loading.
61-
'loading' | // Tile data has been loaded. Tile can be rendered.
62-
'loaded' | // Tile data has been loaded but has no content for rendering.
63-
'empty' | // Tile data has been loaded and is being updated. Tile can be rendered.
64-
'reloading' | // Tile data has been deleted.
65-
'unloaded' | // Tile data was not loaded because of an error.
66-
'errored' | 'expired';/* Tile data was previously loaded, but has expired per its
67-
* HTTP headers and is in the process of refreshing. */
60+
export type TileState =
61+
| 'loading' // Tile data is in the process of loading.
62+
| 'loaded' // Tile data has been loaded. Tile can be rendered.
63+
| 'empty' // Tile data has been loaded but has no content for rendering.
64+
| 'reloading' // Tile data has been loaded and is being updated. Tile can be rendered.
65+
| 'unloaded' // Tile data has been deleted.
66+
| 'errored' // Tile data was not loaded because of an error.
67+
| 'expired'; // Tile data was previously loaded, but has expired per its HTTP headers and is in the process of refreshing.
6868

6969
export type ExpiryData = {
7070
cacheControl?: string;
@@ -543,6 +543,10 @@ class Tile {
543543
}
544544
}
545545

546+
loaded(): boolean {
547+
return this.state === 'loaded' || this.state === 'errored';
548+
}
549+
546550
hasData(): boolean {
547551
return this.state === 'loaded' || this.state === 'reloading' || this.state === 'expired';
548552
}

test/ignores/all.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,7 @@ const skip = [
331331
"render-tests/3d-intersections/road-islands",
332332
"render-tests/3d-intersections/road-markups-clipping-underground",
333333
// Time out after 30s
334-
"render-tests/3d-intersections/max-zoom-mismatch",
335-
336-
// https://mapbox.atlassian.net/browse/GLJS-1184
337-
"render-tests/raster-array/semi-transparent-icon"
334+
"render-tests/3d-intersections/max-zoom-mismatch"
338335
];
339336

340337
export default {todo, skip};

0 commit comments

Comments
 (0)