月球大数据地理空间分析展示平台-【前端】-月球2期前端
Surpriseplus
2023-10-10 77f9937b32f67f5b7d5476b0a1db19956702c0c8
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import store from "@/store";
var temporaryTool = {
    isedit: false,
    removeTemporaryLayer(res) {
        var entities = window.Viewer.entities._entities._array;
        for (var i in entities) {
            if (entities[i].id == res.id && entities[i].shpType == res.shpType) {
                window.Viewer.entities.remove(entities[i])
            }
        }
    },
    addTemporaryTool(res) {
        switch (res.type) {
            case "point":
                this.addTemporaryPointLayer(res);
                break;
            case "label":
                this.addTemporaryLabelLayer(res);
                break;
            case "polygon":
                this.addTemporaryPolygonLayer(res);
                break;
            case "polyline":
                this.addTemporaryPolylineLayer(res);
                break;
            case "rectangle":
                this.addTemporaryRectangleLayer(res);
                break;
        }
    },
    addTemporaryLabelLayer(res) {
        var heightReference;
        if (res.heightReference) {
            heightReference = null;
        } else {
            heightReference = Number.POSITIVE_INFINITY;
        }
        var style;
        if (res.style) {
            style = Cesium.LabelStyle.FILL_AND_OUTLINE
        } else {
            style = Cesium.LabelStyle.FILL
        }
 
        window.Viewer.entities.add({
            name: res.cnName,
            id: res.id,
            shpType: res.shpType,
            position: Cesium.Cartesian3.fromDegrees(
                res.geometry.lng,
                res.geometry.lat
            ),
            label: {
                text: res.text,
                font: res.font,
                fillColor: Cesium.Color.fromCssColorString(res.material).withAlpha(
                    res.materialAlpha
                ),
                backgroundColor: Cesium.Color.fromCssColorString(
                    res.backColor
                ).withAlpha(res.backColor),
                showBackground: res.showBackground,
 
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                    res.near,
                    res.far
                ),
                outlineColor: Cesium.Color.fromCssColorString(
                    res.outlineColor
                ).withAlpha(res.outlineAlpha),
 
                outlineWidth: res.outlineWidth,
                scale: res.scale,
                style: style,
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER,//对齐方式
                verticalOrigin: Cesium.VerticalOrigin.CENTER,
                disableDepthTestDistance: heightReference // 被遮挡是否可见(也就是将这个Entity在场景中置顶)
            },
        });
    },
    addTemporaryPointLayer(res) {
        var heightReference;
        if (res.heightReference) {
            heightReference = null;
        } else {
            heightReference = Number.POSITIVE_INFINITY;
        }
        window.Viewer.entities.add({
            name: res.cnName,
            id: res.id,
            shpType: res.shpType,
            position: Cesium.Cartesian3.fromDegrees(
                res.geometry.lng,
                res.geometry.lat,
                res.geometry.alt
            ),
            point: {
                color: Cesium.Color.fromCssColorString(res.material).withAlpha(
                    res.materialAlpha
                ),
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                    res.near,
                    res.far
                ),
                outlineColor: Cesium.Color.fromCssColorString(
                    res.outlineColor
                ).withAlpha(res.outlineAlpha),
                outlineWidth: res.outlineWidth,
                pixelSize: res.size,
 
                disableDepthTestDistance: heightReference // 被遮挡是否可见(也就是将这个Entity在场景中置顶)
            },
        });
    },
    addTemporaryPolygonLayer(res) {
        window.Viewer.entities.add({
            name: res.cnName,
            id: res.id,
            shpType: res.shpType,
            polygon: {
                hierarchy: {
                    positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
                },
                material: Cesium.Color.fromCssColorString(res.metaColor).withAlpha(
                    res.metaAlpha
                ),
                outline: true,
                outlineColor: Cesium.Color.fromCssColorString(
                    res.outlineColor
                ).withAlpha(res.outlineAlpha),
            },
        });
    },
    addTemporaryPolylineLayer(res) {
        var outlinewidth = 0
        if (res.outline) {
            outlinewidth = res.outlineWidth
 
        }
        window.Viewer.entities.add({
            name: res.cnName,
            id: res.id,
            shpType: res.shpType,
            polyline: {
                positions: Cesium.Cartesian3.fromDegreesArray(res.geometry),
                width: res.width,
 
                material: new Cesium.PolylineOutlineMaterialProperty({
                    color: Cesium.Color.fromCssColorString(res.material).withAlpha(
                        res.materialAlpha
                    ),
                    // 设置中间间隙的颜色
                    outlineWidth: outlinewidth,
                    outlineColor: Cesium.Color.fromCssColorString(res.outlineColor).withAlpha(
                        res.outlineAlpha
                    ),
                }),
 
                clampToGround: res.heightReference,
            },
        });
    },
    addTemporaryRectangleLayer(res) {
 
        const rectangle = new Cesium.Entity({
            name: res.cnName,
            id: res.id,
            shpType: res.shpType,
            rectangle: {
                coordinates: Cesium.Rectangle.fromDegrees(res.geometry[0],
                    res.geometry[1],
                    res.geometry[2],
                    res.geometry[3]),
                material: Cesium.Color.fromCssColorString(res.metaColor).withAlpha(
                    res.metaAlpha
                ),
                outlineColor: Cesium.Color.fromCssColorString(
                    res.outlineColor
                ).withAlpha(res.outlineAlpha),
 
            }
        });
        window.Viewer.entities.add(rectangle)
    },
 
    getEntityObj(res) {
        var entity = null;
        var entities = window.Viewer.entities._entities._array;
        for (var i in entities) {
            if (entities[i].id == res && entities[i].shpType == 'temporaryLayer') {
                entity = entities[i];
            }
        }
        var obj = null;
        if (entity) {
            this.isedit = true;
            switch (entity.GeoType) {
                case "point":
                    obj = this.getPointEntityObj(entity);
                    break;
                case 'label':
                    obj = this.getLabelEntityObj(entity);
                    break;
                case 'polyline':
                    obj = this.getPolylineEntityObj(entity);
                    break;
            }
        }
        return obj;
    },
    setInsertEntityObj(type, res) {
        var obj = null;
        this.isedit = false;
        store.state.temporaryLayer = null;
        switch (type) {
            case 'point':
                obj = this.getPointEntityObj(res);
                break;
            case 'label':
                obj = this.getLabelEntityObj(res);
                break;
            case 'polyline':
                obj = this.getPolylineEntityObj(res);
                break;
        }
 
        store.state.temporaryLayer = obj;
        sgworld.Creator.SimpleGraphic.clear();
    },
    getPolylineEntityObj(res) {
        var mataColor = res.polyline.material.color._value;
        var outlineColor = res.polyline.material.outlineColor._value;
        var val = res.polyline.positions.getValue();
        var geom = [];
        for (var i in val) {
            var coord = this.setCartesianToEightFour(val[i])
            geom.push(coord.lng, coord.lat)
        }
 
        return {
            id: this.isedit ? res.id : (new Date()).getTime(),
            cnName: res.name,
            type: 'polyline',
            shpType: 'temporaryLayer',
            layerType: '线',
            geometry: geom,
            heightReference: res.polyline.clampToGround._value,
            outline: res.outline != null ? res.outline : false,
            width: res.polyline.width._value,
            material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
            outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
            materialAlpha: mataColor.alpha,
            outlineAlpha: outlineColor.alpha,
        }
    },
    getLabelEntityObj(res) {
        var mataColor = res.label.fillColor._value;
        var outlineColor = res.label.outlineColor._value;
        var backColor = res.label.backgroundColor._value;
        var outline = false;
        if (res.label.style && res.label.style > 0) {
            outline = true
        }
        var width = 0;
        if (res.label.outlineWidth && res.label.outlineWidth._value) {
            width = res.label.outlineWidth._value
        }
 
        return {
            id: this.isedit ? res.id : (new Date()).getTime(),
            cnName: res.name,
            text: res.label.text._value,
            font: res.label.font._value,
            materialAlpha: mataColor.alpha,
            outlineAlpha: outlineColor.alpha,
            backAlpha: backColor.alpha,
            backColor: this.colorRgbToHex('rgb(' + (backColor.red * 255) + ',' + (backColor.green * 255) + ',' + (backColor.blue * 255) + ')'),
            material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
            outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
            scale: res.label.scale._value,
            heightReference: res.label.disableDepthTestDistance != null ? false : true,
            width: width,
            showBackground: false,
            outline: outline,
            near: res.label._distanceDisplayCondition._value.near,
            far: res.label._distanceDisplayCondition._value.far,
            geometry: this.setCartesianToEightFour(res.position.getValue()),
            type: 'label',
            shpType: 'temporaryLayer',
            layerType: '文本点',
        }
    },
 
    getPointEntityObj(res) {
        var mataColor = res.point.color._value;
        var outlineColor = res.point.outlineColor._value;
        return {
            id: this.isedit ? res.id : (new Date()).getTime(),
            cnName: res.name,
            materialAlpha: mataColor.alpha,
            material: this.colorRgbToHex('rgb(' + (mataColor.red * 255) + ',' + (mataColor.green * 255) + ',' + (mataColor.blue * 255) + ')'),
            outlineColor: this.colorRgbToHex('rgb(' + (outlineColor.red * 255) + ',' + (outlineColor.green * 255) + ',' + (outlineColor.blue * 255) + ')'),
            outlineAlpha: outlineColor.alpha,
            outlineWidth: res.point.outlineWidth._value,
            near: res.point._distanceDisplayCondition._value.near,
            far: res.point._distanceDisplayCondition._value.far,
            geometry: this.setCartesianToEightFour(res.position.getValue()),
            width: res.point.outlineWidth._value != null ? res.point.outlineWidth._value : 0,
            outline: res.point.outlineWidth._value != null ? true : false,
            type: 'point',
            shpType: 'temporaryLayer',
            layerType: '基本点',
            heightReference: res.point.disableDepthTestDistance != null ? false : true,
            size: res.point.pixelSize._value,
        }
    },
 
    colorRgbToHex(str) {
 
        let reg = /^(rgb|RGB)/;
        if (!reg.test(str)) { return; }
        var rgb = str.slice(4, str.length - 1).split(",")
        // 将RGB色号拆分为红、绿、蓝三个通道的值
        var r = parseInt(rgb[0]);
        var g = parseInt(rgb[1]);
        var b = parseInt(rgb[2]);
        return "#" + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0');
    },
 
    setCartesianToEightFour(res) {
        var std = {}
        let ellipsoid = Viewer.scene.globe.ellipsoid
        let cartographic = ellipsoid.cartesianToCartographic(res)
        std.lat = Cesium.Math.toDegrees(cartographic.latitude)
        std.lng = Cesium.Math.toDegrees(cartographic.longitude)
        std.alt = cartographic.height
        return std
    },
};
export default temporaryTool;