cshenfu
2022-11-03 e9ab53b5bcb031ac7e6b1dcb596eb7d21ff8d1ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use script'; //开发环境建议开启严格模式
 
function getPositionFromLonLat(in_json_string) {
    let postion = [];
    var points = in_json_string.split(",");
    points.forEach(element => {
        var tmplon_lat = element.split(" ");
        postion[postion.length] = [tmplon_lat[0], tmplon_lat[1], 1];
    });
    return postion;
}
 
function getClass(o) { //判断数据类型
    return Object.prototype.toString.call(o).slice(8, -1);
}
 
function deepCopy(obj) {
    var result, oClass = getClass(obj);
 
    if (oClass == "Object") result = {}; //判断传入的如果是对象,继续遍历
    else if (oClass == "Array") result = []; //判断传入的如果是数组,继续遍历
    else return obj; //如果是基本数据类型就直接返回
 
    for (var i in obj) {
        var copy = obj[i];
 
        if (getClass(copy) == "Object") result[i] = deepCopy(copy); //递归方法 ,如果对象继续变量obj[i],下一级还是对象,就obj[i][i]
        else if (getClass(copy) == "Array") result[i] = deepCopy(copy); //递归方法 ,如果对象继续数组obj[i],下一级还是数组,就obj[i][i]
        else result[i] = copy; //基本数据类型则赋值给属性
    }
 
    return result;
}