Feat:新增限制TouchEvent插件双指缩放的最大值和最小值
This commit is contained in:
parent
eea1109e43
commit
f794df4e6f
@ -323,6 +323,10 @@ export const defaultOpt = {
|
|||||||
// 禁止双指缩放,你仍旧可以使用api进行缩放
|
// 禁止双指缩放,你仍旧可以使用api进行缩放
|
||||||
// 需要注册TouchEvent插件后生效
|
// 需要注册TouchEvent插件后生效
|
||||||
disableTouchZoom: false,
|
disableTouchZoom: false,
|
||||||
|
// 允许最大和最小的缩放值,百分数
|
||||||
|
// 传-1代表不限制
|
||||||
|
minTouchZoomScale: 20,
|
||||||
|
maxTouchZoomScale: -1,
|
||||||
|
|
||||||
// 【Scrollbar插件】
|
// 【Scrollbar插件】
|
||||||
// 当注册了滚动条插件(Scrollbar)时,是否将思维导图限制在画布内,isLimitMindMapInCanvas不再起作用
|
// 当注册了滚动条插件(Scrollbar)时,是否将思维导图限制在画布内,isLimitMindMapInCanvas不再起作用
|
||||||
|
|||||||
@ -66,7 +66,13 @@ class TouchEvent {
|
|||||||
let touch = e.touches[0]
|
let touch = e.touches[0]
|
||||||
this.dispatchMouseEvent('mousemove', touch.target, touch)
|
this.dispatchMouseEvent('mousemove', touch.target, touch)
|
||||||
} else if (len === 2) {
|
} 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 touch1 = e.touches[0]
|
||||||
let touch2 = e.touches[1]
|
let touch2 = e.touches[1]
|
||||||
let ox = touch1.clientX - touch2.clientX
|
let ox = touch1.clientX - touch2.clientX
|
||||||
@ -101,8 +107,14 @@ class TouchEvent {
|
|||||||
if (Math.abs(distance - viewBefore.distance) <= 10) {
|
if (Math.abs(distance - viewBefore.distance) <= 10) {
|
||||||
scale = viewBefore.scale
|
scale = viewBefore.scale
|
||||||
}
|
}
|
||||||
|
scale =
|
||||||
|
scale < minTouchZoomScale
|
||||||
|
? minTouchZoomScale
|
||||||
|
: scale > maxTouchZoomScale
|
||||||
|
? maxTouchZoomScale
|
||||||
|
: scale
|
||||||
const ratio = 1 - scale / viewBefore.scale
|
const ratio = 1 - scale / viewBefore.scale
|
||||||
view.scale = scale < 0.1 ? 0.1 : scale
|
view.scale = scale
|
||||||
view.x =
|
view.x =
|
||||||
viewBefore.x +
|
viewBefore.x +
|
||||||
(cx - viewBefore.x) * ratio +
|
(cx - viewBefore.x) * ratio +
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user