admin管理员组文章数量:1432213
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 badges1 Answer
Reset to default 6In 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.
本文标签: javascriptCesium handle viewer animation playingpauseStack Overflow
版权声明:本文标题:javascript - Cesium handle viewer animation playingpause - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745576554a2664364.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论