I'm building a Canvas by some data that i receive from api, and this is all fine. Is a few days anyway that I'm stucked on the fact that with the following code `canvas.addEventListener('wheel', (event: MouseWheelEvent) => { event.preventDefault();
let coords = Positioning.transformedPoint(
event.pageX - canvas.offsetLeft,
event.pageY - canvas.offsetTop
);
canvasMethods.clear();
canvasMethods.translate(coords.x, coords.y);
if (event.wheelDeltaY > 0) {
canvasMethods.scale(ZoomDirection.ZOOM_IN);
} else if (event.wheelDeltaY < 0) {
canvasMethods.scale(ZoomDirection.ZOOM_OUT);
}
canvasMethods.translate(-coords.x, -coords.y);
this._renderFn();
}, false);
canvas.addEventListener('mousedown', (event: MouseEvent) => {
event.preventDefault();
this._dragging = true;
this._dragStart = Positioning.transformedPoint(
event.clientX - canvas.offsetLeft,
event.clientY - canvas.offsetTop
);
}, false);
canvas.addEventListener('dblclick', (event: MouseEvent) => {
let coords = Positioning.transformedPoint(
event.clientX - canvas.offsetLeft,
event.clientY - canvas.offsetTop
);
this._clickFn(coords);
});
canvas.addEventListener('mousemove', (event: MouseEvent) => {
if (this._dragging) {
event.preventDefault();
this._dragEnd = Positioning.transformedPoint(
event.pageX - canvas.offsetLeft,
event.pageY - canvas.offsetTop
);
let coords = Positioning.transformedPoint(
event.clientX - canvas.offsetLeft,
event.clientY - canvas.offsetTop
);
canvasMethods.translate(coords.x - this._dragStart.x, coords.y - this._dragStart.y);
canvasMethods.clear();
this._renderFn();
this._dragStart = this._dragEnd;
}
}, false);
canvas.addEventListener('mouseup', (event: MouseEvent) => {
event.preventDefault();
this._dragging = false;
this._dragStart = null;
this._dragEnd = null;
})
}`
i get the right coordinates when it's on normale scale, but as soon as i scale i get an incremental error( basically the distance between the actual point and the mouse cursor is getting bigger and bigger ) and i cannot figure why. For calculate the coord in a Matrix i use the SVG method as wrapper in the following way ` export class Positioning { static svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); private static xform = Positioning.svg.createSVGMatrix();
static transformedPoint(x: number, y: number): SVGPoint {
let coords = Positioning.svg.createSVGPoint();
coords.x = x;
coords.y = y;
return coords.matrixTransform(Positioning.xform.inverse());
}
}`
I know that this somehow has to do with caling but i really cannot figure how get account of the scaling and do the proper operation to obtain the proportion. I've also checked this answer Zoom Canvas to Mouse Cursor that's pretty accurate but actually he get account of it in some way that i cannot reconize. Have someone else faced the same problem?