Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Rotate globe in cesium map

I'm rotating my Cesium globe through this code:

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

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

Now I want to stop it, so how I can I stop this globe rotation on a particular event?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There's a removeEventListener that needs to be passed a reference to the same function that you provided to addEventListener.

Here's a Sandcastle Demo. Note that this demo does not protect against the user clicking "Spin" multiple times, so the user will need to hit "Stop" an equal number of times. Real (non-demo) code should take care not to add multiple event listeners for the same event.

var viewer = new Cesium.Viewer("cesiumContainer");

var previousTime = Date.now();
var spinRate = 1.0;

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

function startSpinGlobe() {
    previousTime = Date.now();
    viewer.clock.onTick.addEventListener(applyGlobeSpin);
}

function stopSpinGlobe() {
    viewer.clock.onTick.removeEventListener(applyGlobeSpin);
}

Sandcastle.addToolbarButton("Spin", startSpinGlobe);
Sandcastle.addToolbarButton("Stop", stopSpinGlobe);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!