/** * Animate topmost map layer if it is time aware layer, for example from http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi * 2017-03-02 Piotr Szrajber <piotr.szrajber@hexagongeospatial.com> * */varT=Intergraph.WebSolutions.Core.WebClient.Platform.Common.TemporalUtils,mapState=$mapStateManager.findMapState("map"),mapControl=mapState.get_mapControl(),mapLayer=mapControl.get_mapLayers().slice(-1)[0],config=mapLayer.get_config(),legend=mapState.get_legend().get_flatLegend(),legendItem=legend.find(function(legendItem){returnlegendItem.get_priority()===config.get_priority();}),definition=legendItem.get_definition(),dimension=definition.get_dimensions().time,extent=dimension.extent[0],timeFormat=config.get_timeFmt(),dateMin=T.parseDateTimeStr(extent.min),dateMax=T.parseDateTimeStr(extent.max),time=newDate(dateMin),step=T.unitPerResolution[extent.res]||300000,// make sure that the step is defined and the resolution is defined for this resolutionpreloadSize=100,interval=null;functionpreloadNext(){varpreload=Array.apply(null,{length:preloadSize}).map(Number.call,Number).map(function(x){returnnewDate(x*step+time.getTime())}).map(getUrl);preload.forEach(function(x){vari=newImage();i.src=x;})}functionnext(){time.setTime(dateMin.getTime()+step);mapLayer.updateTimeAndRender(time,timeFormat);}functiongetFormattedTime(t){returnmapLayer.get_config().getFormattedTime.call({_time:t,_timeFmt:timeFormat,get_mapService:function(){returnconfig.get_mapService()}});}functiongetUrl(t){returnmapLayer.getURL(mapState.get_mapRange()).replace(/(&TIME=)[^$&]*/,'$1'+getFormattedTime(t));}functionstartAnimation(){interval=setInterval(next,1500);}functionstopAnimation(){interval&&clearInterval(interval);interval=null;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.