Your Name
2022-03-14 aaebe147d319e59a8b510ff4ce9271088a330732
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { Cesium } from "@/global";
import dayjs from "dayjs";
import * as R from "ramda";
 
Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI1NjM5MjMxOS1lMWVkLTQyNDQtYTM4Yi0wZjA4ZDMxYTlmNDMiLCJpZCI6MTQ4MiwiaWF0IjoxNTI4Njc3NDQyfQ.vVoSexHMqQhKK5loNCv6gCA5d5_z3wE2M0l_rWnIP_w";
 
/**
 * 获取CESIUM开始时钟
 * @param {String | Null} time 时间
 * @param {String | Null} date 日期
 */
function getDayTimeClock(time, date) {
    const dateString =
      dayjs(date || new Date())
        .format("YYYY-MM-DD")
        .toString() +
      "T" +
      (time || "09:30:00");
    const startTime = Cesium.JulianDate.fromDate(new Date(dateString));
    return new Cesium.Clock({ startTime: startTime });
  }
  
/**
 * 获取CESIUM时钟ViewModel
 * @param {String} time 时间
 * @return {Cesium.ClockViewModel}
 */
export function getClockViewModel(time) {
    const startTimeClock = getDayTimeClock(time);
    return new Cesium.ClockViewModel(startTimeClock);
}
 
/**
 * 设置对象属性
 * @param {*} entity 
 * @param {*} properties 
 * @returns 
 */
export function setEntityAttributes(entity, properties) {
    if(!entity || !properties) return;
    if(!entity.attribute.attr) {
        entity.attribute.attr = {};
    }
    for(const key in properties) {
        entity.attribute.attr[key] = properties[key];
    }
}
 
/**
 * Cartesian3转WGS84
 * @param {Cartesian3} point 
 * @return {Object}
 */
export function Cartesian3_to_WGS84(point) {
    if(!point) return null;
    var cartesian33 = new Cesium.Cartesian3(point.x, point.y, point.z || 0.0);
    var cartographic = Cesium.Cartographic.fromCartesian(cartesian33);
    var lat = Cesium.Math.toDegrees(cartographic.latitude);
    var lng = Cesium.Math.toDegrees(cartographic.longitude);
    var alt = cartographic.height;
    return {
        x: lng,
        y: lat,
        z: alt
    };
}
 
let entity = null;
export function viewerflyToLonLat(viewer, lon, lat, alt, heading, pitch) {
    if (!viewer) return;
    if (entity) viewer.entities.remove(entity);
    entity = new Cesium.Entity({
        id: "flyTmp",
        position: Cesium.Cartesian3.fromDegrees(lon, lat),
        point: {
            pixelSize: 0,
            color: Cesium.Color.WHITE.withAlpha(0),
        },
    });
    viewer.entities.add(entity);
    viewer.flyTo(entity, {
        offset: {
            heading: Cesium.Math.toRadians(heading || 0.0),
            pitch: Cesium.Math.toRadians(pitch || -90),
            range: alt,
        },
    });
}
 
 
export function updateImageLayerStyle(viewer, layerId, option) {
    if (!viewer) return;
    const layer = viewer.imageryLayers.get(layerId);
    if (!layer) return;
    for (const key in option) {
        layer[key] = option[key];
    }
}
 
/**
 * 根据中心点创建多边形动画
 * @param {*} center
 * @param {*} option
 * @param {*} entities
 */
 export function createAnimateShapeByCenter(center, option, entities) {
    if (!center || center.x === undefined) return dataSource;
    const _option = R.merge(
        {
            minHeight: 1,
            maxHeight: 90,
            repeat: [2, 1],
            color: "#8BDBFA",
            duration: 2000,
            opacity: 0.6,
            radius: 100,
        },
        option
    );
    const point = turf.point([center.x, center.y]);
    const buffered = turf.buffer(point, _option.radius, { units: "meters" });
    const points = buffered.geometry.coordinates[0];
    const _points = [];
    const minHeights = [];
    const maxHeights = [];
    for (let i = 0; i < points.length; i++) {
        _points.push(points[i][0], points[i][1]);
        if (points[i][2] !== undefined) {
            minHeights.push(points[i][2]);
        } else {
            minHeights.push(_option.minHeight);
        }
        maxHeights.push(_option.maxHeight);
    }
 
    return entities.add({
        wall: {
            positions: Cesium.Cartesian3.fromDegreesArray(_points),
            maximumHeights: maxHeights,
            minimumHeights: minHeights,
            material: new wutu3d.LineFlowMaterial({
                //动画线材质
                color: new Cesium.Color.fromCssColorString(_option.color).withAlpha(
                    _option.opacity
                ),
                duration: _option.duration,
                url: `./images/fence.png`,
                repeat: new Cesium.Cartesian2(_option.repeat[0], _option.repeat[1]),
                axisY: true,
            }),
        },
    });
}
 
/**
 * 检查坐标值
 * @param {Number} x 经度
 * @param {Number} y 纬度
 */
 export function checkWgs84Point(x, y) {
    x = Number(x);
    y = Number(y);
    return (
        x !== null &&
        y !== null &&
        x !== "" &&
        y !== "" &&
        x !== undefined &&
        y !== undefined &&
        !isNaN(x) &&
        !isNaN(y) &&
        x >= -180 &&
        x <= 180 &&
        y >= -90 &&
        y <= 90
    );
}