source: imaps-frontend/src/scripts/util/zoomStage.js

main
Last change on this file was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 7 months ago

Pred finalna verzija

  • Property mode set to 100644
File size: 732 bytes
Line 
1export const zoomStage = (e,stage,shift=false) => {
2 if (shift && !e.evt.shiftKey) return;
3
4 e.evt.preventDefault();
5
6 const scaleFactor = e.evt.deltaY > 0 ? 0.85 : 1.2;
7
8 const prevScale = stage.scaleX();
9
10 let newScale = prevScale * scaleFactor;
11
12 const mousePos = stage.getRelativePointerPosition();
13
14 let mousePoint = {
15 x: (mousePos.x - stage.x()) / prevScale,
16 y: (mousePos.y - stage.y()) / prevScale,
17 };
18
19 stage.scale({
20 x: newScale,
21 y: newScale,
22 });
23
24 let newStagePos = {
25 x: mousePos.x - mousePoint.x * newScale,
26 y: mousePos.y - mousePoint.y * newScale,
27 };
28
29 stage.position(newStagePos);
30 // this.drawGrid();
31 stage.batchDraw();
32}
Note: See TracBrowser for help on using the repository browser.