Fix errors with fog disappearing on zoom and crashing on zooming out

This commit is contained in:
Mitchell McCaffrey
2021-01-02 18:01:04 +11:00
parent c90434b626
commit 2482196876
2 changed files with 22 additions and 4 deletions

View File

@@ -428,11 +428,21 @@ function MapFog({
const canvas = fogGroup.getChildren()[0].getCanvas();
const pixelRatio = canvas.pixelRatio || 1;
// Constrain fog buffer to the map resolution
const fogRect = fogGroup.getClientRect();
const maxMapSize = Math.max(map.width, map.height);
const maxFogSize =
Math.max(fogRect.width, fogRect.height) / debouncedStageScale;
const maxPixelRatio = maxMapSize / maxFogSize;
fogGroup.cache({
pixelRatio: Math.min(debouncedStageScale * pixelRatio, 20),
pixelRatio: Math.min(
Math.max(debouncedStageScale * pixelRatio, 1),
maxPixelRatio
),
});
fogGroup.getLayer().draw();
}, [fogShapes, editable, active, debouncedStageScale, mapWidth]);
}, [fogShapes, editable, active, debouncedStageScale, mapWidth, map]);
return (
<Group>