|
|
@ -17,7 +17,7 @@ export interface Point { |
|
|
|
const Viewport: react.FC<{}> = (props: {}) => { |
|
|
|
console.log(`--- Rendering viewport, props: ${JSON.stringify(props)} ---`); |
|
|
|
|
|
|
|
const initialShitf: Point = { x: 1000, y: 1000 }; |
|
|
|
const initialShitf: Point = { x: 0, y: 0 }; |
|
|
|
|
|
|
|
const [shift, setShift] = useState(initialShitf); |
|
|
|
|
|
|
@ -35,9 +35,18 @@ const Viewport: react.FC<{}> = (props: {}) => { |
|
|
|
setShift({ x: shift.x + shiftDelta.x, y: shift.y + shiftDelta.y }); |
|
|
|
}; |
|
|
|
|
|
|
|
const updateZoom = (zoomFactor: number) => { |
|
|
|
setZoom(zoom * zoomFactor); |
|
|
|
}; |
|
|
|
const updateZoom = (zoomFactor: number, center: Point) => { |
|
|
|
const newZoom = zoom * zoomFactor; |
|
|
|
setZoom(newZoom); |
|
|
|
setShift({ |
|
|
|
x: shift.x + center.x / zoom - center.x / newZoom, |
|
|
|
y: shift.y + center.y / zoom - center.y / newZoom, |
|
|
|
}); |
|
|
|
// setShift({
|
|
|
|
// x: shift.x + 1440 / 2 / zoom - window.innerWidth / 2 / newZoom,
|
|
|
|
// y: shift.y + 2904 / 2 / zoom - window.innerHeight / 2 / newZoom,
|
|
|
|
// });
|
|
|
|
}; |
|
|
|
|
|
|
|
return ( |
|
|
|
<div className='viewport'> |
|
|
|