this.hammer = new Hammer.Manager(this.canvasElement);
const pinch = new Hammer.Pinch();
const pan = new Hammer.Pan({
threshold: 5,
});
this.hammer.add([pinch, pan]);
let initialZoom = 1;
this.hammer.on('pinchstart', (event) => {
initialZoom = mainCamera.zoom;
});
this.hammer.on('pinchmove', (event) => {
this.backgroundZonePointerDown = false;
mainCamera.zoom = initialZoom * event.scale;
});
this.hammer.on('pinchend', (event) => {
initialZoom = 1;
});
this.hammer.on('panmove', (event) => {
this.backgroundZonePointerDown = false;
this.pan = {x: event.deltaX * window.devicePixelRatio, y: event.deltaY * window.devicePixelRatio};
});
this.hammer.on('panend', () => {
this.backgroundZonePointerDown = false;
this.pan = undefined;
this.previousPan = undefined;
});
有时我平移然后快速捏住,它无法识别平移。有时我会快速摇两次,但失败了。使用d3缩放效果完美。