2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
let construct3DRectangle = function (options) {
    let dx = options.xMax - options.xMin;
    let dy = options.yMax - options.yMin;
    let width = options.width;
    let height = options.height;
    let gx = dx / width;
    let gy = dy / height;
 
    let wgwidth = width;
    let wgheight = height + 1;
 
    let positions = [];
    let st = [];
    let indexs = [];
    
    //
    for (let i = 0; i < wgheight; i++) {
        for (let j = 0; j < wgwidth; j++) {
            let degx = options.xMin + gx * j;
            let degy = options.yMin + gy * i;
            /**
             * 计算结果
             */
            let result = getValueFromDegrees({ lon: degx, lat: degy });
            // if (!result.tooFar) {
            let point = Cesium.Cartesian3.fromDegrees(
                degx,
                degy,
                // (getValueFromDegrees({ lon: degx, lat: degy }) || 0) * options.scale + options.z
                result.minDistanceHeight
            );
 
            positions.push(point.x, point.y, point.z);
 
            st.push((gx * j) / dx, (gy * i) / dy);
 
            if (i != 0 && j != 0) {
                indexs.push(
                    (i - 1) * wgwidth + (j - 1),
                    (i - 1) * wgwidth + j,
                    i * wgwidth + j - 1
                );
 
                indexs.push(
                    (i - 1) * wgwidth + j,
                    i * wgwidth + j,
                    i * wgwidth + j - 1
                )
            }
            // }
        }
    }
    return {
        positions,
        st,
        indexs,
    };
};
let getValueFromDegrees = function (degrees) {
 
    // return Math.random() * 10 + 340;
    /**
     * 测试 遍历最近点
     */
    let minDistance = 9999999999999;
    let minDistanceHeight = 0;
    for (let k = 0; k < chunkedData.length; k++) {
        let distance = Math.pow((degrees.lon - chunkedData[k][0]), 2) + Math.pow((degrees.lat - chunkedData[k][1]), 2);
        if (distance < minDistance) {
            minDistance = distance;
            minDistanceHeight = chunkedData[k][2];
        }
    }
    return { minDistanceHeight, tooFar: Boolean(minDistance > 0.05) };
 
 
    // if (this.heatmapInstance && this.extent && degrees) {
    //     let x = (degrees.lon - this.extent.xMin) / (this.extent.xMax - this.extent.xMin) * this.heatmapcanvas.width;
    //     let y = (-(degrees.lat - this.extent.yMin) / (this.extent.yMax - this.extent.yMin) + 1) * this.heatmapcanvas.height;
    //     if (x <= this.heatmapcanvas.width && x >= 0 & y <= this.heatmapcanvas.height && y >= 0) {
    //         return this.heatmapInstance.getValueAt({
    //             x: Math.round(x),
    //             y: Math.round(y)
    //         });
    //     }
    // }
}
// getHeatmapData = function (bounds, data, num = 600) {
//     let heatmapData = [];
//     for (let i = 0; i < num; i++) {
//         let x = Math.random() * (bounds.east - bounds.west) + bounds.west;
//         let y = Math.random() * (bounds.north - bounds.south) + bounds.south;
//         let value = data.value || Math.random() * (data.max - data.min) + data.min;
//         heatmapData.push({ x: x, y: y, value: value });
//     }
//     return heatmapData;
// }
let create3DGeometry = function (option) {
    let rect = construct3DRectangle(option);
    let geometry = new Cesium.Geometry({
        attributes: {
            position: new Cesium.GeometryAttribute({
                componentDatatype: Cesium.ComponentDatatype.DOUBLE,
                componentsPerAttribute: 3,
                values: rect.positions,
            }),
            st: new Cesium.GeometryAttribute({
                componentDatatype: Cesium.ComponentDatatype.FLOAT,
                componentsPerAttribute: 2,
                values: rect.st,
            }),
        },
        //索引
        indices: rect.indexs,
        //绘制类型
        primitiveType: option.grid ? Cesium.PrimitiveType.LINES : Cesium.PrimitiveType.TRIANGLES,
        boundingSphere: Cesium.BoundingSphere.fromVertices(rect.positions),
    });
    return geometry;
};