diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 44257b04..526665fe 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -323,6 +323,10 @@ export const defaultOpt = { // 禁止双指缩放,你仍旧可以使用api进行缩放 // 需要注册TouchEvent插件后生效 disableTouchZoom: false, + // 允许最大和最小的缩放值,百分数 + // 传-1代表不限制 + minTouchZoomScale: 20, + maxTouchZoomScale: -1, // 【Scrollbar插件】 // 当注册了滚动条插件(Scrollbar)时,是否将思维导图限制在画布内,isLimitMindMapInCanvas不再起作用 diff --git a/simple-mind-map/src/plugins/TouchEvent.js b/simple-mind-map/src/plugins/TouchEvent.js index 61fae73d..d13569ca 100644 --- a/simple-mind-map/src/plugins/TouchEvent.js +++ b/simple-mind-map/src/plugins/TouchEvent.js @@ -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 +