<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="目标ID" prop="targetId">
        <el-input
          v-model="queryParams.targetId"
          placeholder="请输入目标ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="目标集群类型" prop="formationType">
        <el-select
          v-model="queryParams.formationType"
          placeholder="目标集群类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.uavps_target_formation_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="经度" prop="longitude">
        <el-input
          v-model="queryParams.longitude"
          placeholder="请输入经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="纬度" prop="latitude">
        <el-input
          v-model="queryParams.latitude"
          placeholder="请输入纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海拔" prop="altitude">
        <el-input
          v-model="queryParams.altitude"
          placeholder="请输入海拔"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="东向速度" prop="eastSpeed">
        <el-input
          v-model="queryParams.eastSpeed"
          placeholder="请输入东向速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="北向速度" prop="northSpeed">
        <el-input
          v-model="queryParams.northSpeed"
          placeholder="请输入北向速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="天向速度" prop="skySpeed">
        <el-input
          v-model="queryParams.skySpeed"
          placeholder="请输入天向速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="UTC时间" prop="utcTimes">
        <el-input
          v-model="queryParams.utcTimes"
          placeholder="请输入UTC时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="本次目标总数" prop="targetTotal">
        <el-input
          v-model="queryParams.targetTotal"
          placeholder="请输入本次目标总数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['uavps:parameter:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['uavps:parameter:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['uavps:parameter:remove']"
          >删除</el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['uavps:parameter:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="parameterList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="ID" align="center" prop="id" width="40"/>-->
      <el-table-column label="目标集群类型" align="center" prop="formationType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.uavps_target_formation_type"
            :value="scope.row.formationType"
          />
        </template>
      </el-table-column>
      <el-table-column label="目标ID" align="center" prop="targetId" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column label="海拔" align="center" prop="altitude" />
      <el-table-column label="东向速度" align="center" prop="eastSpeed" />
      <el-table-column label="北向速度" align="center" prop="northSpeed" />
      <el-table-column label="天向速度" align="center" prop="skySpeed" />
      <el-table-column label="UTC时间" align="center" prop="utcTimes" />
      <el-table-column label="本次目标总数" align="center" prop="targetTotal" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['uavps:parameter:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['uavps:parameter:remove']"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-s-operation"
            @click="handleRun(scope.row)"
            v-hasPermi="['uavps:parameter:run']"
            >运行</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改算法参数信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="目标ID" prop="targetId">
          <el-input v-model="form.targetId" placeholder="请输入目标ID" />
        </el-form-item>
        <el-form-item label="目标集群类型" prop="formationType">
          <el-select
            v-model="form.formationType"
            placeholder="请选择目标集群类型"
          >
            <el-option
              v-for="dict in dict.type.uavps_target_formation_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="海拔" prop="altitude">
          <el-input v-model="form.altitude" placeholder="请输入海拔" />
        </el-form-item>
        <el-form-item label="东向速度" prop="eastSpeed">
          <el-input v-model="form.eastSpeed" placeholder="请输入东向速度" />
        </el-form-item>
        <el-form-item label="北向速度" prop="northSpeed">
          <el-input v-model="form.northSpeed" placeholder="请输入北向速度" />
        </el-form-item>
        <el-form-item label="天向速度" prop="skySpeed">
          <el-input v-model="form.skySpeed" placeholder="请输入天向速度" />
        </el-form-item>
        <el-form-item label="UTC时间" prop="utcTimes">
          <el-input v-model="form.utcTimes" placeholder="请输入UTC时间" />
        </el-form-item>
        <el-form-item label="本次目标总数" prop="targetTotal">
          <el-input
            v-model="form.targetTotal"
            placeholder="请输入本次目标总数"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 飞行轨迹展示对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="showTrajectory"
      @opened="initTrajectory"
      @closed="destroyTrajectory"
      :fullscreen="true"
      append-to-body
    >
      <div class="container">
        <div>
          <el-row type="flex" align="middle" style="height: 40px">
            <el-col :span="7">
              <el-button @click="transFormation" type="danger"
                >转换队形</el-button
              >
              <el-button @click="" type="success">回放</el-button>
            </el-col>
            <el-col :span="17">
              <!--              <el-progress v-show="isShow" :percentage="percentage"></el-progress>-->
            </el-col>
          </el-row>
          <el-row>
            <div ref="pixiContainer" class="pixi-container"></div>
          </el-row>
        </div>
        <div class="right-board">
          <el-divider content-position="left">目标无人机群</el-divider>
          <li v-for="(item, index) in targetLblAry" :key="index">
            <span>编号：&nbsp;&nbsp;</span><label>{{ item.no }}</label
            ><br />
            <span>经度：&nbsp;&nbsp;</span><label>{{ item.longitude }}</label
            ><br />
            <span>纬度：&nbsp;&nbsp;</span><label>{{ item.latitude }}</label
            ><br />
            <span>海拔：&nbsp;&nbsp;</span><label>{{ item.altitude }}</label
            ><br />
            <span>东向速度：&nbsp;&nbsp;</span
            ><label>{{ item.eastSpeed }}</label
            ><br />
            <span>北向速度：&nbsp;&nbsp;</span
            ><label>{{ item.northSpeed }}</label
            ><br />
            <span>天向速度：&nbsp;&nbsp;</span><label>{{ item.skySpeed }}</label
            ><br />
          </li>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listParameter,
  getParameter,
  delParameter,
  addParameter,
  updateParameter,
} from "@/api/uavps/parameter";
import * as PIXI from "pixi.js";

export default {
  name: "Parameter",
  dicts: ["uavps_target_formation_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 算法参数信息表格数据
      parameterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        formationType: null,
        targetId: null,
        longitude: null,
        latitude: null,
        altitude: null,
        eastSpeed: null,
        northSpeed: null,
        skySpeed: null,
        utcTimes: null,
        targetTotal: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        formationType: [
          {
            required: true,
            message: "目标集群类型不能为空",
            trigger: "change",
          },
        ],
        targetId: [
          { required: true, message: "目标ID不能为空", trigger: "blur" },
        ],
        longitude: [
          { required: true, message: "经度不能为空", trigger: "blur" },
        ],
        latitude: [
          { required: true, message: "纬度不能为空", trigger: "blur" },
        ],
        altitude: [
          { required: true, message: "海拔不能为空", trigger: "blur" },
        ],
        eastSpeed: [
          { required: true, message: "东向速度不能为空", trigger: "blur" },
        ],
        northSpeed: [
          { required: true, message: "北向速度不能为空", trigger: "blur" },
        ],
        skySpeed: [
          { required: true, message: "天向速度不能为空", trigger: "blur" },
        ],
        // utcTimes: [
        //   { required: true, message: "UTC时间不能为空", trigger: "blur" }
        // ],
        targetTotal: [
          { required: true, message: "本次目标总数不能为空", trigger: "blur" },
        ],
      },
      // 是否显示轨迹
      showTrajectory: false,
      pixiApp: null,
      parameterId: null,
      webSocket: null,
      curLongitude: null,
      curLatitude: null,
      curAltitude: null,
      texture: null,
      targetTexture: null,
      pathGraphics: null,
      planeSprite: null,
      targetTotal: null,
      targetLblAry: [],
      targetUavAry: [],
      targetUavCircle: [],
      targetUavCircleNum: [],
      targetUavPath: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询算法参数信息列表 */
    getList() {
      this.loading = true;
      listParameter(this.queryParams).then((response) => {
        this.parameterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        formationType: null,
        targetId: null,
        longitude: null,
        latitude: null,
        altitude: null,
        eastSpeed: null,
        northSpeed: null,
        skySpeed: null,
        utcTimes: null,
        targetTotal: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加算法参数信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getParameter(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改算法参数信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateParameter(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addParameter(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除算法参数信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delParameter(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handleRun(row) {
      this.parameterId = row.id || this.ids;
      this.showTrajectory = true;
      this.title = "飞行轨迹";
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "uavps/parameter/export",
        {
          ...this.queryParams,
        },
        `parameter_${new Date().getTime()}.xlsx`
      );
    },
    initTrajectory() {
      this.clearAllAry();
      this.initPixi();
      this.initWebSocket();
    },
    initPixi() {
      const container = this.$refs.pixiContainer;
      if (!container) return;

      // 创建Pixi应用
      this.pixiApp = new PIXI.Application({
        width: container.clientWidth,
        height: container.clientHeight,
        antialias: true,
        transparent: false,
        resolution: 1,
        backgroundAlpha: 0,
      });
      this.pixiApp.renderer.backgroundColor = 0x66ccff;
      container.appendChild(this.pixiApp.view);

      //this.createPlane();

      // 初始化路径绘制对象
      this.pathGraphics = new PIXI.Graphics();
      this.pixiApp.stage.addChild(this.pathGraphics);

      // 添加视窗控制
      this.enableViewControl();
    },
    initWebSocket() {
      const wsUri = "ws://127.0.0.1:8080/websocket/message";
      this.webSocket = new WebSocket(wsUri);
      const self = this;

      this.webSocket.onopen = function (event) {
        self.webSocket.send("RUN:" + self.parameterId);
        console.log("WebSocket连接成功!");
      };

      this.webSocket.onmessage = function (event) {
        self.processMessage(JSON.parse(event.data));
      };

      this.webSocket.onclose = function (event) {
        console.log("WebSocket连接断开!");
      };

      this.webSocket.onerror = function (event) {
        console.log(
          "WebSocket连接异常: " +
            event.code +
            " " +
            event.reason +
            " " +
            event.wasClean
        );
      };
    },
    // 处理WebSocket消息
    processMessage(data) {
      // 集群无人机总数
      // this.targetTotal = 2;
      this.targetTotal = data.targetAircraft[0].aircrafts.length;
      // 创建无人机,红色圆圈编号
      if (this.targetUavAry.length === 0) {
        this.targetTexture = new PIXI.Texture.from(
          "../../textures/uav-tar.png"
        );
        for (let i = 0; i < this.targetTotal; i++) {
          // 创建无人机
          const dude = new PIXI.Sprite(this.targetTexture);
          dude.anchor.set(0.5);
          dude.scale.set(0.04);
          dude.x = data.targetAircraft[0].aircrafts[i].coordinateX;
          dude.y = data.targetAircraft[0].aircrafts[i].coordinateY;
          dude.rotation = Math.atan2(dude.y, dude.x) + Math.PI / 2;

          this.targetUavAry.push(dude);
          this.pixiApp.stage.addChild(dude);

          // 创建圆圈
          // 圆圈相对于飞机的位置
          const cx = dude.x - 25;
          const cy = dude.y - 17;

          //编号-圆圈
          const circle = new PIXI.Graphics();
          circle.beginFill(0xff0000); // 红色
          circle.drawCircle(0, 0, 8);
          circle.endFill();
          circle.x = cx;
          circle.y = cy;
          this.targetUavCircle.push(circle);
          this.pixiApp.stage.addChild(circle);

          //编号-数字
          const text = new PIXI.Text(
            data.targetAircraft[0].aircrafts[i].aircraftNumber,
            {
              fontFamily: "Arial",
              fontSize: 12,
              fill: 0xffffff,
              align: "center",
            }
          );
          text.anchor.set(0.5);
          // 计算文字位置以便在圆形内居中
          text.x = cx;
          text.y = cy;
          this.targetUavCircleNum.push(text);
          this.pixiApp.stage.addChild(text);

          if (data.targetAircraft[0].aircrafts[i].piloted) {
            const point = { x: dude.x, y: dude.y };
            this.targetUavPath.push(point);
            this.curLongitude = data.targetAircraft[0].aircrafts[i].longitude;
            this.curLatitude = data.targetAircraft[0].aircrafts[i].latitude;
            this.curAltitude = data.targetAircraft[0].aircrafts[i].altitude;
          }
        }
      } else {
        for (let i = 0; i < this.targetUavAry.length; i++) {
          const targetUav = this.targetUavAry[i];
          targetUav.x = data.targetAircraft[0].aircrafts[i].coordinateX;
          targetUav.y = data.targetAircraft[0].aircrafts[i].coordinateY;
          targetUav.rotation =
            Math.atan2(targetUav.y, targetUav.x) + Math.PI / 2;

          const cx = targetUav.x - 25;
          const cy = targetUav.y - 17;

          const circle = this.targetUavCircle[i];
          circle.x = cx;
          circle.y = cy;

          const text = this.targetUavCircleNum[i];
          text.x = cx;
          text.y = cy;

          if (data.targetAircraft[0].aircrafts[i].piloted) {
            const point = { x: targetUav.x, y: targetUav.y };
            this.targetUavPath.push(point);
            this.curLongitude = data.targetAircraft[0].aircrafts[i].longitude;
            this.curLatitude = data.targetAircraft[0].aircrafts[i].latitude;
            this.curAltitude = data.targetAircraft[0].aircrafts[i].altitude;
          }
        }
      }
      if (data.targetAircraft != null) {
        for (let i = 0; i < this.targetTotal; i++) {
          // 多目标集群信息显示
          const lbl = {
            no: data.targetAircraft[0].aircrafts[i].aircraftNumber,
            longitude: data.targetAircraft[0].aircrafts[i].longitude.toFixed(7),
            latitude: data.targetAircraft[0].aircrafts[i].latitude.toFixed(7),
            altitude: data.targetAircraft[0].aircrafts[i].altitude + " m",
            eastSpeed:
              data.targetAircraft[0].aircrafts[i].eastSpeed.toFixed(1) + " m/s",
            northSpeed:
              data.targetAircraft[0].aircrafts[i].northSpeed.toFixed(1) +
              " m/s",
            skySpeed:
              data.targetAircraft[0].aircrafts[i].skySpeed.toFixed(1) + " m/s",
          };
          if (this.targetLblAry.length === 0) {
            this.targetLblAry.push(lbl);
          } else {
            this.targetLblAry.splice(i, 1, lbl);
          }
        }
      }
      // 更新路径绘制
      this.updatePath();

      // 更新位置
      //this.updatePosition();
    },
    // 创建飞机精灵
    createPlane() {
      this.texture = new PIXI.Texture.from("../../textures/uav.png");
      this.targetTexture = new PIXI.Texture.from("../../textures/uav-tar.png");
      this.planeSprite = new PIXI.Sprite(this.targetTexture);
      this.planeSprite.anchor.set(0.5);
      this.planeSprite.scale.set(0.04);
      this.pixiApp.stage.addChild(this.planeSprite);
    },
    // 更新飞行路径
    updatePath() {
      this.pathGraphics.clear();
      this.pathGraphics.lineStyle(1, 0xeeee00, 1);

      if (this.targetUavPath.length > 1) {
        this.pathGraphics.moveTo(
          this.targetUavPath[0].x,
          this.targetUavPath[0].y
        );

        // 使用曲线平滑路径
        this.targetUavPath.forEach((point, index) => {
          if (index > 0) {
            const prev = this.targetUavPath[index - 1];
            this.pathGraphics.quadraticCurveTo(
              prev.x,
              prev.y,
              (prev.x + point.x) / 2,
              (prev.y + point.y) / 2
            );
          }
        });
      }
    },
    // 更新位置
    updatePosition() {
      this.pixiApp.ticker.add(() => {
        for (let i = 0; i < this.targetTotal; i++) {
          const targetUav = this.targetUavAry[i];
          const point = this.targetUavPath[i];
          targetUav.x += point.x * 1.9;
          targetUav.y += point.y * 1.9;
          targetUav.rotation = Math.atan2(point.y, point.x) + Math.PI / 2;

          const cx = point.x - 25;
          const cy = point.y - 17;

          const circle = this.targetUavCircle[i];
          circle.x = cx;
          circle.y = cy;

          const text = this.targetUavCircleNum[i];
          text.x = cx;
          text.y = cy;
        }

        // const dx = target.x - this.planeSprite.x;
        // const dy = target.y - this.planeSprite.y;
        //
        // this.planeSprite.x += dx * 1.9;
        // this.planeSprite.y += dy * 1.9;
        // this.planeSprite.rotation = Math.atan2(dy, dx) + Math.PI/2;

        // if(Math.abs(dx) < 1 && Math.abs(dy) < 1) {
        //   currentPoint++;
        // }
      });
    },
    // 添加视窗控制
    enableViewControl() {
      this.pixiApp.stage.interactive = true;
      // 拖曳状态变量
      let dragging = false;
      let offsetX = 0;
      let offsetY = 0;

      // 鼠标拖曳
      this.pixiApp.stage
        .on("pointerdown", (e) => {
          dragging = true;
          offsetX = this.pixiApp.stage.position.x - e.data.global.x;
          offsetY = this.pixiApp.stage.position.y - e.data.global.y;
        })
        .on("pointermove", (e) => {
          if (dragging) {
            this.pixiApp.stage.position.x = e.data.global.x + offsetX;
            this.pixiApp.stage.position.y = e.data.global.y + offsetY;
          }
        })
        .on("pointerup", () => {
          dragging = false;
        });

      // 使用 mouseup 事件
      this.pixiApp.renderer.view.addEventListener("mouseup", (event) => {
        dragging = false;
      });

      // 或者使用 pointerup 事件
      this.pixiApp.renderer.view.addEventListener("pointerup", (event) => {
        dragging = false;
      });

      // 鼠标滚轮缩放
      this.pixiApp.renderer.view.addEventListener("wheel", (e) => {
        e.preventDefault();
        const zoomFactor = e.deltaY > 0 ? 0.9 : 1.1;
        this.pixiApp.stage.scale.x *= zoomFactor;
        this.pixiApp.stage.scale.y *= zoomFactor;
      });
    },
    destroyTrajectory() {
      if (this.webSocket) {
        this.webSocket.close();
      }
      if (this.pixiApp) {
        this.pixiApp.destroy(true);
        this.pixiApp = null;
      }
      this.clearAllAry();
    },
    transFormation() {
      debugger;
      let msg =
        "TRANSFORMATION:" +
        this.parameterId +
        "," +
        this.curLongitude +
        "," +
        this.curLatitude +
        "," +
        this.curAltitude;
      console.info("transFormation", msg);
      this.webSocket.send(msg);
      // this.pixiApp.stage.removeChildren();
      // this.clearAllAry();
    },
    clearAllAry() {
      this.targetLblAry = [];
      this.targetUavAry = [];
      this.targetUavCircle = [];
      this.targetUavCircleNum = [];
      this.targetUavPath = [];
    },
    // 经度转X坐标（示例转换函数）
    lonToX(longitude) {
      // 实际需要根据地图投影算法调整
      return (longitude + 180) * (this.pixiApp.screen.width / 360);
    },
    // 纬度转Y坐标（示例转换函数）
    latToY(latitude) {
      // 使用墨卡托投影简化计算
      const rad = (latitude * Math.PI) / 180;
      return (
        this.pixiApp.screen.height / 2 -
        Math.log(Math.tan(rad) + 1 / Math.cos(rad)) *
          (this.pixiApp.screen.width / (2 * Math.PI))
      );
    },
  },
};
</script>

<style>
.pixi-container {
  width: 100%;
  height: 750px;
  position: relative;
}

.pixi-container canvas {
  width: 100%;
  height: 100%;
}

.container {
  display: grid;
  grid-template-columns: 85% 15%; /* 两栏按比例分 */
}
.right-board {
  padding: 2px;
  margin: 2px;
  height: 750px;
  overflow: auto; /* 当内容超出元素边界时显示滚动条 */
}
</style>
