Riku
2025-03-20 7d02024c5351e620dcc2d49f36331e4a37228ea4
src/utils/map/dialog.js
@@ -3,17 +3,15 @@
import { factorUnit } from '@/constant/factor-unit';
import { windDir } from '@/constant/wind-dir';
import { map } from './index_old';
import { checkboxOptions } from '@/constant/checkbox-options';
import { useToolboxStore } from '@/stores/toolbox';
const toolboxStore = useToolboxStore();
export const DialogUtil = {
  show: true,
  toggleDataDialog() {
    this.show = !this.show;
    if (this.show) {
      return '数据弹框:开';
    } else {
      return '数据弹框:关';
    }
  },
  // 当前打开的弹框及位置坐标
  marker: undefined,
  lnglat: undefined,
  /**
   * 创建弹出框
   * @param {*} factorDatas 监测数据
@@ -21,8 +19,9 @@
   * @param {*} onClose 关闭弹出框回调
   * @returns
   */
  createInfoWindow(deviceCode, factorDatas, i, onClose) {
  createInfoWindow(deviceType, deviceCode, factorDatas, i, onClose) {
    let m = {
      deviceType: deviceType,
      deviceCode: deviceCode,
      data: factorDatas,
      index: i,
@@ -37,25 +36,9 @@
      offset: new AMap.Pixel(16, -45),
      autoMove: false
    });
    return m.window;
    return m;
  },
  createInfoWindow2(factorData, onClose) {
    let m = {
      time: factorData.time,
      factorList: factorData.values,
      window: '',
      close: onClose
    };
    // eslint-disable-next-line no-undef
    m.window = new AMap.InfoWindow({
      isCustom: true, //使用自定义窗体
      content: this.createWindowContent2(m),
      // eslint-disable-next-line no-undef
      offset: new AMap.Pixel(16, -45)
    });
    return m.window;
  },
  /**
   * 站点标记信息窗体
   */
@@ -74,6 +57,7 @@
  },
  createWindowContent2(marker) {
    const factorTypes = checkboxOptions(marker.deviceType);
    const time = marker.time;
    const factorList = marker.factorList;
    //实例化信息窗体
@@ -89,14 +73,17 @@
    var _contents = new Map();
    factorList.forEach((f) => {
      // 删选不显示的因子
      if (
        f.factorName == 'NOI' ||
        f.factorName == 'LNG' ||
        f.factorName == 'LAT' ||
        f.factorName == 'VELOCITY' ||
        f.factorName == 'TIME' ||
        f.factorName == 'HEIGHT'
      ) {
      // if (
      //   f.factorName == 'NOI' ||
      //   f.factorName == 'LNG' ||
      //   f.factorName == 'LAT' ||
      //   f.factorName == 'VELOCITY' ||
      //   f.factorName == 'TIME' ||
      //   f.factorName == 'HEIGHT'
      // ) {
      //   return;
      // }
      if (!factorTypes.find((v) => v.name == f.factorName)) {
        return;
      }
@@ -253,15 +240,45 @@
    return info;
  },
  openNewWindow(deviceCode, factorDatas, i, onClose) {
    if (!this.show) return;
    const window = this.createInfoWindow(deviceCode, factorDatas, i, onClose);
    window.open(map, factorDatas.lnglats_GD[i]);
  /**
   * 开启一个新的数据弹框
   * @param {String} deviceType 设备类型
   * @param {String} deviceCode 设备编号
   * @param {Array} factorDatas 监测数据
   * @param {Number} i 数据索引
   * @param {Function} onClose 弹框关闭回调
   * @returns
   */
  openNewWindow(deviceType, deviceCode, factorDatas, i, onClose) {
    if (!toolboxStore.dataDialogStatus) return;
    this.marker = this.createInfoWindow(
      deviceType,
      deviceCode,
      factorDatas,
      i,
      onClose
    );
    this.marker.window.open(map, factorDatas.lnglats_GD[i]);
    this.lnglat = factorDatas.lnglats_GD[i];
  },
  openNewWindow2(factorData, position, onClose) {
    if (!this.show) return;
    const window = this.createInfoWindow2(factorData, onClose);
    window.open(map, position);
  /**
   * 打开缓存中的弹框
   */
  openWindow() {
    if (this.marker && this.lnglat) {
      // this.marker.close();
      this.marker.window.open(map, this.lnglat);
    }
  },
  /**
   * 关闭已弹出的弹框
   */
  closeWindow() {
    if (this.marker) {
      // this.marker.close();
      this.marker.window.close();
    }
  }
};