let currentUsers = []

/*
    {
        "createTime": "2023-09-27 14:15:06",
        "lng": "117.641188",
        "lat": "35.5059383",
        "createId": "a33cdcc8-24aa-4d72-92bb-2399ec831db2",
        "name": "汪键波",
        "phone": "18263982658"
    }
*/
export function handlerData(newUsers){
    // 判断是否是第一次传入
    if(currentUsers.length == 0){
        currentUsers = newUsers;
    }

    // 添加数据
    for(let i=0;i<newUsers.length;i++){
        let obj = currentUsers.find((item,index)=>{
            return item.createId == newUsers[i].createId;
        })
        if(!obj){
            currentUsers.push(newUsers[i]);
        }
    }

    // 更新和删除数据
    for(let i=0;i<currentUsers.length;i++){
        for(let j=0;j<newUsers.length;j++){
            // 如果在新数据中有则更新数据
            if(currentUsers[i].createId == newUsers[j].createId){
                currentUsers[i] = newUsers[j];
            }else{ // 如果在新数据中没有则删除数据
                currentUsers.slice(j,1);
            }
        }
    }

    return currentUsers;
}


export function updateGraphic(graphicLayer,currentUsers){
    // graphicLayer.eachGraphic((graphic) => {
    //     let obj = currentUsers.find((item,index)=>{
    //         return item.createId == graphic
    //     })
    //     if (graphic.isPrivate) {
    //         return
    //     }
    //     graphic.addDynamicPosition(position, time) // 按time秒运动至指定位置
    // })
}






