Set start time for refreshInterval

903
4
06-10-2014 07:07 AM
YinghongLi
Occasional Contributor
Hello All,

My app's data updates every 15 minutes starting at top of the hour.  I want to set a start time for refreshInterval so whenever a map is loaded,  a start time is set.  For example, if map is loaded at 9:04 am  I want to set the map refresh starting time at 9:20 am (data will start to refresh at 9:15 am and it may take up to 5 minutes to finish calculation).  Then set the  refreshInterval to 15 minutes.  this way does not matter when user loads the map the map will be updated every 15 minutes with new data.  it is very important that user can view the latest data.

However I did not find any thing in map or layer object which allows me to set the start time.  At moment I do not know what to do except to write my own update function.  Please help.
0 Kudos
4 Replies
DasaPaddock
Esri Regular Contributor
You could use setTimeout to schedule when to call setRefreshInterval on the layer.
0 Kudos
YinghongLi
Occasional Contributor
I checked setTimeout function.  It does not set a start time.  It just runs a function after the given time.  What I need is something like window' scheduler.  I can set a start time.  from the start time every 15 minutes the map will refresh.  More help is needed.

Thanks
0 Kudos
JeffPace
MVP Alum
setTimeout is what you need.  You will just have to calculate the current time, and do some math.

use javascripts date object and .getMinutes() methods to get the minutes of the hour.  Then use how many minutes until 15,30,45,60,0 etc to calculate how long to setTimeout.
0 Kudos
DasaPaddock
Esri Regular Contributor
I would caution against this approach if you have a lot of users since they'll all then be hitting your server at the same time.
0 Kudos