Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda