From 0168018f65e2b41e4e5d891366497e6d0e0ed191 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 4 Nov 2024 08:36:06 -0800 Subject: [PATCH 1/3] reduce calls to _render() caused by jumpTo() --- src/ui/map.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ui/map.ts b/src/ui/map.ts index 1a8aab7783f..9e7a361efee 100644 --- a/src/ui/map.ts +++ b/src/ui/map.ts @@ -424,7 +424,7 @@ const defaultOptions: Readonly> = { maxTileCacheZoomLevels: config.MAX_TILE_CACHE_ZOOM_LEVELS, transformRequest: null, transformCameraUpdate: null, - fadeDuration: 300, + fadeDuration: 0, crossSourceCollisions: true, clickTolerance: 3, localIdeographFontFamily: 'sans-serif', @@ -676,8 +676,17 @@ export class Map extends Camera { this._setupContainer(); this._setupPainter(); - this.on('move', () => this._update(false)) - .on('moveend', () => this._update(false)) + this.on('moveend', () => { + if (!this.style || !this.style.sourceCaches || !this.transform) { + return; + } + for (const id in this.style.sourceCaches) { + this.style.sourceCaches[id].update(this.transform, this.terrain); + } + if (this.areTilesLoaded()) { + this._update(false); + } + }) .on('zoom', () => this._update(true)) .on('terrain', () => { this.painter.terrainFacilitator.dirty = true; @@ -745,6 +754,9 @@ export class Map extends Camera { } }); this.on('data', (event: MapDataEvent) => { + if (!this.areTilesLoaded()) { + return; + } this._update(event.dataType === 'style'); this.fire(new Event(`${event.dataType}data`, event)); }); @@ -3226,6 +3238,11 @@ export class Map extends Camera { this._placementDirty = this.style && this.style._updatePlacement(this.transform, this.showCollisionBoxes, fadeDuration, this._crossSourceCollisions, transformUpdateResult.forcePlacementUpdate); + if (this._placementDirty) { + this.triggerRepaint(); + return this; + } + if (transformUpdateResult.fireProjectionEvent) { this.fire(new Event('projectiontransition', transformUpdateResult.fireProjectionEvent)); } From dba6c0151e82ca4f69c33399ed41e389aa57b963 Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 5 Nov 2024 09:15:49 -0800 Subject: [PATCH 2/3] don't rerender on 'zoom' event ('movend' is sufficient) --- src/ui/map.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/map.ts b/src/ui/map.ts index 9e7a361efee..3dad41ed651 100644 --- a/src/ui/map.ts +++ b/src/ui/map.ts @@ -687,7 +687,6 @@ export class Map extends Camera { this._update(false); } }) - .on('zoom', () => this._update(true)) .on('terrain', () => { this.painter.terrainFacilitator.dirty = true; this._update(true); From 3583850143a6adc10c9c4e747e426d2421bb828d Mon Sep 17 00:00:00 2001 From: Nathan Date: Tue, 5 Nov 2024 09:16:37 -0800 Subject: [PATCH 3/3] if re-render is needed, call _render recursively instead of via triggerRepaint() --- src/ui/map.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ui/map.ts b/src/ui/map.ts index 3dad41ed651..46c31d0f80f 100644 --- a/src/ui/map.ts +++ b/src/ui/map.ts @@ -3238,8 +3238,7 @@ export class Map extends Camera { this._placementDirty = this.style && this.style._updatePlacement(this.transform, this.showCollisionBoxes, fadeDuration, this._crossSourceCollisions, transformUpdateResult.forcePlacementUpdate); if (this._placementDirty) { - this.triggerRepaint(); - return this; + return this._render(paintStartTimeStamp); } if (transformUpdateResult.fireProjectionEvent) {