Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How to get absolute mouse coordinates of full image on cropped canvas in React

I've got an HTMLCanvasElement that I'm rendering in a React component that's supposed to display a map for a game. However, I don't want the entire image to be displayed on a person's screen as the map is fairly large, so I only draw a canvas element for part of the image at a time based on the user's position. However, when the user clicks on the map, I still want to retrieve the coordinates with respect to the entire image as opposed to just what's been drawn on the canvas. Is there any way to do this?

I've tried building the typical event handler for getting the mouse position, but this returns the coordinates relative to the cropped image, not the full image.

function handleClick(event) {
  const canvas = event.target;
  const context = canvas.getContext('2d');
  const rect = canvas.getBoundingClientRect();

  const x = event.clientX - rect.left;
  const y = event.clientY - rect.top;

  return [x, y]
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!