From eaf5c9f7cda17fe765f262c96e9453a8ec862d1d Mon Sep 17 00:00:00 2001 From: Aidan H Date: Thu, 4 Nov 2021 12:26:13 -0600 Subject: [PATCH] Fix terrain cache not updating on `setFeatureState` (#11209) * Invalidating terrain render cache on style.setFeatureState * Changed approach to directly clear render cache from Tile * Only on LineBucket and FillBucket Tests will be in a new PR --- src/source/source_state.js | 1 - src/source/tile.js | 8 ++++++++ src/terrain/terrain.js | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/source/source_state.js b/src/source/source_state.js index ceb78178b7e..be69889419d 100644 --- a/src/source/source_state.js +++ b/src/source/source_state.js @@ -80,7 +80,6 @@ class SourceFeatureState { } else { this.deletedStates[sourceLayer] = null; } - } getState(sourceLayer: string, featureId: number | string) { diff --git a/src/source/tile.js b/src/source/tile.js index d37ee05ca06..f3444baaf1b 100644 --- a/src/source/tile.js +++ b/src/source/tile.js @@ -29,6 +29,8 @@ import SegmentVector from '../data/segment.js'; const CLOCK_SKEW_RETRY_TIMEOUT = 30000; import type {Bucket} from '../data/bucket.js'; +import FillBucket from '../data/bucket/fill_bucket.js'; +import LineBucket from '../data/bucket/line_bucket.js'; import type StyleLayer from '../style/style_layer.js'; import type {WorkerTileResult} from './worker_source.js'; import type Actor from '../util/actor.js'; @@ -527,6 +529,12 @@ class Tile { if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) continue; bucket.update(sourceLayerStates, sourceLayer, availableImages, this.imageAtlas && this.imageAtlas.patternPositions || {}); + if (bucket instanceof LineBucket || bucket instanceof FillBucket) { + const sourceCache = painter.style._getSourceCache(bucket.layers[0].source); + if (painter._terrain && painter._terrain.enabled && sourceCache && bucket.programConfigurations.needsUpload) { + painter._terrain._clearRenderCacheForTile(sourceCache.id, this.tileID); + } + } const layer = painter && painter.style && painter.style.getLayer(id); if (layer) { this.queryPadding = Math.max(this.queryPadding, layer.queryRadius(bucket)); diff --git a/src/terrain/terrain.js b/src/terrain/terrain.js index 12f690566a1..09e2083f6c1 100644 --- a/src/terrain/terrain.js +++ b/src/terrain/terrain.js @@ -982,7 +982,11 @@ export class Terrain extends Elevation { const tiles = current[source]; const prevTiles = prev[source]; if (!prevTiles || prevTiles.length !== tiles.length || - tiles.some((t, index) => (t !== prevTiles[index] || (dirty[source] && dirty[source].hasOwnProperty(t.key))))) { + tiles.some((t, index) => + (t !== prevTiles[index] || + (dirty[source] && dirty[source].hasOwnProperty(t.key) + ))) + ) { equal = -1; break; }