geosolution/scene~TraceReplay(layer, options)

过车轨迹类。通过给定的路径,模拟出当前车辆的行驶轨迹,通过setPath设置路径,根据给定的数据进行按距离的回放展示
等距离比例回放:在整段回放轨迹的基础上,根据轨迹回放步数将整段路程分为等距离的n段,每段按照设定的时间完成播放。

Summary

Methods:
simplifyPathData

路径简化,剔除距离太近的点

denoise

当轨迹类options中mode为'time'时,剔除移动速度过高的路径点,实现对点位的去噪。

destroy

销毁轨迹播放

getInterval

获取每次移动的时间间隔

getVectors

获取轨迹所有矢量要素对象,随设置状态不同可能返回空值

off

取消事件

on

事件绑定

pause

暂停

restart

重新播放轨迹.不传如参数,默认为从起点到终点;

resume

APIMethod: resume
暂停后继续播放轨迹.

setEndStyle

设置结束点位符号

setInterval

设定轨迹每移动一步的默认时间间隔

setMiddleStyle

设置节点符号

setMoveStyle

设置移动点位的符号

setPassedStyle

设置路径符号

setPath

设置路径,请确认关键参数已输入,样式设置需要在此方法之前调用

setPathStyle

设置路径颜色,pathLineMode为color时有效,为trail时请使用module:geosolution/scene~TraceReplay#setTrailOptions

setSpeed

设置过车速度

setStartStyle

设置开始点位符号

setStopTime

在卡口点的停留时间设定

setTotalTime

设置按“等时间比例”模式完成轨迹的总时间

setTrailOptions

设置路径动画,pathLineMode为trail时有效,为color时请使用module:geosolution/scene~TraceReplay#setPathStyle

setTranceStep

按距离回放中设定完成轨迹的步数,默认为1000步

showPassedPath

设置是否显示已完成的轨迹线

showPath

设置是否显示完整的轨迹线

start

开始播放轨迹.

stop

停止播放轨迹.

zoomToExt

缩放至当前轨迹范围

Constructor

new TraceReplay(layer, options)

Parameters:
Name Type Description
layer module:layer~VectorLayer

已添加到地图上的矢量图层

options Object

可选项

Name Type Description
mode Object

支持"time"(通过自定义时间戳time指定),"distance"(等步长运动,默认)

fitToExtent Boolean

【首次设置路径数据】是否缩放到当前轨迹范围。默认true,为true时初始化数据后将重设地图中心点和范围。

pathData Object

可选项(可以通过接口附加数据),路径数据格式参考setPath

callbackMiddle function

在路线节点处触发的事件,可以通过on/off方法进行绑定/解绑

callbackStep function

每移动一次都会触发,事件绑定/解绑方式同上

interval Number

每移动一次的间隔,默认60ms

stopTime Number

在节点处的停顿时间,单位秒,为0

showMiddlePoint Boolean

是否显示节点(开始和结束节点除外),默认为false,只能在setPath之前调用

showMovingOnPath Boolean

是否显示移动对象,默认为true,只能在setPath之前调用

showPassed Boolean

是否显示走过的路径,默认为false

autoRotate Boolean

移动点位是否自动计算旋转,默认为true,即指向屏幕上边框方向

pathLineMode Boolean

轨迹的形态,当前支持'color'(默认),'trail',注意'trail'模式下不支持z值

trailOptions Object

当pathLineMode为'trail'时有效,且是必须的,参数设置参考module:geosolution/cell~Trail

Example
let trace=new hmap.geosolution.scene.TraceReplay(layer,options);

Methods

static simplifyPathData(data, tolerance) → {Object}

路径简化,剔除距离太近的点

Parameters:
Name Type Default Description
data Object

路径数据

tolerance * 0.00001

简化所用容差值,大于等于0,单位和地图单位一致,可以通过地图对象上的getDegreePerMeter和getMeterPerDegree方法,对地图单位进行度和米的转换,默认值0.00001。

Returns:
Object -

简化之后的路径

Example
data = [{
                "id": "K1",
                "latitude": "30.222066",
                "longitude": "120.20474",
                "label": "K1"
            }, {
                "id": "K2",
                "latitude": "30.258439",
                "longitude": "120.206797",
                "label": "K2"
            },  {
                "id": "K3",
                "latitude": "30.258439",
                "longitude": "120.206797",
                "label": "K3"
            }];
        const simpData = hmap.geosolution.scene.TraceReplay.simplifyPathData(data); //会剔除掉k2

denoise(threshold) → {Array}

当轨迹类options中mode为'time'时,剔除移动速度过高的路径点,实现对点位的去噪。

Parameters:
Name Type Description
threshold Number

轨迹移动的最高速度,单位(m/s);

Returns:
Array -

去噪后的路径点数组

Example
data = [{
                "id": "K1",
                "latitude": "30.122066",
                "longitude": "120.00394",
                "z": 0,
                "label": "K1",
                "time": 1523930914207
            }, {
                "id": "K2",
                "latitude": "30.12395149",
                "longitude": "120.00394",
                "z": 0,
                "label": "K2",
                "time": 1523930924207
            }, {
                "id": "K3",
                "latitude": "30.12513323",
                "longitude": "120.00458312",
                "z": 0,
                "label": "K3",
                "time": 1523930964207
            }, {
                "id": "K4",
                "latitude": "30.12294061",
                "longitude": "120.00489448",
                "z": 0,
                "label": "K4",
                "time": 1523931004207
            }, {
                "id": "K5",
                "latitude": "30.12165288",
                "longitude": "120.00888876",
                "z": 0,
                "label": "K5",
                "time": 1523931012207
            }];
        let trace=new hmap.geosolution.scene.TraceReplay(layer,options);
        const denoiseData = trace.denoise(27.78); //设置最高速度为27.78米/s(100公里/小时)会剔除掉k5

destroy()

销毁轨迹播放

getInterval() → {Number}

获取每次移动的时间间隔

Returns:
Number

getVectors() → {Object}

获取轨迹所有矢量要素对象,随设置状态不同可能返回空值

Returns:
Object -

{startVector:起点,endVector:终点,middleVector:中间节点,moveVector:移动的点位,pathVector:完整轨迹线,passedVector:已经走过的轨迹线}

off()

取消事件

on(type, callack)

事件绑定

Parameters:
Name Type Description
type String

仅支持“callbackMiddle”和“callbackStep”,'start','end'

callack function

pause()

暂停

restart(startIndex, endIndex)

重新播放轨迹.不传如参数,默认为从起点到终点;

Parameters:
Name Type Description
startIndex Number

开始播放点的下标

endIndex Number

结束播放点的下标

resume()

APIMethod: resume
暂停后继续播放轨迹.

setEndStyle(style)

设置结束点位符号

Parameters:
Name Type Description
style module:style~Style

setInterval(time)

设定轨迹每移动一步的默认时间间隔

Parameters:
Name Type Description
time Number

setMiddleStyle(style)

设置节点符号

Parameters:
Name Type Description
style module:style~Style

setMoveStyle(style)

设置移动点位的符号

Parameters:
Name Type Description
style module:style~Style

setPassedStyle(style)

设置路径符号

Parameters:
Name Type Description
style module:style~Style

setPath(data)

设置路径,请确认关键参数已输入,样式设置需要在此方法之前调用

Parameters:
Name Type Description
data Object

路径点的数组

Example
//1,按照距离模式
let data=[{
     "id" : "K1",  //点位id
     "latitude" : "3656947", //坐标点纬度坐标
     "longitude" : "13519927", //经度
     "label" : "111",  //显示的标签
 },{
     "id" : "K2",
     "latitude" : "3658227",
     "longitude" : "13522277",
     "label" : "333",
 }];

//2,按照时间模式,需要传入时间戳
let data = [ {
     "id" : "K1",
     "latitude" : "3658227",
     "longitude" : "13522277",
     "label" : "333",
     "time" :1523930914207  //按照时间模式,必须指定
 },{
     "id" : "K2",
     "latitude" : "3658227",
     "longitude" : "13522277",
     "label" : "333",
     "time" :1523930919207
}];

setPathStyle(style)

设置路径颜色,pathLineMode为color时有效,为trail时请使用module:geosolution/scene~TraceReplay#setTrailOptions

Parameters:
Name Type Description
style module:style~Style

setSpeed(speedNum)

设置过车速度

Parameters:
Name Type Description
speedNum Number

轨迹移动倍率,默认1,speedNum大于1表示加速,小于1表示减速,<=0的设置无效.

Example
trace.setSpeed(2); //2倍率速度播放

setStartStyle(style)

设置开始点位符号

Parameters:
Name Type Description
style module:style~Style

setStopTime(timeSnap)

在卡口点的停留时间设定

Parameters:
Name Type Description
timeSnap

setTotalTime(time)

设置按“等时间比例”模式完成轨迹的总时间

Parameters:
Name Type Description
time Number

请注意,该值存在一临界值(基于实际数据计算),小于该值时无效

setTrailOptions(options)

设置路径动画,pathLineMode为trail时有效,为color时请使用module:geosolution/scene~TraceReplay#setPathStyle

Parameters:
Name Type Description
options Object

参数设置参考module:geosolution/cell~Trail

setTranceStep(step)

按距离回放中设定完成轨迹的步数,默认为1000步

Parameters:
Name Type Description
step Number

showPassedPath(flag)

设置是否显示已完成的轨迹线

Parameters:
Name Type Description
flag Boolean

showPath(flag)

设置是否显示完整的轨迹线

Parameters:
Name Type Description
flag Boolean

start()

开始播放轨迹.

stop()

停止播放轨迹.

zoomToExt()

缩放至当前轨迹范围