Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用hammerjs和camera.pan实现相机平移,拖拽画布时漂移得很厉害 #1868

Open
qcjwind opened this issue Dec 12, 2024 · 3 comments

Comments

@qcjwind
Copy link

qcjwind commented Dec 12, 2024

!!!https://antv-issue-helper.surge.sh 无法提交issue。

重现demo:https://g.antv.antgroup.com/zh/examples/camera/camera-action#zoom-by-point
重现步骤:随意拖拽画布。就会出现漂移的情况。

@wang1212
Copy link
Member

漂移指的是什么意思?


如果是灵敏度太高的话,可以调整参数:

hammer.on('pan', (ev) => {
  camera.pan(
    (-ev.deltaX / Math.pow(2, camera.getZoom())) * 0.5,
    (-ev.deltaY / Math.pow(2, camera.getZoom())) * 0.5,
  );
});

将上述代码的 0.5 调整为更小即可。

@qcjwind
Copy link
Author

qcjwind commented Dec 12, 2024

2024-12-12.13.52.45.mov

@wang1212
Copy link
Member

2024-12-12.13.52.45.mov

没理解错的话,你的问题可能是想实现跟随手势均速平移。

对于 hammer 提供的事件对象来说,deltaXdeltaY 参数似乎代表的是自从首次触发事件时位置以来的绝对偏移量,而 G 相机 API 的 pan() 需要的参数是相对偏移量,你可以通过在每次触发事件时记录上一次的绝对偏移量,通过计算差值得到相对偏移量,然后调用 pan() 来实现你期望的交互效果。

你可以直接使用 g-plugin-control 插件,或者参考其实现:https://github.com/antvis/G/blob/next/packages/g-plugin-control/src/ControlPlugin.ts#L66

关于插件的使用方式请查看该文档:https://g.antv.antgroup.com/plugins/intro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants