您的位置:首页 > Web前端 > JavaScript

使用JavaScript控制WebGIS电子地图中轨迹回放的速度 - window.setInterval 控制执行速度

2007-11-24 09:37 811 查看
(January 11) http://www.handandaily.com

我在做WebGIS轨迹回放的时候使用到了window.setInterval,因为需要轨迹动态的回放,空之轨迹回放的速度,所以需要使用window.setInterval.

我们看一下语法:

iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])

Parameters


vCodeRequired. [b]Variant that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSecondsRequired. Integer that specifies the number of milliseconds.
sLanguageOptional. String that specifies any one of the possible values for the LANGUAGE attribute.

Return Value


Integer. Returns an identifier that cancels the timer with the clearInterval method. [/b]

我在搜索的时候,搜索到了Flash中的setInterval,它说明了这个问题的根源,如果你一直对时间进行设置,速度会越来越快,setInterval会叠加.你按多次1就等多执行一次serInterval.时间间隔就缩短了.最好是判断按1后先清除已定义的setInterval

使用 clearInterval 语句,可以清除一个使用 setInterval 语句创建出来的自循环执行对象。参数(intervalID) 是 setInterval 语句创建该循环执行对象时产生的一个对象标记,它指定了要清除的自循环执行对象。
在使用setinterval之前,我的习惯是一定要执行一下clearInterval

更多的WebGIS应用和轨迹回放可以访问我的网站:
http://www.handandaily.com/post/WebGIS.html

发一部分代码给大家吧.

var coodIndex=0;
var oInterval="";
//开始启动添加轨迹点
function addTrackPoint(latlons,title,times)
{
UploadInternal();

//使用匿名函数
oInterval=window.setInterval(function ()
{
addTrack(latlonArray,title,dateSpeedArray);
},times);
}
//添加轨迹点
function addTrack(latlon,title,content)
{
if(coodIndex<(latlon.length-1))
{
//display map
}
else
{
//卸载该事件,timer
UploadInternal();
}
}
//停止轨迹回放
function UploadInternal()
{
window.clearInterval(oInterval);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐