# Stop Globe rotation not working

**URL:** <https://community.cesium.com/t/stop-globe-rotation-not-working/9393>\
**Category:** CesiumJS\
**Created:** [April 20, 2020, 6:50pm UTC](https://community.cesium.com/t/stop-globe-rotation-not-working/9393 "2020-04-20T18:50:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kulvinderjatt](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kulvinderjatt/32/2895_2.png) [@kulvinderjatt](https://community.cesium.com/u/kulvinderjatt)\
**Post date:** [April 20, 2020, 6:50pm UTC](https://community.cesium.com/t/stop-globe-rotation-not-working/9393/1 "2020-04-20T18:50:22Z")

</div>

1. A concise explanation of the problem you’re experiencing.  
Stop Globe rotation function not working

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.  
var viewer = new Cesium.Viewer(‘cesiumContainer’);  
var scene = viewer.scene;

function spinGlobe( dynamicRate ){  
var previousTime = Date.now();

```
viewer.scene.postRender.addEventListener(function (scene, time){
    var spinRate = dynamicRate;
    var currentTime = Date.now();
    var delta = ( currentTime - previousTime ) / 1000;
    previousTime = currentTime;
    viewer.scene.camera.rotate(Cesium.Cartesian3.UNIT_Z, spinRate * delta);
});

```

}

function stopglobe() {  
[//console.log](https://console.log)(‘hjhggh’);  
spinGlobe(0.0);  
viewer.scene.postRender.removeEventListener(spinGlobe);

}

Sandcastle.addToolbarMenu([

```
{

text : 'Select',

```

},

```
{

text : 'Spin Globe',
onselect : function() {
    spinGlobe(0.08);
    
}

```

}, {  
text : ‘Stop GlobeRotation’,  
onselect : function() {  
stopglobe(0.0);  
viewer.scene.postRender.removeEventListener(spinGlobe);

```
}

```

}]);

Sandcastle.reset = function() {  
viewer.entities.removeAll();  
};

1. Context. Why do you need to do this? We might know a better way to accomplish your goal.  
Project requirement

2. The Cesium version you’re using, your operating system and browser.  
1.68

---

<div class="post-metadata">

**Author:** ![kulvinderjatt](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kulvinderjatt/32/2895_2.png) [@kulvinderjatt](https://community.cesium.com/u/kulvinderjatt)\
**Post date:** [May 4, 2020, 5:43pm UTC](https://community.cesium.com/t/stop-globe-rotation-not-working/9393/2 "2020-05-04T17:43:17Z")

</div>

Hi Omar,

I used the following logic:

var viewer = new Cesium.Viewer(‘cesiumContainer’);  
var isSpinning = true;  
//default true for launch app rotate  
var scene = viewer.scene;

```
                    // Add event to rotate camera for globe
                    function addSpinCameraEvent(){
                      viewer.clock.onTick.addEventListener(spinCamera);
                    }
                    
                    // Remove event to rotate camera for globe
                    function removeSpinCameraEvent(){
                      viewer.clock.onTick.removeEventListener(spinCamera);
                    }
                    
                    //rotate globe function
                      function rotateGlobeCamera(){
                        //if not spinning, spin
                        if (!isSpinning){
                          addSpinCameraEvent();
                          isSpinning = true;
                        }
                        else{
                          //stop spinning
                          removeSpinCameraEvent();
                          isSpinning = false;
                        }
                      }
                    
                    //spin camera function
                      function spinCamera(clock) {
                      if (scene.mode === Cesium.SceneMode.SCENE3D)
                      {
                          //scene.camera.rotateRight(0.001);}
                          scene.camera.rotateLeft(0.001);}
                      }
                 
                    Sandcastle.addToolbarButton('click to spin', function(){
                       addSpinCameraEvent();
                      
                    });
                    
                    Sandcastle.addToolbarButton('click to stop', function(){
                        removeSpinCameraEvent();
                    }); 

```

Thanks,  
Kulvinder
