Hi all,
How to trigger a function call when the clock bar of Cesium Viewer reaches a certain time?
For example, trigger function foo1() at 1pm, and trigger function foo2() at 2pm.
Thanks in advance.
Steve
Hi all,
How to trigger a function call when the clock bar of Cesium Viewer reaches a certain time?
For example, trigger function foo1() at 1pm, and trigger function foo2() at 2pm.
Thanks in advance.
Steve
You can subscribe to the clock ‘onTick’ event. This will fire every time the time changes.
viewer.clock.onTick.addEventListener(function(clock) {
var currentTime = clock.currentTime;
});
Then, in the callback function, you can use the currentTime (which is a JulianDate object) to decide which function to call.
Thanks for the reply, Scott. I have another problem.
If I explicitly define a listener function with a parameter, then add listener function to the clock’s onTick event(like the code below), how do I pass the parameter that the listener function needs since the clock’s onTick event is triggered by the changing of time?
var myListener = function (data){
//process the data
}
viewer.clock.onTick.addEventListener(myListener);
Thanks in advance.
Steven
在 2014年2月3日星期一UTC-8上午11时52分10秒,Scott Hunter写道:
Can someone help please?Thanks.
在 2014年2月12日星期三UTC-8上午1时24分42秒,Steven写道:
It seems Your question is not about Cesium. Is it about closure in javascript? This case use closure.
The “data” variable in your function is actually an instance of the clock.
var myListener = function (clock){
if(clock.currentTime.greaterThanOrEquals(someTime)){
//Do something
}
}
Thanks Matt.
I think I used the onTick.addEventListener incorrectly. By that, I meant I did not use it the way onTick.addEventListener was designed to be used.
在 2014年2月13日星期四UTC-8上午6时05分50秒,Matthew Amato写道:
It is not about the closure problem, but thanks for your reply.
在 2014年2月13日星期四UTC-8上午6时01分09秒,Алексей Кузнецов写道:
Hi Steve I know this post is old, but I'm looking for the same thing today.
Do you know how to trigger a function every hour based on clock onTick event ? Can you help me ? thx
I'm trying to update the elements on my cesium app every hour based on some data on database.
Regards,
Shengda Liu
Hi there,
There are many ways to achieve this effect depending on your use case. Ideas include:
Subscribing to the onTick function and checking when an hour has passed to call your function.
Using SetInterval()
Using Cesium’s Entity API to define how your geometry should behave over time, if you know the behavior ahead of time.
Hope that helps,