Feat:新增限制TouchEvent插件双指缩放的最大值和最小值

This commit is contained in:
街角小林
2024-06-13 19:12:24 +08:00
parent eea1109e43
commit f794df4e6f
2 changed files with 18 additions and 2 deletions

View File

@@ -323,6 +323,10 @@ export const defaultOpt = {
// 禁止双指缩放你仍旧可以使用api进行缩放
// 需要注册TouchEvent插件后生效
disableTouchZoom: false,
// 允许最大和最小的缩放值,百分数
// 传-1代表不限制
minTouchZoomScale: 20,
maxTouchZoomScale: -1,
// 【Scrollbar插件】
// 当注册了滚动条插件Scrollbar是否将思维导图限制在画布内isLimitMindMapInCanvas不再起作用

View File

@@ -66,7 +66,13 @@ class TouchEvent {
let touch = e.touches[0]
this.dispatchMouseEvent('mousemove', touch.target, touch)
} else if (len === 2) {
if (this.mindMap.opt.disableTouchZoom) return
let { disableTouchZoom, minTouchZoomScale, maxTouchZoomScale } =
this.mindMap.opt
if (disableTouchZoom) return
minTouchZoomScale =
minTouchZoomScale === -1 ? -Infinity : minTouchZoomScale / 100
maxTouchZoomScale =
maxTouchZoomScale === -1 ? Infinity : maxTouchZoomScale / 100
let touch1 = e.touches[0]
let touch2 = e.touches[1]
let ox = touch1.clientX - touch2.clientX
@@ -101,8 +107,14 @@ class TouchEvent {
if (Math.abs(distance - viewBefore.distance) <= 10) {
scale = viewBefore.scale
}
scale =
scale < minTouchZoomScale
? minTouchZoomScale
: scale > maxTouchZoomScale
? maxTouchZoomScale
: scale
const ratio = 1 - scale / viewBefore.scale
view.scale = scale < 0.1 ? 0.1 : scale
view.scale = scale
view.x =
viewBefore.x +
(cx - viewBefore.x) * ratio +