Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How i get clicked x, y coordinates in react-zoom-pan-pinch canvas? #472

Open
skky-y opened this issue Apr 8, 2024 · 1 comment
Open

Comments

@skky-y
Copy link

skky-y commented Apr 8, 2024

I want to place an item at the x, y coordinates where I've clicked within the react-zoom-pan-pinch canvas. To do this, I need to get the x, y values from the react-zoom-pan-pinch canvas where I clicked. How can I achieve this?

@skky-y skky-y changed the title How i get clicked x, y value in react-zoom-pan-pinch canvas? How i get clicked x, y coordinates in react-zoom-pan-pinch canvas? Apr 8, 2024
@zardoy
Copy link

zardoy commented Jul 7, 2024

very easy

onZoom={ref => {
      scale = 1 / ref.state.scale
  }}
  onPanning={ref => {
      scale = 1 / ref.state.scale
  }}
const rect = containerRef.current.getBoundingClientRect()
const { x, y } = { x: e.clientX - rect.left, y: e.clientY - rect.top }
getXyFromAbslute(x: number, y: number) {
        return [x * scale, y * scale]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants