Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back synced frame method and use it for triggerRepaint. #4535

Merged
merged 7 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### 🐞 Bug fixes

- _...Add new stuff here..._
- Render frame synchronized again in requestAnimationFrame callback ([#4535](https://github.com/maplibre/maplibre-gl-js/pull/4535))

## 5.0.1

Expand Down
24 changes: 15 additions & 9 deletions src/ui/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3379,15 +3379,21 @@
triggerRepaint() {
if (this.style && !this._frameRequest) {
this._frameRequest = new AbortController();
browser.frameAsync(this._frameRequest).then((paintStartTimeStamp: number) => {
PerformanceUtils.frame(paintStartTimeStamp);
this._frameRequest = null;
this._render(paintStartTimeStamp);
}).catch((error: Error) => {
if (!isAbortError(error) && !isFramebufferNotCompleteError(error)) {
throw error;
}
});
browser.frame(
this._frameRequest,
(paintStartTimeStamp) => {
PerformanceUtils.frame(paintStartTimeStamp);
this._frameRequest = null;
try {
this._render(paintStartTimeStamp);
} catch(error) {
if (!isAbortError(error) && !isFramebufferNotCompleteError(error)) {
throw error;

Check warning on line 3391 in src/ui/map.ts

View check run for this annotation

Codecov / codecov/patch

src/ui/map.ts#L3391

Added line #L3391 was not covered by tests
}
}
},
() => {}
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui/map_tests/map_events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,9 @@ describe('map events', () => {
await sourcePromise;
});

test('getZoom on moveend is the same as after the map end moving, with terrain on', () => {
test('getZoom on moveend is the same as after the map end moving, with terrain on', async () => {
const map = createMap({interactive: true, clickTolerance: 4});
await map.once('style.load');
map.terrain = createTerrain();
let actualZoom: number;
map.on('moveend', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/map_tests/map_zoom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ test('throw on maxZoom smaller than minZoom at init with falsey maxZoom', () =>
}).toThrow(new Error('maxZoom must be greater than or equal to minZoom'));
});

test('recalculate zoom is done on the camera update transform', () => {
test('recalculate zoom is done on the camera update transform', async () => {
const map = createMap({
interactive: true,
clickTolerance: 4,
transformCameraUpdate: ({zoom}) => ({zoom: zoom + 0.1})
});
await map.once('style.load');
map.terrain = createTerrain();
const canvas = map.getCanvas();
simulate.dragWithMove(canvas, {x: 100, y: 100}, {x: 100, y: 150});
Expand Down
14 changes: 9 additions & 5 deletions src/util/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export const browser = {
*/
now,

frame(abortController: AbortController, fn: (paintStartTimestamp: number) => void, reject: (error: Error) => void): void {
const frame = requestAnimationFrame(fn);
abortController.signal.addEventListener('abort', () => {
cancelAnimationFrame(frame);
reject(createAbortError());
});
},

frameAsync(abortController: AbortController): Promise<number> {
return new Promise((resolve, reject) => {
const frame = requestAnimationFrame(resolve);
abortController.signal.addEventListener('abort', () => {
cancelAnimationFrame(frame);
reject(createAbortError());
});
this.frame(abortController, resolve, reject);
});
},

Expand Down
Loading