简体   繁体   中英

Get canvas viewport translate when zooming

How i can get translate canvas viewport when zooming?

My zooming method:

    mouseZoom(opt) {
        let canvas = this.canvasRender;
        let delta = opt.e.deltaY;
        let zoom = canvas.getZoom();
        zoom = zoom + delta / 200;
        if (zoom > 10 || zoom < 0.2) {
            return;
        }

        if (zoom > 20) zoom = 20;
        if (zoom < 0.001) zoom = 0.01;
        canvas.zoomToPoint({x: opt.e.offsetX, y: opt.e.offsetY}, zoom);
        opt.e.preventDefault();
        opt.e.stopPropagation();       
     }

Take a look at canvas.viewportTransform property.

It contains all viewport transformation stored as array [a, b, c, d, tx, ty] , where:

a -– x scale

b – y skew

c – x scew

d – y scale

tx – x translation

ty – y translation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM