support full screen mode
This commit is contained in:
@@ -72,25 +72,8 @@ function fitMap() {
|
|||||||
|
|
||||||
watch(() => [props.screenWidth, props.screenHeight], ([w, h]) => {
|
watch(() => [props.screenWidth, props.screenHeight], ([w, h]) => {
|
||||||
if (viewport) {
|
if (viewport) {
|
||||||
// 1. Resize Viewport 视口尺寸更新
|
// 窗口尺寸变化时,直接重新适配地图,确保自动 Zoom 和居中
|
||||||
viewport.resize(w, h, props.worldWidth, props.worldHeight)
|
fitMap()
|
||||||
|
|
||||||
// 2. 重新计算适配比例
|
|
||||||
const fitScale = Math.min(w / props.worldWidth, h / props.worldHeight)
|
|
||||||
|
|
||||||
// 3. 设定缩放限制
|
|
||||||
// 确保 maxScale 始终大于 minScale,防止地图极小时崩溃
|
|
||||||
const minScale = fitScale * 0.8
|
|
||||||
const maxScale = Math.max(4.0, minScale * 2.0)
|
|
||||||
|
|
||||||
viewport.clampZoom({ minScale, maxScale })
|
|
||||||
|
|
||||||
// 4. 自动修正缩放
|
|
||||||
// 如果当前缩放过小(导致黑边),或者因为初始化时的尺寸问题导致缩放不正确,强制恢复到适配大小
|
|
||||||
if (viewport.scaled < minScale * 0.95) {
|
|
||||||
viewport.setZoom(fitScale)
|
|
||||||
viewport.moveCenter(props.worldWidth / 2, props.worldHeight / 2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user