javascript - Cesium handle viewer animation playingpause - Stack Overflow

There is a few ways that i see to handle playingpause animation in Cesium.First - is to bind event li

There is a few ways that i see to handle playing/pause animation in Cesium. First - is to bind event listeners to all buttons that could start/stop animation, like this:

let ctrls = document.getElementsByClassName("CONTROLS_THAT_COULD_CHANGE_ANIMATING_STATE");
Array.from(classname).forEach(function(ctrls) {
  element.addEventListener('click', () => {
    /* handle change animating state */
  });
});

But I think it is a little brutal.

Another way is to use cesium clock and its onTick event

viewer.clock.onTick.addEventListener((clock) => {
  console.log(clock._shouldAnimate);
});

This decision would be good if not lodash in the attribute title, which says that the developers of cesium let us know, not to use this.

So, Im interested what is really proper way to handle animation playing/pause in Cesium.

There is a few ways that i see to handle playing/pause animation in Cesium. First - is to bind event listeners to all buttons that could start/stop animation, like this:

let ctrls = document.getElementsByClassName("CONTROLS_THAT_COULD_CHANGE_ANIMATING_STATE");
Array.from(classname).forEach(function(ctrls) {
  element.addEventListener('click', () => {
    /* handle change animating state */
  });
});

But I think it is a little brutal.

Another way is to use cesium clock and its onTick event

viewer.clock.onTick.addEventListener((clock) => {
  console.log(clock._shouldAnimate);
});

This decision would be good if not lodash in the attribute title, which says that the developers of cesium let us know, not to use this.

So, Im interested what is really proper way to handle animation playing/pause in Cesium.

Share Improve this question asked May 30, 2018 at 12:58 Sasha KosSasha Kos 2,6082 gold badges25 silver badges41 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

In addition to the Clock, Cesium Viewer also maintains a ClockViewModel, which is the UI binding for the clock. ClockViewModel has a Boolean property called shouldAnimate that indicates whether the clock is currently animating. The documentation for shouldAnimate has a little note at the end that says:

This property is observable.

Internally, Cesium is using Knockout observables to bind view models to the UI. So we need to go get that observable, and observe it.

Live Demo - Sandcastle

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

Cesium.knockout.getObservable(viewer.clockViewModel,
                              'shouldAnimate').subscribe(function(isAnimating) {
    if (isAnimating) {
        console.log('Cesium clock is animating.');
    } else {
        console.log('Cesium clock is paused.');
    }
});

In addition to this, you can add your own play/pause controls of any type, that write a Boolean value to shouldAnimate, like this:

function onMyCustomPlayButtonClicked() {
    viewer.clockViewModel.shouldAnimate = true;
}

When doing this, your own play/pause controls will do more than just control the play/pause state, they will affect the visual highlights of the original play/pause controls as well, because those controls are also listening to the observable. Thanks to Knockout, the subscription only fires when the state actually changes, so a user repeatedly clicking the play button will not generate multiple callbacks.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745576555a4633998.html

相关推荐

  • javascript - Cesium handle viewer animation playingpause - Stack Overflow

    There is a few ways that i see to handle playingpause animation in Cesium.First - is to bind event li

    12小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信