vasturiano / globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
https://vasturiano.github.io/globe.gl/example/world-population/
MIT License
2.03k stars 301 forks source link

Resizing canvas breaks .onPointHover() #54

Closed snshn closed 3 years ago

snshn commented 3 years ago

Describe the bug I implemented auto-fitting functionality using this code:

// Fit canvas to window size upon resize
window.addEventListener("resize", event => {
    globe.camera().aspect = window.innerWidth / window.innerHeight;
    globe.camera().updateProjectionMatrix();
    globe.renderer().setSize(window.innerWidth, window.innerHeight);
});

and found out it breaks .onPointHover() and tooltips. They basically stop working, unless I hover over random areas (where those points used to be before the window was resized. If I restore window size back to the exact same dimensions it originally had, point hovers and tooltips will start working perfect again.

To Reproduce Steps to reproduce the behavior:

  1. Use the snippet above
  2. Ensure that .pointLabel() tooltips and .onPointHover() work
  3. Resize window
  4. See that hovering points no longer does anything
  5. Resize back to its original height and width
  6. See that hovering points shows tooltips

Expected behavior Tooltips and point hovers should work correctly after resizing the scene.

Screenshots N/A

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context I'm possibly doing something wrong in the resize callback function, but that's the only piece of code that properly resizes the scene, and that's what's recommended for THREE.js.

moranno commented 3 years ago

try this: https://github.com/vasturiano/globe.gl/issues/8

snshn commented 3 years ago

@maker2002 thank you very much, it worked!