lixuliang
2024-04-19 1fef6dcc04ffe09336e4983c2b05962ad901e545
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
// 垂直飞线
<template>
  <Popup
    ref="pop"
    :title="title"
    :shadow="false"
    :left="left"
    width="310px"
    :showBtn="false"
  >
    <el-form ref="form" :model="data" :rules="rules" label-width="70px">
      <el-form-item label="速度:">
        <el-input v-model="data.time"></el-input>
      </el-form-item>
      <el-form-item label="数量:">
        <el-input v-model="data.num"></el-input>
      </el-form-item>
      <el-form-item label="最低:">
        <el-input v-model="data.min"></el-input>
      </el-form-item>
      <el-form-item label="最高:">
        <el-input v-model="data.max"></el-input>
      </el-form-item>
      <el-form-item label="颜色">
        <el-color-picker v-model="data.color"></el-color-picker>
      </el-form-item>
      <el-form-item label="绘制:">
        <el-button type="info" size="mini" @click="draw">图上绘制</el-button>
      </el-form-item>
    </el-form>
  </Popup>
</template>
 
<script>
import Popup from "@tools/Popup";
import Bus from "@tools/Bus";
let rectangle;
export default {
  name: "FlyingLine",
  components: {
    Popup,
  },
  data() {
    return {
      title: "添加垂直飞线",
      left: "calc(100% - 320px)",
      data: {
        color: "#ffff00",
        size: 0.01,
        time: 2500,
        min: 800,
        max: 1000,
        num: 100,
      },
      length: 1,
      // 表单验证规则
      rules: {},
      //颜色
    };
  },
  mounted() {},
  methods: {
    // 关闭弹窗
    close() {
      rectangle && rectangle.end && rectangle.end();
      rectangle = undefined;
      // 重置data值
      Object.assign(this.$data, this.$options.data());
    },
    // 打开弹窗
    open() {
      this.close();
      this.$refs.pop.open();
    },
    draw() {
      this.$refs.form.validate((valid) => {
        // 验证通过
        if (valid) {
          this.$message("在场景内绘制范围添加");
          rectangle && rectangle.end && rectangle.end();
          let color = Cesium.Color.fromCssColorString(
            this.data.color
          ).withAlpha(0.6);
          rectangle = sgworld.Creator.createSimpleGraphic(
            "rectangle",
            { color: color.toCssColorString() },
            (entity) => {
              entity.deleteObject();
              let coordinates = entity.rectangle.coordinates.getValue();
              coordinates = sgworld.Core.toDegreesRectangle(coordinates);
              this.createFlyingLine(coordinates);
            }
          );
        }
      });
    },
    createFlyingLine(rectangle) {
      let positions = [];
      for (let i = 0; i < this.data.num; i++) {
        let x =
          Math.random() * (rectangle.east - rectangle.west) + rectangle.west;
        let y =
          Math.random() * (rectangle.north - rectangle.south) + rectangle.south;
        let z = Math.random() * (this.data.max - this.data.min) + this.data.min;
        positions.push({ lon: x, lat: y, height: z });
      }
      let flyingLine = sgworld.Creator.createFlyingLine(positions, {
        time: this.data.time,
        color: this.data.color,
      });
      Bus.$emit("addOtherData", "特效", {
        id: sgworld.Core.getuid(),
        name: "新建垂直飞线",
        sourceType: "flyingLine",
        positions: positions,
        ...this.data,
        item: flyingLine,
      });
    },
  },
};
</script>
 
<style scoped lang="less">
.el-form {
  margin-top: 20px;
  margin-right: 10px;
  width: 300px;
 
  /deep/ .el-form-item__label {
    color: #fff;
    font-size: 18px;
  }
}
</style>