fix(map): clamp layer fade progress to the valid range
A frame timestamp may precede performance.now sampled when hiding starts, producing negative progress and opacity above 1. Bound progress at both ends; cover the exact label failure and real MapLibre paint validation.
This commit is contained in:
@@ -48,6 +48,27 @@ async function openLayerFixture(page: Page, vectorPipes = false) {
|
||||
await page.getByRole("button", { name: /图层:管理地图图层/ }).click();
|
||||
}
|
||||
|
||||
test("analysis label fade accepts a frame timestamp earlier than the visibility change", async ({ page }) => {
|
||||
await openLayerFixture(page);
|
||||
await page.evaluate(async () => {
|
||||
const modulePath = "/src/features/workbench/map/layer-visibility.ts";
|
||||
const { setMapLayersVisibility } = await import(modulePath);
|
||||
const map = window.__waterNetworkMap!;
|
||||
const errors: string[] = [];
|
||||
map.on("error", (event) => {
|
||||
if (event.error.message.includes("simulation-backend-analysis-label")) errors.push(event.error.message);
|
||||
});
|
||||
Object.assign(window, { analysisFadeErrors: errors });
|
||||
const nativeFrame = window.requestAnimationFrame.bind(window);
|
||||
window.requestAnimationFrame = (callback) => nativeFrame((time) => callback(time - 100));
|
||||
try { setMapLayersVisibility(map, ["simulation-backend-analysis-label"], false); }
|
||||
finally { window.requestAnimationFrame = nativeFrame; }
|
||||
});
|
||||
await expect.poll(() => page.evaluate(() => window.__waterNetworkMap!
|
||||
.getLayoutProperty("simulation-backend-analysis-label", "visibility"))).toBe("none");
|
||||
expect(await page.evaluate(() => (window as unknown as { analysisFadeErrors: string[] }).analysisFadeErrors)).toEqual([]);
|
||||
});
|
||||
|
||||
for (const [label, layerId, property] of [
|
||||
["管线", "pipes-flow", "line-opacity"],
|
||||
["水库", "reservoirs-symbol", "icon-opacity"],
|
||||
|
||||
Reference in New Issue
Block a user