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

[question]How do I write code to stop/resume autoRotate when mouse click? #49

Closed moranno closed 3 years ago

moranno commented 3 years ago

I just find a example here: https://github.com/vasturiano/react-globe.gl/issues/55#issuecomment-847450561 But it doesn't work in this version.

1.How do I write code to stop/resume autoRotate when mouse click? 2.Which version should I use? Ract ver or this ver? for performance wise?

Thanks for the great work!

vasturiano commented 3 years ago
  1. You can set auto-rotation of the globe via:
    myGlobe.controls().autoRotate = false; // or true

    So you just need to associate that action to your click event.

Additionally, if you just want to cancel the auto-rotation when the user manually zooms/pans the globe, you can do this:

// assuming auto-rotation has been previously engaged
const controls = myGlobe.controls();
controls.addEventListener('start', () => controls.autoRotate = false);
  1. Performance wise, both versions should be equivalent. You can choose whichever framework is more convenient for your app.
moranno commented 3 years ago

Thank You!