fix
This commit is contained in:
@@ -499,26 +499,17 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
let trailingTimeout = null;
|
||||
let throttleDelay = 100;
|
||||
observer = new ResizeObserver((entries) => {
|
||||
clearTimeout(trailingTimeout);
|
||||
trailingTimeout = setTimeout(() => {
|
||||
optimizeCanvasRendering(canvasManager.canvas, ()=> handleWindowResize());
|
||||
}, throttleDelay);
|
||||
}, 200);
|
||||
});
|
||||
observer.observe(canvasContainerRef.value);
|
||||
// 使用window的resize事件代替ResizeObserver
|
||||
// 只有当窗口大小变化时才更新画布尺寸
|
||||
// window.addEventListener("resize", handleWindowResize);
|
||||
if (props.config.initZoom) {
|
||||
const width = canvasManager.width;
|
||||
const height = canvasManager.height;
|
||||
const cwidth = props.config.width;
|
||||
const cheight = props.config.height;
|
||||
let zoom = Math.min(1, width / cwidth, height / cheight);
|
||||
if (zoom < 1) zoom -= 0.05;
|
||||
setZoom(zoom); // 设置画布缩放
|
||||
}
|
||||
setInitZoom();
|
||||
});
|
||||
|
||||
watchEffect(() => {
|
||||
@@ -573,13 +564,26 @@ async function handleWindowResize() {
|
||||
// 使用requestAnimationFrame来防止频繁更新
|
||||
await new Promise(requestAnimationFrame);
|
||||
if(!canvasManager) return;
|
||||
updateCanvasSize();
|
||||
await updateCanvasSize();
|
||||
// 确保显示的缩放信息是最新的
|
||||
currentZoom.value = Math.round(canvasManager.canvas.getZoom() * 100);
|
||||
setInitZoom();
|
||||
await new Promise(requestAnimationFrame);
|
||||
await layerManager?.updateLayersObjectsInteractivity?.();
|
||||
}
|
||||
|
||||
function setInitZoom(){
|
||||
if (props.config.initZoom) {
|
||||
const width = canvasManager.width;
|
||||
const height = canvasManager.height;
|
||||
const cwidth = props.config.width;
|
||||
const cheight = props.config.height;
|
||||
let zoom = Math.min(1, width / cwidth, height / cheight);
|
||||
if (zoom < 1) zoom -= 0.05;
|
||||
setZoom(zoom); // 设置画布缩放
|
||||
}
|
||||
}
|
||||
|
||||
function resetZoom() {
|
||||
canvasManager.resetZoom();
|
||||
}
|
||||
@@ -625,13 +629,13 @@ function zoomOut() {
|
||||
canvasManager.animateZoom(centerPoint, newZoom);
|
||||
}
|
||||
|
||||
function updateCanvasSize() {
|
||||
async function updateCanvasSize() {
|
||||
if (canvasManager && canvasContainerRef.value) {
|
||||
const containerWidth = canvasContainerRef.value.clientWidth;
|
||||
const containerHeight = canvasContainerRef.value.clientHeight;
|
||||
|
||||
// 普通模式下,更新画布大小,这会同时重置视图和居中所有元素
|
||||
canvasManager.setCanvasSize(containerWidth, containerHeight);
|
||||
await canvasManager.setCanvasSize(containerWidth, containerHeight);
|
||||
|
||||
// // 如果启用了红绿图模式,使用 layerManager 的缩放方法
|
||||
// if (props.enabledRedGreenMode && layerManager) {
|
||||
|
||||
Reference in New Issue
Block a user