标签:filter gpo nts ret string 距离 try function 通过
有时候地图轨迹采集点不均匀,在做轨迹回放时速度很不均匀,忽快忽慢,通过内插采集点可以平滑播放,代码如下
//points:[turf.point] function interpolation(points){ //获取p1到p2间的最近插入点 const getAlongPoint=(p1,p2,distance)=>{ if(turf.distance(p1,p2,{units: ‘kilometers‘})<distance)return {point:p2,done:true} return {point:turf.along(turf.lineString([p1.geometry.coordinates,p2.geometry.coordinates]),distance,{units: ‘kilometers‘}),done:false} } //获取获取p1到p2间的插入点集合 const getLineInsertPoints=(p1,p2,distance)=>{ const result=[p1] for(let along=getAlongPoint(p1,p2,distance);result.push(along.point),!along.done;along=getAlongPoint(along.point,p2,distance)); return result } //获取points相邻点间最短距离 const getMinDistance=(points)=>{ // const distances=[] // points.reduce((prev,curr)=>{distances.push(turf.distance(prev,curr,{units: ‘kilometers‘}));return curr;}) // return Math.min(...distances.filter(distance=>distance>0)) return 0.01 } const minDistance=getMinDistance(points) //在points所有相邻点间进行插入点操作 let result=[] points.reduce((prev,curr)=>{ result=[...result,...getLineInsertPoints(prev,curr,minDistance)] return curr }) return result }
标签:filter gpo nts ret string 距离 try function 通过
原文地址:https://www.cnblogs.com/zhuxianguo/p/13563136.html