mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-17 22:08:25 +08:00
Feat:新增限制TouchEvent插件双指缩放的最大值和最小值
This commit is contained in:
@@ -323,6 +323,10 @@ export const defaultOpt = {
|
||||
// 禁止双指缩放,你仍旧可以使用api进行缩放
|
||||
// 需要注册TouchEvent插件后生效
|
||||
disableTouchZoom: false,
|
||||
// 允许最大和最小的缩放值,百分数
|
||||
// 传-1代表不限制
|
||||
minTouchZoomScale: 20,
|
||||
maxTouchZoomScale: -1,
|
||||
|
||||
// 【Scrollbar插件】
|
||||
// 当注册了滚动条插件(Scrollbar)时,是否将思维导图限制在画布内,isLimitMindMapInCanvas不再起作用
|
||||
|
||||
@@ -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 +
|
||||
|
||||
Reference in New Issue
Block a user