Fix:修复当画布容器距浏览器窗口左上角不为0时,fit方法计算出来的位置有误差的问题

This commit is contained in:
街角小林 2023-12-21 11:25:08 +08:00
parent 3d0b257325
commit d80ee1e7c8

View File

@ -261,17 +261,17 @@ class View {
// 适应画布大小 // 适应画布大小
fit() { fit() {
let { fitPadding } = this.mindMap.opt const { fitPadding } = this.mindMap.opt
let draw = this.mindMap.draw const draw = this.mindMap.draw
let origTransform = draw.transform() const origTransform = draw.transform()
let rect = draw.rbox() const rect = draw.rbox()
let drawWidth = rect.width / origTransform.scaleX const drawWidth = rect.width / origTransform.scaleX
let drawHeight = rect.height / origTransform.scaleY const drawHeight = rect.height / origTransform.scaleY
let drawRatio = drawWidth / drawHeight const drawRatio = drawWidth / drawHeight
let { width: elWidth, height: elHeight } = this.mindMap.elRect let { width: elWidth, height: elHeight } = this.mindMap.elRect
elWidth = elWidth - fitPadding * 2 elWidth = elWidth - fitPadding * 2
elHeight = elHeight - fitPadding * 2 elHeight = elHeight - fitPadding * 2
let elRatio = elWidth / elHeight const elRatio = elWidth / elHeight
let newScale = 0 let newScale = 0
let flag = '' let flag = ''
if (drawWidth <= elWidth && drawHeight <= elHeight) { if (drawWidth <= elWidth && drawHeight <= elHeight) {
@ -292,7 +292,10 @@ class View {
newScale = newWidth / drawWidth newScale = newWidth / drawWidth
} }
this.setScale(newScale) this.setScale(newScale)
let newRect = draw.rbox() const newRect = draw.rbox()
// 需要考虑画布容器距浏览器窗口左上角的距离
newRect.x -= this.mindMap.elRect.left
newRect.y -= this.mindMap.elRect.top
let newX = 0 let newX = 0
let newY = 0 let newY = 0
if (flag === 1) { if (flag === 1) {