Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda