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

275 views
Skip to first unread message

Scott Jason

unread,
Oct 3, 2014, 4:46:17 PM10/3/14
to cesiu...@googlegroups.com
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

Scott Hunter

unread,
Oct 3, 2014, 5:12:07 PM10/3/14
to cesiu...@googlegroups.com
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.



--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Jason

unread,
Oct 3, 2014, 5:29:28 PM10/3/14
to cesiu...@googlegroups.com
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
Message has been deleted

kulvin...@gmail.com

unread,
Apr 20, 2020, 2:52:31 PM4/20/20
to cesium-dev
Hi Scott,

Have you been able to fix the stop rotation issue?
Reply all
Reply to author
Forward
0 new messages