Rotate Camera Increases In Speed Everytime Function Is Called

Hey guys, I was messing around with trying to get the globe to spin and I was able to make it spin everytime I called the function, but it seems like everytime the function is called the globe begins to increase in rotation speed.

I tried looking at the Camera API to try and find a resolution to it, as well as on here and google. The best answer I've gotten is to initialize the event listener as a variable and remove it as such, but i'm unsure how to do that and still call it inside a function. I've also tried removing the event listener at the end of the function and that didn't work too (maybe i'm calling it wrong?) Anyways, any help would be greatly appreciated!

function startSpin(){
      viewer.clock.onTick.addEventListener(function(clock) {

Uh… if you’re calling startSpin() multiple times, then yes, it would be going faster. Every time you call it, it’s going to add another listener, so if you call it 10 times, you’ll have 10 listeners, and it’ll be rotating at a rate of 10 * 0.005 = 0.05/second. You would definitely want to only add a single listener, and remove it when the spin is supposed to end. You probably also want to put a sanity check in startSpin() so that it only adds a new listener if one doesn’t exist yet.

Hey Mark, thanks for the reply! I was messing with removing the event listener for the longest time and I guess it turns out I was removing it incorrectly. thank you for the response!