Getting Closer .. Still Can't Stop the Rotation .. Please, please help

Hello again,

I realize I’m sorta talking to myself here but am gonna give this one more shot.

I know my questions are not nearly as advanced as most but I’d honestly be really grateful for any help, from anyone.

I went off a posters question from this morning and believe I’m spinning the globe correctly now :

spingGlobe( 0.5 )

spinGlobe : function( dynamicRate ){

var viewer = this.viewer;

var scene = this.scene;

var clock = this.clock;

var previousTime = Date.now();

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

var spinRate = dynamicRate;

var currentTime = Date.now();

var delta = ( currentTime - previousTime ) / 1000;

previousTime = currentTime;

viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z, -spinRate * delta);

});

}

BUT … when I try to stop it by then invoking : spinGobe( 0.0 ) … it doesn’t work. This only works if I invoke spinGlobe( 0.0 ) the first time. So it seems like you can’t dynamically change the spinRate??

If anyone can help me figure out how to stop the globe rotation so I can properly invoke a different event … man, I’d be so happy!

Thanks,

Scott

spinGlobe(0) won’t work, because your spinGlobe function adds a new event listener each time it is called, but does not remove the old listener which will continue to rotate the camera.

Try storing a reference to the event listener function somewhere, so that you can call removeEventListener when you want to stop rotation.

Alternatively, you could modify the listener function to check a flag to determine whether to call rotate or not.

Scott,

Awesome, thank you. That makes sense too because when I console.logged the spinRate it showed both.

So I’ve read the docs and done the camera tutorials … lots of times … but if you can point me in the direction where I might learn enough to be ale to implement either :

storing a reference to the event listener function somewhere, so that you can call removeEventListener when you want to stop rotation.

or

you could modify the listener function to check a flag to determine whether to call rotate or not.

Thank you again.

Much appreciated.

Scott