<template>
  <div id="map_jk">
    <div id="mapDiv" ref="map">
      <div id="viewDiv" ref="view">
        <div id="menu" class="esri-widget">
        </div>
      </div>
      <div id="viewDiv_2D" ref="view_2D">
        <div id="menu" class="esri-widget">
        </div>
      </div>
      <div id = "overviewDiv" ref = "overview" >

      </div>
    </div>
  </div>
</template>

<script>
import $ from 'jquery';
import {getCurrentInstance, onMounted} from "vue";
import SetMapConfig from "../units/map/SetMapConfig.js"
import InitMap from "../units/map/InitMap.js";
import AddBaseMapLayer from "../units/map/AddBaseMapLayer.js";
import AddSingleLayer from "../units/map/AddSingleLayer.js";
import WaterEffect from "../units/map/WaterEffect.js";
import Measurement from "../units/map/Measurement.js";
import SunshineAnalysis from "../units/map/SunshineAnalysis.js";
import AddPointEvent from "../units/map/AddPointEvent.js";
import SetPopupOptions from "../units/map/SetPopuopOptions";
import AddScaleEvent from "../units/map/AddScaleEvent";
import ViewShedAnalysisWidget from "../units/map/ViewShedAnalysis.js";
import AddLightBallEvent from "../units/map/AddLightBallEvent.js";
import AddThreeGridEvent from "../units/map/addThreeGridEvent.js";
import LimitHeightAnalysis from "../units/map/LimitHeightAnalysis.js";
import SetLocation from "../units/map/SetLocation.js";
import GeometryMeshPrismEffect from "../units/map/GeometryMeshPrismEffect.js";
import ReRenderingEvent from "../units/map/ReRenderingEvent.js";
import PathPipeEvent from "../units/map/PathPipeEvent.js";
import FlyGLTFEvent from "../units/map/FlyGLTFEvent.js";
import AddDrawEvent from "../units/map/addDrawEvent.js";
import SymbolPathPipeEvent from "../units/map/SymbolPathPipeEvent.js";
import SymbolPointCubeEvent from "../units/map/SymbolPointCubeEvent.js";
import AddThreeCubeEvent from "../units/map/AddThreeCubeEvent.js";
import AddThreeCubeDetailEvent from "../units/map/AddThreeCubeDetailEvent.js";
import AddThreeNetEvent from "../units/map/AddThreeNetEvent.js";
import dojoConfig from '../config/tsconfig.json'
import ws from 'ws';

import Path from '../config/path_wjc.json'
import routeList from '../config/routeList.json'
import MoveCar from '../config/moveCar.json'

import {
  getAvoidRoute,
  getBuildingPoint,
  getNoFlyPointInterface, getOccupyPointByPolygon, getPath,
  getPowerInterface,
  getPowerPoint, getPowerPointByFrustumCone,
  getPowerPointByFunnel, getPowerPointByInvertedCone, getPowerPointByPath,
  getPowerPointByPolygon, getPowerPointByPrism, getPrism,
  getProxyToken, getQJC,
  getRiverPointInterface,
  getRoadPointInterface,
  gridBaseInfo, queryPathsInfo
} from "../service/http.js";
import FeaturePointsPlottingEvent from "../units/map/FeaturePointsPlottingEvent.js";
import FeaturePolygonPlottingEvent from "../units/map/FeaturePolygonPlottingEvent.js";
import HeatMap from "../units/map/HeatMap.js";
import AddGraphicsEvent from "../units/map/AddGraphicsEvent.js";
import GeometryMeshEffect from "../units/map/GeometryMeshEffect.js";
import QueryIn2D from "../units/map/QueryIn2D.js";
import AddFlowPathEvent from "../units/map/AddFlowPathEvent.js";
import MovePointStreamEvent from "../units/map/MovePointStreamEvent.js";
import AddRadarEffectEvent from "../units/map/AddRadarEffect.js";
export default {
  name: "mapJK",
  setup(){
    let socket = null;
    let virtualSocket = null;
    let flyPointSocket = null;
    let ShowMovePointCube = false;
    const ctx = getCurrentInstance();
    const bus = ctx?.appContext.config.globalProperties.$bus;
    let MapReady = null;
    let m_spatialReference = null;
    let m_fullExtent = null;
    let m_initialExtent = null;
    let m_view;
    let m_map;
    let measureWidget = null;
    let sunshineWidget = null;
    let m_handles = [];
    let viewShedAnalysisWidget = null;
    let lightBallInstance = {};
    let addThreeGridEvent = null;
    let addThreeCubeEvent = null;
    //let addThreeCubeDetailEvent = null;
    let powerDataList = [];
    let addThreeCubeDetailInstance = {};
    let addThreeNetEvent = null;
    let limitHeightAnalysisEvent = null;
    let reRenderingEvent = null;
    let pathPipeInstance = {};
    let flyGLTFInstances = {};
    let radarEffectInstance = {};
    let addDrawEvent = null;
    let draw_GeometryMeshPrismEffectEvent = null;
    let symbolPathPipeEvent = null;
    let symbolPointCubeEvent = null;
    let addGraphicsEvent = null;
    let featurePointsPlottingEvent = null;
    let currentShowGridParams = null;
    let realFlyPointDataQueue = [];
    let addFlowPathEvent = null;
    let movePointEvent = null;
    let currentRealPowerShow = false;  //当前是否显示无极网格
    let getFixedFlyInstance = {};
    let currentRealPowerIds = {
      power_wj_15:[],
      power_wj_16:[],
      power_wj_17:[],
      power_wj_18:[],
      power_wj_19:[],
      power_wj_20:[],
      power_wj_21:[],
      power_wj_22:[],
      power_wj_23:[]
    };   //当前无极网格
    let currentRealPowerLevel = null; //当前无极网格层级
    let popupEnabled = false;
    onMounted(() =>{
      bus.on('CreateMap',() =>{
        MapReady = $.Deferred();
        createMap();
        $.when((MapReady).done(()=>{
          //发送消息
          bus.emit('SendMessage',{
            action:"MapIsReady",
            data:{
              "message":"地图初始化完成"
            }
          })
        }))
      })
      //调用方法
      bus.on('InvokeMethod',(data) =>{
        invokeMethod(data);
      })
      function createMap(){
        let setMapConfig = new SetMapConfig({
          m_spatialReference,
          m_fullExtent,
          m_initialExtent,
          m_handles
        })
        m_spatialReference = setMapConfig.m_spatialReference;
        m_fullExtent = setMapConfig.m_fullExtent;
        m_initialExtent = setMapConfig.m_initialExtent;
        m_handles = setMapConfig.m_handles;
        let initMap = new InitMap({
          m_map,
          m_view,
          m_spatialReference,
          bus
        });
        m_map = initMap.m_map;
        m_view = initMap.m_view;
      }
      function invokeMethod(data){
        //后续设置验证token
        runMethod(data);
      }
      function runMethod(data){
        let methodname = data.methodname;
        let params = data.params;
        if(typeof (params) != "string"&& params)
          params = eval(params);
        switch (methodname) {
          case "SetBackground":
            setBackground(params);
            break;
          case "SetLocation":
            setLocation(params);
            break;
          case "AddBaseMapAnSeLayer":
            addBaseMapAnSeLayer(params);
            break;
          case "AddBaseMapSuSeLayer":
            addBaseMapSuSeLayer(params);
            break;
          case "AddYaoGanLayer":
            addYaoGanLayer(params);
            break;
          case "AddWhiteMoldLayer":
            addWhiteMoldLayer(params);
            break;

          case "AddSingleLayer":
            addSingleLayer(params);
            break;
          case "QueryIn2D":
             queryIn2D(params);
             break;
          case "ReRendering":
            reRendering(params);
            break;
          case "WaterEffect":
            waterEffect(params);
            break;
          case "HeatMap":
            heatMap(params);
            break;
          case "ThreeDimensionalHeatMap":
            threeDimensionalHeatMap(params);
            break;
          case "PathCompletion":
            pathCompletion(params);
            break;
          case "Measurement":
            measurement(params);
            break;
          case "SunshineAnalysis":
            sunshineAnalysis(params);
            break
          case "AccessFeaturesWithPointEvents":
            accessFeaturesWithPointEvents(params);
            break;
          case "ShowLayersWithScaleEvents":
            showLayersWithScaleEvents(params);
            break;
          case "ViewshedAnalysis":
            viewshedAnalysis(params);
            break;
          case "FeatureLayerThreeDimension":
            featureLayerThreeDimension(params);
            break;
          case "AddLightBall":
            addLightBall(params);
            break;
          case "ThreeGrid":
            threeGrid(params);
            break;
          case "ShowThreeCube":
            showThreeCube(params);
            break;
          case "ShowThreeCubeDetail":
            showThreeCubeDetail(params);
            break;
          case "GetAllPowerPoints":
            getAllPowerPoints(params);
            break;
          case "ShowBuildingThreeCubeByInterface":
            showBuildingThreeCubeByInterface(params);
            break;
          case "ShowNoFlyThreeCubeByInterface":
            showNoFlyThreeCubeByInterface(params);
            break;
          case "ShowNoFlyThreeCubeDetailByInterface":
            showNoFlyThreeCubeDetailByInterface(params);
            break;
          case "ShowRoadThreeCubeByInterface":
            showRoadThreeCubeByInterface(params);
            break;
          case "ShowRoadThreeCubeDetailByInterface":
            showRoadThreeCubeDetailByInterface(params);
            break;
          case "ShowRiverThreeCubeByInterface":
            showRiverThreeCubeByInterface(params);
            break;
          case "ShowRiverThreeCubeDetailByInterface":
            showRiverThreeCubeDetailByInterface(params);
            break;
          case "ShowThreeNet":
            showThreeNet(params);
            break;
          case "RealPositionGrid":
            realPositionGrid(params);
            break;
          case "LimitHeightAnalysis":
            limitHeightAnalysis(params);
            break;
          case "GeometryMeshPrismEffect":
            geometryMeshPrismEffect(params);
            break;
          case "GeometryMeshEffect":
            geometryMeshEffect(params);
            break;
          case "PathPipe":
            pathPipe(params);
            break;
          case "FlyGLTF":
            flyGLTF(params);
            break;
          case "Draw":
            draw(params);
            break;
          case "Draw_GeometryMeshPrismEffect":
            draw_GeometryMeshPrismEffect(params);
            break;
          case "SymbolPathPipe":
            symbolPathPipe(params);
            break;
          case "SymbolPointCube":
            symbolPointCube(params);
            break;
          case "FeaturePointsPlotting":
            featurePointsPlotting(params);
            break;
          case "FeaturePolygonPlotting":
            featurePolygonPlotting(params);
            break;
          case "GetRealFlyPoint":
            getRealFlyPoint(params);
            break;
          case "GetVirtualFlyPoint":
            getVirtualFlyPoint(params);
            break;
          case "GetFixedFlyPoint":
            getFixedFlyPoint(params);
            break;
          case "ChangePointStatus":
            changePointStatus(params);
            break;
          case "GetRealPower":
            getRealPower(params);
            break;
          case "GetRealPower2":
            getRealPower2(params);
            break;
          case "PathConflict":
            pathConflict(params);
            break;
          case "UavBatteryWarning":
            uavBatteryWarning(params);
            break;
          case "UavYawWarning":
            uavYawWarning(params);
            break;
          case "Conflict_fly":
            conflict_fly(params);
            break;
          case "SituationAssessment":
            situationAssessment(params);
            break;
          case "FlowPathEffect":
            flowPathEffect(params);
            break;
          case "MovePoint":
            movePoint(params);
            break;
          case "MovePaths":
            movePaths(params)
            break;
          case "ShowMovePointCube":
            showMovePointCube(params)
            break;
          case "GetOccupyCube":
            getOccupyCube(params);
            break;
          case "GetPowerCube":
            getPowerCube(params);
            break;
          case "GetFunnelCube":
            getFunnelCube(params);
            break;
          case "GetFrustumConeCube":
            getFrustumConeCube(params);
            break;
          case "GetInvertedConeCube":
            getInvertedConeCube(params);
            break;


          case "GetCylinderCube":
            getCylinderCube(params);
            break;
          case "GetCuboidCube":
            getCuboidCube(params);
            break;
          case "GetPrismCube":
            getPrismCube(params);
            break;
          case "GetPathCube":
            getPathCube(params);
            break;
          case "GetBasePrism":
            getBasePrism(params);
            break;
          case "GetBasePath":
            getBasePath(params);
            break;
          case "GetBaseQJC":
            getBaseQJC(params);
            break;
          case "RadarEffect":
            radarEffect(params);
            break;
        }
      }
      function setBackground(params){

      }
      function setLocation(params){
        let setLocation = new SetLocation({
          view:m_view,
          x:params.x,
          y:params.y,
          z:params.z,
          heading:params.heading,
          tilt:params.tilt,
          isfly:params.isfly,
        });
        setLocation.start();
      }
      function addYaoGanLayer(params){
        let addSingleLayer = new AddSingleLayer({
          m_map,
          type:params.type,
          id:params.id,
          title:params.title,
          visible:params.visible,
          opacity:params.opacity,
          url:"https://192.168.2.140:6443/geoscene/rest/services/WT_HP/MapServer",
          where:params.where,
          popupEnabled:params.popupEnabled,
          renderer:params.renderer,
          elevationInfo:params.elevationInfo
        })
        let layer = addSingleLayer.layer;
        m_map.add(layer);
      }
      function addBaseMapAnSeLayer(params){
        let addBaseMapLayer = new AddBaseMapLayer({
          id:params.id,
          title:params.title,
          visible:params.visible,
          opacity:params.opacity,
          url:"https://serve2d21.gis.cn:6443/geoscene/rest/services/google_shanghai_black/MapServer",
          //url:"https://192.168.2.140:6443/geoscene/rest/services/JC_dark/MapServer",
          m_spatialReference,
          m_fullExtent,
        })
        m_view.map.basemap = addBaseMapLayer.basemap;
      }

      function addBaseMapSuSeLayer(params){
        let addBaseMapLayer = new AddBaseMapLayer({
          id:params.id,
          title:params.title,
          visible:params.visible,
          opacity:params.opacity,
          url:"https://192.168.2.140:6443/geoscene/rest/services/JC_white/MapServer",
          m_spatialReference,
          m_fullExtent,
        })
        m_view.map.basemap = addBaseMapLayer.basemap;
      }



      function addWhiteMoldLayer(params){
        let addSingleLayer = new AddSingleLayer({
          m_map,
          type:params.type,
          id:params.id,
          title:params.title,
          visible:params.visible,
          opacity:params.opacity,
          url: "https://192.168.2.140:6443/geoscene/rest/services/WT_BM/SceneServer",
          where:params.where,
          popupEnabled:params.popupEnabled,
          renderer:params.renderer,
          elevationInfo:params.elevationInfo
        })
        let layer = addSingleLayer.layer;
        m_map.add(layer);
      }




      function addSingleLayer(params){
        let addSingleLayer = new AddSingleLayer({
          m_map,
          type:params.type,
          id:params.id,
          title:params.title,
          visible:params.visible,
          opacity:params.opacity,
          url: params.url,
          where:params.where,
          popupEnabled:params.popupEnabled,
          renderer:params.renderer,
          elevationInfo:params.elevationInfo
        })
        let layer = addSingleLayer.layer;
        m_map.add(layer);
      }
      async function queryIn2D(params) {
        let type = params.type;
        let geometry = params.geometry;
        let where = params.where;
        let url;
        let layerId;
        if (type === "区县") {
          url = await returnProxyUrl(dojoConfig["queryurl_qx_3857"]) + '/0'
          layerId = 0;
        } else if (type === "街道") {
          url = await returnProxyUrl(dojoConfig["queryurl_jd_3857"]) + '/0'
          layerId = 0;
        }
        let queryIn2DInstance = new QueryIn2D({
          view: m_view,
          map: m_map,
          url: url,
          layerId: layerId,
          geometry: geometry,
          where: where
        })
        let result = await queryIn2DInstance.search();
        if(result.length > 0){
          bus.emit('SendMessage',{
            action:"ReturnResult",
            data:{
              "message":result
            }
          })
        }
      }

      async function returnProxyUrl(url){
        if(!url){
          return;
        }
        let arr = url.split('/');
        let username = '';
        let password = '';
        if(arr.indexOf('MapProxyApi') !== -1){ //不需要授权服务
          for(let i=0;i<arr.length;i++){
            if(arr[i] ==='getSceneServer'){
              username = arr[i+1];
              password = arr[i+2];
              const response = await getProxyToken(username,password);
              if(response?.data?.length > 0){
                arr.splice(i-1, 4);
                return arr.join('/')+'/MapServiceProxy/'+response?.data;
              }
            }
          }
        }else{
          return url
        }
      }

      function getSymbol(params){
        return {
          type: "mesh-3d",
          symbolLayers: [{
            type: "fill",
            material: {
              color: params.color
            },
            edges: {
              type: "solid",
              color:[255, 255, 255],
            }
          }]
        };
      }
      function reRendering(params){
        let ids_1 = [];
        for(let i=0;i<10000;i++){
          ids_1.push(i);
        }
        let ids_2 = [];
        for(let i=10000;i<20000;i++){
          ids_2.push(i);
        }
        let renderer = {
          type:"unique-value",
          defaultSymbol: getSymbol({color: [0, 255, 0,0.8]}),
          defaultLabel: "Other",
          field: "OBJECTID",
          uniqueValueInfos: [
          ]
        };
        // 每秒更新一次网格颜色
        setInterval(() => {
          renderer.uniqueValueInfos = []
        // 定义分组和对应的颜色
        const groups = {
          group1: {
            ids: ids_1, // 分组1的 ID 列表
            color: [Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), 0.8] // 红色
          },
          group2: {
            ids: ids_2, // 分组3的 ID 列表
            color: [Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), Math.floor(Math.random() * 256), 0.8] // 蓝色
          }
        };
        // 遍历分组，动态生成渲染规则
        Object.keys(groups).forEach(groupKey => {
          const group = groups[groupKey];
          group.ids.forEach(id => {
            renderer.uniqueValueInfos.push({
              value: id, // 对应的 ID
              symbol: getSymbol(group)
            });
          });
        });
        if(reRenderingEvent == null){
          reRenderingEvent = new ReRenderingEvent({
            m_map,
            type:"scene",
            id:"WhiteMold",
            renderer:renderer
          });
        }
        reRenderingEvent.ReRendering();
        }, 5000);
      }
      function waterEffect(params){
        params.id = "waterLayer";
        if(params.status === "hide"){
          let layer = m_map.layers.find(item => item.id === params.id);
          m_map.remove(layer);
          return
        }
        if(params.status === "show"){
          let layer = m_map.layers.find(item => item.id === params.id);
          if(typeof layer === "undefined"){
            let waterEffect = new WaterEffect({
              id:params.id,
              url:params.url,
              waveDirection:params.waveDirection,
              waveStrength:params.waveStrength,
              color:params.color
            })
            layer = waterEffect.layer;
            m_map.add(layer);
          }else{
            m_view.environment.lighting.waterReflectionEnabled = true;
            const renderer = layer.renderer.clone();
            renderer.symbol.symbolLayers.getItemAt(0).waveDirection = params.waveDirection;
            renderer.symbol.symbolLayers.getItemAt(0).waveStrength = params.waveStrength;
            renderer.symbol.symbolLayers.getItemAt(0).color = params.color;
            layer.renderer = renderer;
          }
        }
      }

      function heatMap(params){
        params.id = "heatMap";
        if(!params.visible){
          let layer = m_map.layers.find(item => item.id === params.id);
          m_map.remove(layer);
          return
        }
        if(params.visible){
          let layer = m_map.layers.find(item => item.id === params.id);
          if(typeof layer === "undefined"){
            let heatMap = new HeatMap({
              id:params.id,
              url:params.url,
              waveDirection:params.waveDirection,
              waveStrength:params.waveStrength,
              color:params.color
            })
            layer = heatMap.layer;
            m_map.add(layer);
          }
        }
      }

      function threeDimensionalHeatMap(params){
        let status = params.status;
        if(addFlowPathEvent){
          addFlowPathEvent.clear();
          addFlowPathEvent = null;
        }
        if(status === "hide"){
          return
        }
        addFlowPathEvent = new AddFlowPathEvent({
          view:m_view,
          paths:params.paths,
          color:params.color,
          pipeRadius:params.pipeRadius
        })
        addFlowPathEvent.start()
      }


      function pathCompletion(params){
        let points = params.points;
        let speed1 = params.speed1;
        let speed2 = params.speed2;
        const result = [];

        // 将第一个点添加到结果中
        result.push(points[0]);

        for (let i = 1; i < points.length; i++) {
          const prevPoint = points[i - 1];
          const currPoint = points[i];

          const distance = Math.sqrt(
              Math.pow(currPoint[0] - prevPoint[0], 2) +
              Math.pow(currPoint[1] - prevPoint[1], 2) +
              Math.pow(currPoint[2] - prevPoint[2], 2)
          );

          const velocity = prevPoint[2] === currPoint[2] ? speed1 : speed2;  // 判断是否是同一高度

          // 计算所需的时间
          const time = distance / velocity;

          const numPoints = Math.floor(time);  // 根据时间间隔生成插值点数

          for (let j = 1; j <= numPoints; j++) {
            // 线性插值，计算插值点
            const t = j / (numPoints + 1);
            const x = prevPoint[0] + t * (currPoint[0] - prevPoint[0]);
            const y = prevPoint[1] + t * (currPoint[1] - prevPoint[1]);
            const z = prevPoint[2] + t * (currPoint[2] - prevPoint[2]);

            result.push([x, y, z]);
          }

          // 最后将当前点添加到结果中
          result.push(currPoint);
        }
        console.log("离散的点",result)
        return result;
      }

      function measurement(params){
        let status = params.status;
        let type = params.type;
        let position = params.position;
        if(status === "hide"){
          if(measureWidget !== null){
            m_view.ui.remove(measureWidget);
            measureWidget.destroy();
            measureWidget = null;
          }
          return
        }
        if(status === "show"){
          if(measureWidget === null){
            let measurement = new Measurement({
              view:m_view,
              type
            })
            measureWidget = measurement.widget;
          }
          m_view.ui.add(measureWidget,position);
        }
      }
      function sunshineAnalysis(params){
        let status = params.status;
        let position = params.position;
        if(status === "hide"){
          if(sunshineWidget !== null){
            m_view.ui.remove(sunshineWidget);
            sunshineWidget.destroy();
            sunshineWidget = null;
          }
          return
        }
        if(status === "show"){
          if(sunshineWidget === null){
            let sunshineAnalysis = new SunshineAnalysis({
              view:m_view
            })
            sunshineWidget = sunshineAnalysis.widget;
          }
          m_view.ui.add(sunshineWidget,position);
        }
      }
      function accessFeaturesWithPointEvents(params){
        let status = params.status;
        let mouse_handle_id = params.mouse_handle_id;
        let highlight_handle_id = params.highlight_handle_id;
        if(status === "hide"){
          if(m_handles.has(mouse_handle_id)){
            m_handles.remove(mouse_handle_id);
          }
          if(m_handles.has(highlight_handle_id)){
            m_handles.remove(highlight_handle_id);
          }
          return
        }
        if(status === "show"){
          let type = params.type;
          let mouseTime = params.mouse_time;
          let popupTitle = params.popup_title;
          if(m_handles.has(mouse_handle_id)){
            m_handles.remove(mouse_handle_id);
          }
          if(m_handles.has(highlight_handle_id)){
            m_handles.remove(highlight_handle_id);
          }
          if(params.popupEnabled){
            popupEnabled = params.popupEnabled;
          }
          let addPointEvent = new AddPointEvent({
            m_view,
            type,
            highlightHandleId:highlight_handle_id,
            mouseTime,
            popupTitle,
            callbackFunction:accessFeaturesWithPointEventsReturn
          });
          m_handles.add(addPointEvent.mouseHandle,mouse_handle_id);
        }
      }
      function accessFeaturesWithPointEventsReturn(screenPoint,handleId,popupTitle){
        if(m_handles.has(handleId)){
          m_handles.remove(handleId);
        }
        m_view.hitTest(screenPoint).then((response) =>{
          if(response.results.length > 0){
            let result = response.results[0];
            m_view.whenLayerView(result.graphic.layer).then((lyrView) =>{
              let highlightHandle = lyrView.highlight(result.graphic);
              m_handles.add(highlightHandle,handleId);
            })
            if(popupEnabled){
              let setPopupOptions = new SetPopupOptions({
                title:popupTitle,
                location:m_view.toMap(screenPoint),
                content:result.graphic.attributes
              })
              m_view.popup.open(setPopupOptions.popupOptions());
            }
            bus.emit('SendMessage',{
              action:"ClickResult",
              data:{
                "message":result.graphic.attributes
              }
            })
          }
        })
      }




      function showLayersWithScaleEvents(params){
        let status = params.status;
        let scale_handle_id = params.scale_handle_id;
        if(status === "hide"){
          if(scale_handle_id === "scale_handle_cube"){
            currentRealPowerShow = false;
            currentRealPowerIds = {
              power_wj_15:[],
              power_wj_16:[],
              power_wj_17:[],
              power_wj_18:[],
              power_wj_19:[],
              power_wj_20:[],
              power_wj_21:[],
              power_wj_22:[],
              power_wj_23:[]
            };
            currentRealPowerLevel = null;
            closeOtherThreeCubeDetail("power_wj")
          }else if(scale_handle_id === "scale_handle_tileLayerChange"){
            //暂无操作
          }else if(scale_handle_id === "scale_handle_sceneLayerLayerChange"){
            //暂无操作
          }
          if(m_handles.has(scale_handle_id)){
            m_handles.remove(scale_handle_id);
          }
          return
        }
        if(status === "show"){
          if(m_handles.has(scale_handle_id)){
            m_handles.remove(scale_handle_id);
          }
          let addScaleEvent;
          if(scale_handle_id === "scale_handle_cube"){
            currentRealPowerShow = true;
            showCubeWithScaleEventsReturn(m_view.scale);
            addScaleEvent = new AddScaleEvent({
              m_view,
              callBackFunction:showCubeWithScaleEventsReturn
            });
          }else if(scale_handle_id === "scale_handle_tileLayerChange"){
            showTileLayersWithScaleEventsReturn(m_view.scale)
            addScaleEvent = new AddScaleEvent({
              m_view,
              callBackFunction:showTileLayersWithScaleEventsReturn
            });
          }else if(scale_handle_id === "scale_handle_sceneLayerLayerChange"){
            showSceneLayersWithScaleEventsReturn(m_view.scale)
            addScaleEvent = new AddScaleEvent({
              m_view,
              callBackFunction:showSceneLayersWithScaleEventsReturn
            });
          }
          m_handles.add(addScaleEvent.scaleHandle,scale_handle_id);
        }
      }



      //不同比例尺加载白膜
      function showSceneLayersWithScaleEventsReturn(scaleValue){
        let layer = m_map.layers.find(item => item.id === "WhiteMold");
        if(scaleValue > 50000){
          if(layer){
            layer.visible = false;
          }
        }else{
          if(layer){
            layer.visible = true;
          }
        }
      }

      //不同比例尺加载长三角瓦片
      function showTileLayersWithScaleEventsReturn(scaleValue){
        let layer = m_map.layers.find(item => item.id === "BaseMapCSJYaoGan");
        if(scaleValue < 150000){
          if(layer){
            layer.visible = false;
          }
        }else{
          if(layer){
            layer.visible = true;
          }
        }
      }



      //不同比例尺加载网格
      function showCubeWithScaleEventsReturn(scaleValue){
        switch (true) {
          case (scaleValue > 1500000):  //15级以上隐藏
            getCurrentRealPower({
              status:'hide'
            })
            currentRealPowerIds = {
              power_wj_15:[],
              power_wj_16:[],
              power_wj_17:[],
              power_wj_18:[],
              power_wj_19:[],
              power_wj_20:[],
              power_wj_21:[],
              power_wj_22:[],
              power_wj_23:[]
            };
            currentRealPowerLevel = null;
            break;
          case (scaleValue <= 1500000 && scaleValue > 300000): //15级
            currentRealPowerLevel = 15;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 1000,
              level: 15,
              size:{ x: 1582.2726823222256, y: 1856.6079667204758, z: 1724.5956527210265 }
            })
            break;
          case (scaleValue <= 300000 && scaleValue > 150000): //16级
            currentRealPowerLevel = 16;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 500,
              level: 16,
              size:{ x: 844.8477050379952, y: 990.1345935064928, z: 862.239544684298 }
            })
            break;
          case (scaleValue <= 150000 && scaleValue > 100000): //17级
            currentRealPowerLevel = 17;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 200,
              level: 17,
              size:{ x: 424.0518521273334, y: 492.09123171765896, z: 431.1052029077298 }
            })
            break;
          case (scaleValue <= 100000 && scaleValue > 40000): //18级
            currentRealPowerLevel = 18;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 100,
              level: 18,
              size:{ x: 211.66439868324142, y: 246.49964316944533, z: 215.5489592181181 }
            })
            break;
          case (scaleValue <= 40000 && scaleValue > 15000): //19级
            currentRealPowerLevel = 19;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 100,
              level: 19,
              size:{ x: 105.79869494173579, y: 123.19232219036257, z: 107.77356906534683 }
            })
            break;
          case (scaleValue <= 15000 && scaleValue > 6000): //20级
            currentRealPowerLevel = 20;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 50,
              level: 20,
              size:{ x: 52.887881893650956, y: 61.627412608112536, z: 53.887012166300096 }
            })
            break;
          case (scaleValue <= 6000 && scaleValue > 3000): //21级
            currentRealPowerLevel = 21;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 30,
              level: 21,
              size:{ x: 26.44107169853396, y: 30.815525255577086, z: 26.943221541824816 }
            })
            break;
          case (scaleValue <= 3000 && scaleValue > 1500): //22级
            currentRealPowerLevel = 22;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 30,
              level: 22,
              size:{ x: 13.222978864358083, y: 15.406742669116284, z: 13.471596544164798 }
            })
            break;
          case (scaleValue <= 1500): //23级
            currentRealPowerLevel = 23;
            getCurrentRealPower({
              status:"show",
              id:"power_wj",
              fields:["demographics","green","river","road","collision_buffer","no_fly_zone_buffer","clear_zone_buffer"],
              center:m_view.center,
              radius: (m_view.extent.xmax - m_view.extent.xmin) > (m_view.extent.ymax - m_view.extent.ymin) ? (m_view.extent.xmax - m_view.extent.xmin) : (m_view.extent.ymax - m_view.extent.ymin),
              minZ: 0,
              maxZ: 30,
              level: 23,
              size:{ x: 6.7358, y: 7.7024, z: 6.6111 }
            })
            break;
        }
        //加载二维服务
        //showCurrentCubeTileLayer(currentRealPowerLevel)
      }


      async function showCurrentCubeTileLayer(level) {
        let layerList = [15,16,17,18,19,20,21,22,23];
        layerList.forEach((item)=>{
          if (item !== level) {
            addSingleLayer({
              id: "cubeTile"+item,
              type: "tile",
              visible:false,
            })
          }
        })
        if (level === 15) {
          addSingleLayer({
            id: "cubeTile15",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031601")
          })
        } else if (level === 16) {
          addSingleLayer({
            id: "cubeTile16",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031602")
          })
        } else if (level === 17) {
          addSingleLayer({
            id: "cubeTile17",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031603")
          })
        } else if (level === 18) {
          addSingleLayer({
            id: "cubeTile18",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031604")
          })
        } else if (level === 19) {
          addSingleLayer({
            id: "cubeTile19",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031605")
          })
        } else if (level === 20) {
          addSingleLayer({
            id: "cubeTile20",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031606")
          })
        } else if (level === 21) {
          addSingleLayer({
            id: "cubeTile21",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031607")
          })
        } else if (level === 22) {
          addSingleLayer({
            id: "cubeTile22",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031608")
          })
        } else if (level === 23) {
          addSingleLayer({
            id: "cubeTile23",
            type: "tile",
            visible:true,
            url: await returnProxyUrl("https://cimweb.zjw.sh.cegn.cn:2008/MapProxyApi/getSceneServer/gxjh_fwjk/D999999012025031609")
          })
        }
      }


      function showThreeCube(params){
        let status = params.status;
        if(status === "hide"){
          if(addThreeCubeEvent){
            addThreeCubeEvent.clear();
            addThreeCubeEvent = null;
          }
          return
        }
        let size = params.size;
        let points = params.points;
        // 初始化 AddThreeCubeEvent，暂时不启动
        addThreeCubeEvent = new AddThreeCubeEvent({
          view: m_view,
          points:points,
          size,
        });
        addThreeCubeEvent.init();
      }




      function showThreeCubeDetail(params){
        let status = params.status;
        let id = params.id;
        let depthTest = params.depthTest;
        if(depthTest == undefined){
          depthTest = true;
        }
        let deepOpacity = params.deepOpacity;
        if(status === "hide"){
          if(addThreeCubeDetailInstance[id]){
            addThreeCubeDetailInstance[id].clear();
            addThreeCubeDetailInstance[id] = null;
          }
          return
        }
        let size = params.size;
        if(addThreeCubeDetailInstance[id]){
          addThreeCubeDetailInstance[id].add(params.points);
        }else{
          let addThreeCubeDetailEvent = new AddThreeCubeDetailEvent({
            view: m_view,
            points:params.points,
            size,
            bus,
            deepOpacity,
            depthTest
          });
          addThreeCubeDetailEvent.start();
          addThreeCubeDetailInstance[id] = addThreeCubeDetailEvent;
        }
      }


      // 递归获取所有建筑点的辅助函数
      function getAllPowerPoints(level,scrollId = null) {
        getPowerInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          //level: level,
          scrollId: scrollId,
        }).then(res =>{
          if(res.data.data.list?.length >= 10000 && res.data.data.scrollId){
            powerDataList =  powerDataList.concat(res.data.data.list);
            getAllPowerPoints(level,res.data.data.scrollId);
          }else{
            powerDataList =  powerDataList.concat(res.data.data.list);
            // 初始化 AddThreeCubeEvent，暂时不启动
            powerDataList.forEach((item)=>{
              item.color = getColor(item.averageValue, -100, 0);
            })

            let size = {
              x:13.223015683766334,
              y:15.404125436905815,
              z:13.471596544164798
            }
            let para = {
              id:"1",
              status:"show",
              size,
              points:powerDataList
            }
            //symbolPointCube(para)
            showThreeCubeDetail(para);
          }
        })
      }


      function getColor(value, minValue, maxValue) {
        // 边界处理
        if (value < minValue) value = minValue;
        if (value > maxValue) value = maxValue;
        // 映射到 [0, 1]
        let t = (value - minValue) / (maxValue - minValue);
        // 定义颜色
        let r, g, b;
        if (t <= 0.5) {
          // 从红色到黄色
          r = 1;
          g = t * 2; // 线性插值增加绿色
          b = 0;
        } else {
          // 从黄色到绿色
          r = 2 * (1 - t); // 线性插值减少红色
          g = 1;
          b = 0;
        }
        return [r, g, b];
      }


      function showBuildingThreeCubeByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        // 初始化 AddThreeCubeEvent，暂时不启动
        addThreeCubeEvent = new AddThreeCubeEvent({
          view: m_view,
          size,
        });
        addThreeCubeEvent.start();
        // 获取所有建筑点数据
        getAllBuildingPoints(level);
      }

      function showNoFlyThreeCubeDetailByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        getNoFlyPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: "",
        }).then(res =>{
          res.data.data.list.forEach(item =>{
            item.color = [1,0,0]
          })
          // 初始化 AddThreeCubeEvent，暂时不启动
          let addThreeCubeDetailEvent = new AddThreeCubeDetailEvent({
            view: m_view,
            points:res.data.data.list,
            size,
            bus
          });
          addThreeCubeDetailEvent.start();
        })
      }

      function showNoFlyThreeCubeByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        // 初始化 AddThreeCubeEvent，暂时不启动
        addThreeCubeEvent = new AddThreeCubeEvent({
          view: m_view,
          size,
        });
        addThreeCubeEvent.start();
        // 获取所有建筑点数据
        getNoFlyPoint(level);
      }

      function showRoadThreeCubeByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        // 初始化 AddThreeCubeEvent，暂时不启动
        addThreeCubeEvent = new AddThreeCubeEvent({
          view: m_view,
          size,
        });
        addThreeCubeEvent.start();
        // 获取所有建筑点数据
        getRoadPoint(level);
      }

      function showRoadThreeCubeDetailByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        getRoadPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: "",
        }).then(res =>{
          res.data.data.list.forEach(item =>{
            item.color = [0,0,1]
          })
          // 初始化 AddThreeCubeEvent，暂时不启动
          let addThreeCubeDetailEvent = new AddThreeCubeDetailEvent({
            view: m_view,
            points:res.data.data.list,
            size,
            bus
          });
          addThreeCubeDetailEvent.start();
        })
      }


      function showRiverThreeCubeByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        // 初始化 AddThreeCubeEvent，暂时不启动
        addThreeCubeEvent = new AddThreeCubeEvent({
          view: m_view,
          size,
        });
        addThreeCubeEvent.start();
        // 获取所有建筑点数据
        getRiverPoint(level);
      }

      function showRiverThreeCubeDetailByInterface(params){
        let status = params.status;
        let size = params.size;
        if(addThreeCubeEvent){
          addThreeCubeEvent.clear();
          addThreeCubeEvent = null;
        }
        if(status === "hide"){
          return
        }
        let level = params.level;
        getRiverPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: "",
        }).then(res =>{
          res.data.data.list.forEach(item =>{
            item.color = [1,1,0]
          })
          // 初始化 AddThreeCubeEvent，暂时不启动
          let addThreeCubeDetailEvent = new AddThreeCubeDetailEvent({
            view: m_view,
            points:res.data.data.list,
            size,
            bus
          });
          addThreeCubeDetailEvent.start();
        })
      }


      function showThreeNet(params){
        let status = params.status;
        if(addThreeNetEvent){
          addThreeNetEvent.clear();
          addThreeNetEvent = null;
        }
        if(status === "hide"){
          return
        }
        let size = params.size;
        let origin = params.origin;
        let buffer = params.buffer;
        let maxHeight = params.maxHeight;
        let minHeight = params.minHeight;
        //另一类是网加载（网只根据范围变化）
        addThreeNetEvent = new AddThreeNetEvent({
          view: m_view,
          size,
          origin,
          buffer,
          maxHeight,
          minHeight
        });
        addThreeNetEvent.start();
      }

      // 递归获取所有建筑点的辅助函数
      function getAllBuildingPoints(level,scrollId = null) {
        getBuildingPoint({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: scrollId,
        }).then(res =>{
          if(res.data.data.list?.length >= 10000 && res.data.data.scrollId){
            addThreeCubeEvent.addPoints(res.data.data.list);
            getAllBuildingPoints(level,res.data.data.scrollId);
          }else{
            addThreeCubeEvent.addPoints(res.data.data.list);
          }
        })
      }


      // 递归获取所有建筑点的辅助函数
      function getNoFlyPoint(level,scrollId = null) {
        getNoFlyPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: scrollId,
        }).then(res =>{
          if(res.data.data.list?.length >= 10000 && res.data.data.scrollId){
            addThreeCubeEvent.addPoints(res.data.data.list);
            getNoFlyPoint(level,res.data.data.scrollId);
          }else{
            addThreeCubeEvent.addPoints(res.data.data.list);
          }
        })
      }


      // 递归获取所有道路点的辅助函数
      function getRoadPoint(level,scrollId = null) {
        getRoadPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: scrollId,
        }).then(res =>{
          if(res.data.data.list?.length >= 10000 && res.data.data.scrollId){
            addThreeCubeEvent.addPoints(res.data.data.list);
            getRoadPoint(level,res.data.data.scrollId);
          }else{
            addThreeCubeEvent.addPoints(res.data.data.list);
          }
        })
      }

      // 递归获取所有河流点的辅助函数
      function getRiverPoint(level,scrollId = null) {
        getRiverPointInterface({
          x: m_view.camera.position.x,
          y: m_view.camera.position.y,
          level: level,
          scrollId: scrollId,
        }).then(res =>{
          if(res.data.data.list?.length >= 10000 && res.data.data.scrollId){
            addThreeCubeEvent.addPoints(res.data.data.list);
            getRiverPoint(level,res.data.data.scrollId);
          }else{
            addThreeCubeEvent.addPoints(res.data.data.list);
          }
        })
      }

      //全市格网自定义分割效果加载
      // function showLayersWithScaleEventsReturn(scaleValue){
      //   let eyeExtent = getEyeExtent();
      //   if(!eyeExtent){
      //     return
      //   }
      //   let height = m_view.camera.position.z;
      //   console.log("height",height,"scale",m_view.scale);
      //   let sizeObj = extentGridLimit({
      //     eyeExtent,
      //     height
      //   });
      //   let size = sizeObj.size;
      //   let opacity = sizeObj.opacity;
      //   let layerHeight;
      //   if(size > 400){
      //     layerHeight = 400;
      //   }else{
      //     layerHeight = size;
      //   }
      //   if(addThreeGridEvent){
      //     addThreeGridEvent.extent = {minX:eyeExtent.xmin,maxX:eyeExtent.xmax,minY:eyeExtent.ymin,maxY:eyeExtent.ymax};
      //     addThreeGridEvent.height = height>1200?1200:height;
      //     addThreeGridEvent.size = size;
      //     addThreeGridEvent.layerHeight = layerHeight;
      //     addThreeGridEvent.gridEnabled = true;
      //     addThreeGridEvent.netEnabled = true;
      //     addThreeGridEvent.opacity = opacity;
      //     addThreeGridEvent.start();
      //   }else{
      //     addThreeGridEvent = new AddThreeGridEvent({
      //       view:m_view,
      //       extent: {minX:eyeExtent.xmin,maxX:eyeExtent.xmax,minY:eyeExtent.ymin,maxY:eyeExtent.ymax},
      //       height:height>1200?1200:height,
      //       size:size,
      //       gridEnabled : true,
      //       netEnabled : true,
      //       opacity:opacity,
      //       layerHeight:layerHeight,
      //     })
      //     addThreeGridEvent.start();
      //   }
      //
      // }
      //
      //格网范围限制
      // function extentGridLimit(params){
      //   try{
      //     //let size = [7.73,61.84,123.69,1850];
      //     let size = [
      //       {
      //         value:7.73,
      //         opacity:0.05
      //       },
      //       {
      //         value:61.84,
      //         opacity:0.05
      //       },
      //       {
      //         value:123.69,
      //         opacity:0.15
      //       },
      //       {
      //         value:1850,
      //         opacity:0.3
      //       }
      //     ]
      //     params.eyeExtent = {
      //       xmin: params.eyeExtent.xmin < -60000?-60000:params.eyeExtent.xmin,
      //       ymin: params.eyeExtent.ymin < -60000?-60000:params.eyeExtent.ymin,
      //       xmax: params.eyeExtent.xmax > 60000?60000:params.eyeExtent.xmax,
      //       ymax: params.eyeExtent.ymax > 70000?70000:params.eyeExtent.ymax,
      //     }
      //     params.height = params.height < 1200?params.height:1200;
      //     for(let i = 0;i<size.length;i++){
      //       let xCount = Math.floor((params.eyeExtent.xmax - params.eyeExtent.xmin) / size[i].value);
      //       let yCount = Math.floor((params.eyeExtent.ymax - params.eyeExtent.ymin) / size[i].value);
      //       let zCount = Math.floor(params.height / size[i].value);
      //       let count = xCount * yCount * zCount;
      //       if(count < 200000){
      //         return {
      //           size: size[i].value,
      //           opacity: size[i].opacity
      //         }
      //       }
      //     }
      //   }catch(e){
      //     console.log("params",params)
      //   }
      // }
      // function getEyeExtent() {
      //   const screenWidth = m_view.width;
      //   const screenHeight = m_view.height;
      //
      //   // 四个角的像素坐标
      //   const screenCorners = [
      //     { x: 0, y: 0 }, // 左上角
      //     { x: screenWidth, y: 0 }, // 右上角
      //     { x: screenWidth, y: screenHeight }, // 右下角
      //     { x: 0, y: screenHeight }, // 左下角
      //   ];
      //
      //   // 将屏幕角坐标转为地图坐标
      //   const mapPoints = screenCorners.map((screenPoint) => m_view.toMap(screenPoint)).filter(p => p);
      //
      //   // 添加 camera.position 到 mapPoints
      //   const cameraPoint = m_view.camera.position;
      //
      //   if (mapPoints.length < 4) {
      //     if (cameraPoint) {
      //       const bufferDistance = 2000; // 2公里
      //       const spatialReference = m_view.spatialReference;
      //
      //       const screenExtent = {
      //         xmin: cameraPoint.x - bufferDistance,
      //         ymin: cameraPoint.y - bufferDistance,
      //         xmax: cameraPoint.x + bufferDistance,
      //         ymax: cameraPoint.y + bufferDistance,
      //         spatialReference: spatialReference,
      //       };
      //       console.warn("视图范围不足4个有效点，使用摄像机位置生成的2公里范围。");
      //       console.log(screenExtent);
      //       return screenExtent;
      //     } else {
      //       console.warn("无法获取摄像机位置，请检查视图状态。");
      //       return null;
      //     }
      //   } else {
      //     try {
      //       // 获取最小和最大坐标值
      //       const xmin = Math.min(...mapPoints.map((p) => p.x));
      //       const ymin = Math.min(...mapPoints.map((p) => p.y));
      //       const xmax = Math.max(...mapPoints.map((p) => p.x));
      //       const ymax = Math.max(...mapPoints.map((p) => p.y));
      //
      //       const screenExtent = {
      //         xmin: xmin,
      //         ymin: ymin,
      //         xmax: xmax,
      //         ymax: ymax,
      //         spatialReference: m_view.spatialReference,
      //       };
      //       console.log(screenExtent);
      //       return screenExtent;
      //     } catch (e) {
      //       console.error("获取地图范围时出错：", e);
      //       return null;
      //     }
      //   }
      // }



      function viewshedAnalysis(params){
        let status = params.status;
        if(status === "hide"){
          if(viewShedAnalysisWidget !== null){
            viewShedAnalysisWidget.clearAnalysis();
          }
          return
        }
        if(status === "show"){
          if(viewShedAnalysisWidget === null){
            viewShedAnalysisWidget = new ViewShedAnalysisWidget({  view:m_view  });
            viewShedAnalysisWidget.startAnalysis();
          }
        }
      }
      function featureLayerThreeDimension(params){
        let status = params.status;

      }
      function addLightBall(params){
        let status = params.status;
        let id = params.id;
        if(lightBallInstance[id]){
          lightBallInstance[id].clear();
          lightBallInstance[id] = null;
        }
        if(status === "hide"){
          return
        }
        let points = params.points;
        let addLightBallEvent = new AddLightBallEvent({
          view:m_view,
          points
        })
        addLightBallEvent.start()
        // 保存实例
        lightBallInstance[id] = addLightBallEvent;
      }
      function threeGrid(params){
        let status = params.status;
        if(status === "hide"){
          if(addThreeGridEvent){
            addThreeGridEvent.clear();
            addThreeGridEvent = null;
          }
          return
        }
        let animationEnabled = false;
        if(params.animationEnabled){
          animationEnabled = params.animationEnabled;
        }
        if(addThreeGridEvent){
          addThreeGridEvent.height = params.height;
          addThreeGridEvent.size = params.size;
          addThreeGridEvent.layerHeight = params.layerHeight;
          addThreeGridEvent.animationEnabled = animationEnabled;
          addThreeGridEvent.gridEnabled = true;
          addThreeGridEvent.netEnabled = true;
          addThreeGridEvent.start();
        }else{
          addThreeGridEvent = new AddThreeGridEvent({
            view:m_view,
            extent : {minX:2176,maxX:6048,minY:-1024,maxY:1352},
            height : params.height,
            size : params.size,
            layerHeight :params.layerHeight,
            gridEnabled:true,
            netEnabled:true,
            animationEnabled
          })
          addThreeGridEvent.start();
        }
      }

      function threeGridDetail(params){

      }

      function realPositionGrid(params){
        let status = params.status;

      }

      function limitHeightAnalysis(params){
        let status = params.status;
        if(limitHeightAnalysisEvent){
          limitHeightAnalysisEvent.clear();
          limitHeightAnalysisEvent =null;
        }
        if(status === "hide"){
          return
        }
        limitHeightAnalysisEvent = new LimitHeightAnalysis({
          view:m_view,
          map:m_map,
          layerId:params.layerId,
          limitH:params.limitH,
          maxLimitH:params.maxLimitH,
          rings:params.rings,
        });
        limitHeightAnalysisEvent.start()
      }

      function geometryMeshPrismEffect(params){
        let status = params.status;
        let f_layer = m_map.layers.find(item => item.id === "geometryMeshPrismEffect");
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status === "hide"){
          return
        }
        let geometryMeshPrismEffect = new GeometryMeshPrismEffect({
          view:m_view,
          m_map,
          items:params.items,
          startHeight:params.startHeight,
          rings:params.rings
        });
        m_map.add(geometryMeshPrismEffect.graphicsLayer);
      }


      function geometryMeshEffect(params){
        let status = params.status;
        let id = params.id;
        let f_layer = m_map.layers.find(item => item.id === "geometryMeshEffect" + id);
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status === "hide"){
          return
        }
        let geometryMeshEffect = new GeometryMeshEffect({
          view:m_view,
          m_map,
          id:params.id,
          data:params.data,
        });
        m_map.add(geometryMeshEffect.graphicsLayer);
      }



      // 路径冲突
      function pathConflict(params){

        pathPipe({
          "id": "conflict1",
          "status": "show",
          "paths":Path.path_conflict_1,
          "color": "#438EDB",
          "intensity": 1.2,
          "pipeRadius": 5
        });
        pathPipe({
          "id": "conflict2",
          "status": "show",
          "paths":Path.path_conflict_2,
          "color": "#438EDB",
          "intensity": 1.2,
          "pipeRadius": 5
        });

        getRealFlyPoint({
          flyList:[
            {
              "id": "67513a6e-7ce2-4121-9b11-cd6f1d28e02c",
              "speed":40,
              "uavid": "87066700-f12d-4b3e-ac77-a55a409dd30b"
            },
            {
              "id": "fba073d1-def3-4f85-9326-dff8a1ac6ea6",
              "speed":25,
              "uavid": "9556344a-c055-4156-86d4-bc57930275a2"
            }
          ]
        })


      }

      // 无人机电量预警
      function uavBatteryWarning(params){
        pathPipe({
          "id": "conflict1",
          "status": "show",
          "paths":Path.path_conflict_1,
          "color": "#438EDB",
          "intensity": 1.2,
          "pipeRadius": 10
        });
        getRealFlyPoint({
          flyList:[
            {
              "id": "67513a6e-7ce2-4121-9b11-cd6f1d28e02c",
              "speed":40,
              "uavid": "02d47b30-003c-4e7e-89ec-72255c1ebdaf"
            }
          ]
        })
      }

      //无人机偏航
      function uavYawWarning(params){
        pathPipe({
          "id": "yaw",
          "status": "show",
          "paths":Path.yaw_path,
          "color": "#438EDB",
          "intensity": 1.2,
          "pipeRadius": 10
        });
        getRealFlyPoint({
          flyList:[
            {
              "id": "6fd0fa45-de0b-4008-8d4d-afaaa15064f3",
              "speed":40,
              "uavid": "7e080fe7-dbd4-4be2-aa45-72a28da7f26c"
            }
          ]
        })
      }


      function pathPipe(params){
        let id = params.id;
        let status = params.status;
        if(pathPipeInstance[id]){
          pathPipeInstance[id].clear();
          pathPipeInstance[id] = null;
        }
        if(status === "hide"){
          return
        }
        //优化数据
        //params.paths = [MoveCar.paths1];
        let pathPipeEvent = new PathPipeEvent({
          view:m_view,
          paths:params.paths,
          color:params.color,
          pipeRadius:params.pipeRadius,
          intensity:params.intensity
        });
        pathPipeEvent.start();
        // 保存实例
        pathPipeInstance[id] = pathPipeEvent;
      }
      function flyGLTF(params){
        let id = params.id;
        let uavid = params.uavid;
        let status = params.status;
        if(status === "hide"){
          if(flyGLTFInstances[uavid]){
            flyGLTFInstances[uavid].clear();
            delete flyGLTFInstances[uavid];
          }
          return
        }
        let point = params.point;
        let duration = params.duration;
        let uavInfo = params.uavInfo;
        if(flyGLTFInstances[uavid]){
          flyGLTFInstances[uavid].updatePath(point,duration);
          if(uavInfo){
            flyGLTFInstances[uavid].updateUavInfo(uavInfo);
          }
        }else{
          let flyGLTFEvent = new FlyGLTFEvent({
            view:m_view,
            uavid,
            bus,
          })
          flyGLTFEvent.start();
          flyGLTFEvent.updatePath(point,duration);
          if(params.uavInfo){
            flyGLTFEvent.updateUavInfo(uavInfo);
          }
          flyGLTFInstances[uavid] = flyGLTFEvent;
        }
      }


      function getVirtualFlyPoint(params){
        let status = params.status;
        const connectVirtualWebSocket = (status) => {
          if(status === "show"){
            if(virtualSocket){
              virtualSocket.send(JSON.stringify(params.flyList));
            }else{
              virtualSocket = new WebSocket('ws://172.16.8.44:9250/low-altitude/simulate/getRouteInfoWebSocket');
              virtualSocket.onopen = () => {
                console.log('WebSocket 连接成功');
                virtualSocket.send(JSON.stringify(params.flyList));
              };
              virtualSocket.onmessage = (messageEvent) => {
                let messages = JSON.parse(messageEvent.data).data;
                messages.forEach(message => {
                  flyGLTF({
                    id:message.id,
                    uavid:message.uavid,
                    status:message.routeInfoVO.status == 3?"hide":"show",
                    duration:2100,
                    //duration:3000,
                    point:message.position_cj,
                    uavInfo: {
                      type:"safe",
                      data:message.routeInfoVO,
                      origin:message.routeInfoVO
                    }
                  });
                })
              };

              virtualSocket.onerror = (error) => {
                console.error('WebSocket 出错:', error);
              };

              virtualSocket.onclose = () => {
                console.log('WebSocket 连接已关闭');
              };
            }
          }else{
            if(virtualSocket){
              virtualSocket.close();
            }
          }
        };
        connectVirtualWebSocket(status);
      }

      function getFixedFlyPoint(params){
        let status = params.status;
        let data = params.paths;
        let id = params.id;
        // let data  = params.paths;
        // let id = params.id;
        //设置定时2秒发送data里面下一个点执行flyGltf

        if (status === "show") {
          // 清除已有定时器避免重复
          if (getFixedFlyInstance[id]) {
            clearInterval(getFixedFlyInstance[id].timerId);
            getFixedFlyInstance[id].timerId = null;
            getFixedFlyInstance[id] = null;
          }
          // 重置索引以重新开始
          getFixedFlyInstance[id] = {};
          getFixedFlyInstance[id].currentIndex = 0;
          // 设置新定时器
          getFixedFlyInstance[id].timerId = setInterval(() => {
            if (getFixedFlyInstance[id].currentIndex < data.length) {
              // 获取当前点并发送
              debugger
              let currentPoint = data[getFixedFlyInstance[id].currentIndex];
              flyGLTF({
                uavid:id,
                status:"show",
                duration:2000,
                //duration:3000,
                point:currentPoint
              });
              getFixedFlyInstance[id].currentIndex++;
            } else {
              // 数据发送完毕，清除定时器
              clearInterval(getFixedFlyInstance[id].timerId);
              getFixedFlyInstance[id].timerId = null;
              getFixedFlyInstance[id] = null;
            }
          }, 2000); // 每2秒执行一次
        } else {
          // 状态非show时停止发送
          debugger
          if (getFixedFlyInstance[id]?.timerId !== null && getFixedFlyInstance[id]?.timerId !== undefined) {
            clearInterval(getFixedFlyInstance[id].timerId);
            getFixedFlyInstance[id].timerId = null;
          }
          getFixedFlyInstance[id] = null;
          flyGLTF({
            uavid:id,
            status:"hide"
          });
        }
      }



      function getRealFlyPoint(params){
        const connectWebSocket = () => {
          if(socket){
            socket.send(JSON.stringify(params.flyList));
          }else{
            socket = new WebSocket('ws://172.16.8.44:9250/low-altitude/aircraftRouteSpeedWebSocket');
            socket.onopen = () => {
              console.log('WebSocket 连接成功');
              socket.send(JSON.stringify(params.flyList));
            };
            socket.onmessage = (messageEvent) => {
              let messages = JSON.parse(messageEvent.data).data;
              realFlyPointDataQueue.push(messages);
            };
            socket.onerror = (error) => {
              console.error('WebSocket 出错:', error);
            };

            socket.onclose = () => {
              console.log('WebSocket 连接已关闭');
            };
          }
        };
        connectWebSocket();
        processRealFlyPointData();
      }

      //如果是等待，就要设置另一台无人机继续飞行
      function processRealFlyPointData(){
        setInterval(() => {
          if (realFlyPointDataQueue.length > 0) {
            const messages = realFlyPointDataQueue.shift(); // 从队列中取出数据
            //发送消息
            bus.emit('SendMessage',{
              action:"RealTimeUAVList",
              data:{
                "message":messages
              }
            })
            messages.forEach(message => {
              message.routeInfoVO.speed = message.routeInfoVO.speed * 1 +(Math.random() * 2).toFixed(2) * 1
              if(message.overall === "SAFE"){
                addGraphics({
                  "id": message.uavid+'_conflict',
                  "status": "hide"
                });
                pathPipe({
                  "id": message.uavid+'_conflict',
                  "status": "hide"
                });
                flyGLTF({
                  id:message.id,
                  uavid:message.uavid,
                  status:message.routeInfoVO.status == 3?"hide":"show",
                  //duration:message.time + 100,
                  duration:2500,
                  point:message.position_cj,
                  uavInfo: {
                    type:"safe",
                    data:message.routeInfoVO,
                    origin:message.routeInfoVO
                  }
                });
              }else{
                if(message.nearestAircraft.status !="SAFE"){ //碰撞
                  flyGLTF({
                    id:message.id,
                    uavid:message.uavid,
                    status:message.routeInfoVO.status == 3?"hide":"show",
                    //duration:message.time + 100,
                    duration:2500,
                    point:message.position_cj,
                    uavInfo: {
                      type:"conflict",
                      action:message.routeInfoVO.avoidanceType,
                      data:message.routeInfoVO.avoidanceType == "wait" ?message.nearestAircraft:message.routeInfoVO,
                      origin:{
                        ...message.nearestAircraft,
                        ...message.routeInfoVO
                      }
                    }
                  });
                  addGraphics({
                    id: message.uavid+'_conflict',
                    status:message.routeInfoVO.status == 3?"hide":"show",
                    data: {
                      "geometry": { "type": "point", "x": message.nearestAircraft.conflictPoint[0],   "y":  message.nearestAircraft.conflictPoint[1], "z": message.nearestAircraft.conflictPoint[2] },
                      "attributes": { "name": "碰撞点位" }
                    }
                  });
                  pathPipe({
                    "id": message.uavid+'_conflict',
                    "status": message.routeInfoVO.status == 3?"hide":"show",
                    "paths":[message.nearestAircraft.conflictPath],
                    "color": "#FF0000",
                    "intensity": 1.5,
                    "pipeRadius": 10
                  });
                }else{
                  addGraphics({
                    "id": message.uavid+'_conflict',
                    "status": "hide"
                  });
                  pathPipe({
                    "id": message.uavid+'_conflict',
                    "status": "hide"
                  });
                  // if(message.noFlyZone.status != "SAFE"){
                  //   console.log("禁飞区预警",message);
                  //   flyGLTF({
                  //     id:message.id,
                  //     uavid:message.uavid,
                  //     status:message.routeInfoVO.status == 3?"hide":"show",
                  //     //duration:message.time + 100,
                  //     duration:2100,
                  //     point:message.position_cj,
                  //     uavInfo: {
                  //       type:"noFlyZone",
                  //       data:message.routeInfoVO,
                  //       origin:message.routeInfoVO
                  //     }
                  //   });
                  // }else

                  if(message.routeDeviate.status != "SAFE" && message.routeDeviate.distance * 1 > 14){
                    console.log("偏航异常预警",message);
                    flyGLTF({
                      id:message.id,
                      uavid:message.uavid,
                      status:message.routeInfoVO.status == 3?"hide":"show",
                      //duration:message.time + 100,
                      duration:2500,
                      point:message.position_cj,
                      uavInfo: {
                        type:"routeDeviate",
                        data:message.routeDeviate,
                        index:message.index,
                        origin:{
                          ...message.routeDeviate,
                          ...message.routeInfoVO
                        }
                      }
                    });
                  }
                      //   else if(message.electricityWarning.status != "SAFE"){
                      //   console.log("电量异常预警",message);
                      //   flyGLTF({
                      //     id:message.id,
                      //     uavid:message.uavid,
                      //     status:message.routeInfoVO.status == 3?"hide":"show",
                      //     //duration:message.time + 100,
                      //     duration:2100,
                      //     point:message.position_cj,
                      //     uavInfo: {
                      //       type:"electricityWarning",
                      //       data:message.electricityWarning,
                      //       origin:message.routeInfoVO
                      //     }
                      //   });
                      // }
                      //   else if(message.collision.status != "SAFE"){
                      //   console.log("建筑物过近异常信息",message);
                      //   flyGLTF({
                      //     id:message.id,
                      //     uavid:message.uavid,
                      //     status:message.routeInfoVO.status == 3?"hide":"show",
                      //     //duration:message.time + 100,
                      //     duration:2100,
                      //     point:message.position_cj,
                      //     uavInfo: {
                      //       type:"collision",
                      //       data:message.collision,
                      //       origin:message.routeInfoVO
                      //     }
                      //   });
                      // }

                      //   else if(message.clearZone.status != "SAFE"){
                      //   console.log("净空区异常预警",message);
                      //   flyGLTF({
                      //     id:message.id,
                      //     uavid:message.uavid,
                      //     status:message.routeInfoVO.status == 3?"hide":"show",
                      //     //duration:message.time + 100,
                      //     duration:2100,
                      //     point:message.position_cj,
                      //     uavInfo: {
                      //       type:"clearZone",
                      //       data:message.clearZone,
                      //       origin:message.routeInfoVO
                      //     }
                      //   });
                  // }
                  else{
                    flyGLTF({
                      id:message.id,
                      uavid:message.uavid,
                      status:message.routeInfoVO.status == 3?"hide":"show",
                      //duration:message.time + 100,
                      duration:2500,
                      point:message.position_cj,
                      uavInfo: {
                        type:"safe",
                        data:message.routeInfoVO,
                        origin:message.routeInfoVO
                      }
                    });
                  }
                }
              }
            })
          } else {
            console.log("No data to process.");
          }
        }, 2500); // 每3秒处理一次数据
      }

      function conflict_fly(params){
        let uavid = params.uavid;
        let skip_route_id = params.skip_route_id;
        let distance = params.distance;
        getAvoidRoute({
          uavid:uavid,
          skip_route_id:skip_route_id,
          distance:distance
        }).then(res =>{
          console.log("临时路线",res);
          pathPipe({
            "id": uavid+'_change',
            "status": "show",
            "paths":[res.data.data.pathAll],
            "color": "#438EDB",
            "intensity": 1.2,
            "pipeRadius": 5
          });
          getRealFlyPoint({
            flyList:{
              "path": res.data.data.pathAll,
              "avoidanceType":"avoid",
              "uavid": uavid
            }
          })
        })
      }


      function changePointStatus(params){
        flyGLTFInstances[params.uavid].followPath(params.isFollow);
      }
      //ws 推送方法
      function getRealPower(params){
        const connectWebSocket = () => {
          socket = new WebSocket('ws://172.16.8.44:9250/low-altitude/gridSearchWebSocket');
          socket.onopen = () => {
            console.log('WebSocket 连接成功');
            socket.send(JSON.stringify({
              "locationPoint": {
                "mapX":  6454.080981250964,
                "mapY": 5487.978352845347
              },
              "radiusInMeters": 5000,
              "minZ": 1,
              "maxZ": 120,
              "routes": [
              ],
              "fields":["gridCode","x","y","z"],
              "scrollPage": {
                "pageIndex": 1,
                "pageSize": 10000,
                "scrollId": ""
              },
              "level":20,
              "className":"LowAltitudeGrid"
            }));
          };

          socket.onmessage = (messageEvent) => {
            let messages = JSON.parse(messageEvent.data);
            messages.data.list.forEach((point) =>{
              point.color = [0, 1, 1];
            });
            console.log("messages.data.list",messages.data.list)
            let para = {
              "id":"1",
              "status":"show",
              "size":{
                x:46,
                y:54,
                z:53
              },
              "points":messages.data.list,
            }
            showThreeCubeDetail(para);
          };

          socket.onerror = (error) => {
            console.error('WebSocket 出错:', error);
          };

          socket.onclose = () => {
            console.log('WebSocket 连接已关闭');
          };
        };
        connectWebSocket();
      }

      //无极变换
      function getCurrentRealPower(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let center = params.center;
        let radius = params.radius;
        let minZ = params.minZ;
        let maxZ = params.maxZ;
        let size = params.size;
        let fields = params.fields;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id,
            status:"hide"
          });
          currentRealPowerIds = {
            power_wj_15:[],
            power_wj_16:[],
            power_wj_17:[],
            power_wj_18:[],
            power_wj_19:[],
            power_wj_20:[],
            power_wj_21:[],
            power_wj_22:[],
            power_wj_23:[]
          };
          currentRealPowerLevel = null;
          return
        }
        getCurrentPowerPoints({
          id,
          "x": center.x,
          "y": center.y,
          status,
          radius,
          size,
          minZ,
          maxZ,
          level,
          fields,
          scrollId:""
        });
      }

      // 无极变化-获取权重数据
      function getCurrentPowerPoints(params) {
        getPowerPoint({
          x: params.x,
          y: params.y,
          radius:params.radius,
          minZ:params.minZ,
          maxZ:params.maxZ,
          level: params.level,
          fields: params.fields,
          scrollId: params.scrollId,
        }).then(res =>{
            if (currentRealPowerShow) {
              if (res.data.data.list?.length > 0) {
                let data = res.data.data.list;
                let responseLevel = res.data.data.list[0].level;
                console.log("当前执行的level-需要的level",responseLevel,currentRealPowerLevel)
                let newData = [];
                if(responseLevel === currentRealPowerLevel){
                  if (currentRealPowerIds[params.id +'_'+ currentRealPowerLevel].length > 0) {
                    //将data对象数组中girdCode与currentRealPowerIds数组中的元素进行对比，如果相同则不添加到newData数组中
                    newData = data.filter(item => !currentRealPowerIds[params.id +'_'+ currentRealPowerLevel].includes(item.gridCode));
                    let newDataIds = newData.map(item => item.gridCode);
                    currentRealPowerIds[params.id +'_'+ currentRealPowerLevel]= [...currentRealPowerIds[params.id +'_'+ currentRealPowerLevel], ...newDataIds];
                  } else {
                    //将data对象数组中girdCode取出来，组成一个数组
                    let gridCodes = data.map(item => item.gridCode);
                    currentRealPowerIds[params.id +'_'+ currentRealPowerLevel] = gridCodes;
                    newData = data;
                  }
                }
                showThreeCubeDetail({
                  "id": params.id + currentRealPowerLevel,
                  "status": params.status,
                  "size": {
                    x:newData[0].boxSize.latLength,
                    y:newData[0].boxSize.lonLength,
                    z:newData[0].boxSize.height
                  },
                  "points": newData,
                })
                bus.emit('SendMessage',{
                  action:"CurrentCubeLevel",
                  data:{
                    "level":currentRealPowerLevel
                  }
                })
                closeOtherThreeCubeDetail(params.id,currentRealPowerLevel)
              }
            }
        })
      }

      function closeOtherThreeCubeDetail(paramsId,index){
        let levels = [15,16,17,18,19,20,21,22,23];
        let newLevels = levels.filter(item => item != index);
        newLevels.forEach((level) =>{
          showThreeCubeDetail({
            "id":paramsId + level,
            "status":"hide"
          })
          currentRealPowerIds[paramsId +'_'+ level] = [];
        })

      }



      //获取当前场景
      function getRealPower2(params){
        let id = params.id;
        let lastId = params.lastId;
        let status = params.status;
        let level = params.level;
        let center = params.center;
        let radius = params.radius;
        let minZ = params.minZ;
        let maxZ = params.maxZ;
        let size = params.size;
        let fields = params.fields;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id,
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        showThreeCubeDetail({
          id:params.lastId,
          status:"hide"
        });
        currentShowGridParams = id;
        getSixPowerPoints({
          id,
          lastId,
          "x": center.x,
          "y": center.y,
          status,
          radius,
          size,
          minZ,
          maxZ,
          level,
          fields,
          scrollId:""
        });
      }

      // 获取当前场景-递归获取权重数据
      function getSixPowerPoints(params) {
        getPowerPoint({
          x: params.x,
          y: params.y,
          radius:params.radius,
          minZ:params.minZ,
          maxZ:params.maxZ,
          level: params.level,
          fields: params.fields,
          scrollId: params.scrollId,
        }).then(res =>{
          if(currentShowGridParams === params.id){
            if(res.data.data.list?.length >= 100000 && res.data.data.scrollId){
              // res.data.data.list.forEach((point) =>{
              //   point.color = [0, 1, 1];
              // });
              // res.data.data.list.forEach((item)=>{
              //   item.color = getColor(item.averageValue, -50, 50);
              // })
              showThreeCubeDetail({
                "id":params.id,
                "status":params.status,
                "size":params.size,
                "points":res.data.data.list,
              })
              params.scrollId = res.data.data.scrollId;

              getSixPowerPoints(params);
            }else{
              if(res.data.data.list?.length > 0){
                showThreeCubeDetail({
                  "id":params.id,
                  "status":params.status,
                  "size":params.size,
                  "points":res.data.data.list,
                })
              }
            }
          }
        })
      }





      //需要添加初始路径（手动绘制和自动绘制）结果
      function draw(params){
        let id = params.id;
        let geometryType = params.type;
        let status = params.status;
        let path = params.path;
        let hasZ = params.hasZ;
        let symbol = params.symbol;
        let clear = true;
        if(params.clear !== undefined){
          clear = params.clear;
        }
        if(clear){
          if(addDrawEvent){
            addDrawEvent.clear();
            addDrawEvent = null;
          }
        }
        if(status === "hide"){
          return
        }
        if(!addDrawEvent){
          addDrawEvent = new AddDrawEvent({
            view:m_view,
            type:geometryType,
            symbol,
            path:path,
            hasZ,
            once:true
          });
        }
        if(path){
          addDrawEvent.update();
          bus.emit('SendMessage',{
            action:"DrawComplete",
            data:{
              "geometry":{
                type: "polyline",
                paths: [path], // 示例路径坐标
                spatialReference: m_view.spatialReference,
              }
            }
          })
        }else{
          addDrawEvent.start(symbol,geometryType);
        }
        addDrawEvent.createListenerEvent((geometry) =>{
          bus.emit('SendMessage',{
            action:"DrawComplete",
            data:{
              "geometry":geometry
            }
          })
        });
        addDrawEvent.updateListenerEvent((geometry) =>{
          bus.emit('SendMessage',{
            action:"DrawComplete",
            data:{
              "geometry":geometry
            }
          })
        });
      }


      //态势评估
      function situationAssessment(params){
        routeList.list.forEach((item) =>{
          pathPipe({
            id: item.id,
            paths: [item.path],
            color:item.color,
            status: params.status,
            "intensity": 1.2,
            "pipeRadius": 10
          })
        })
        featurePointsPlotting({
          status: params.status,
          data:routeList.points
        });
        routeList.conflictList.forEach((item) =>{
          item.status = params.status =="show"?1:3
        })
        //先加载所有的无人机和航线
        getRealFlyPoint({
          status: params.status,
          flyList:params.status=="show"?routeList.conflictList:routeList.conflictList
        })

      }


      function draw_GeometryMeshPrismEffect(params){
        let geometryType = params.type;
        let status = params.status;
        let startHeight = params.startHeight;
        let items = params.items;
        if(addDrawEvent){
          addDrawEvent.clear();
          addDrawEvent = null;
        }
        if(draw_GeometryMeshPrismEffectEvent){
          draw_GeometryMeshPrismEffectEvent.clear();
          draw_GeometryMeshPrismEffectEvent = null;
        }
        let f_layer = m_map.layers.find(item => item.id === "geometryMeshPrismEffect");
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status == "hide"){
          return
        }
        addDrawEvent = new AddDrawEvent({
          view:m_view,
          type:geometryType
        })
        addDrawEvent.start();
        addDrawEvent.createListenerEvent((geometry)=>{
          if(draw_GeometryMeshPrismEffectEvent){
            draw_GeometryMeshPrismEffectEvent.clear();
            draw_GeometryMeshPrismEffectEvent = null;
          }
          draw_GeometryMeshPrismEffectEvent = new GeometryMeshPrismEffect({
            view:m_view,
            m_map,
            items:items,
            startHeight:startHeight,
            rings:geometry.rings
          });
          m_map.add(draw_GeometryMeshPrismEffectEvent.graphicsLayer);
        })
        addDrawEvent.updateListenerEvent((geometry)=>{
          if(draw_GeometryMeshPrismEffectEvent){
            draw_GeometryMeshPrismEffectEvent.clear();
            draw_GeometryMeshPrismEffectEvent = null;
          }
          draw_GeometryMeshPrismEffectEvent = new GeometryMeshPrismEffect({
            view:m_view,
            m_map,
            items:items,
            startHeight:startHeight,
            rings:geometry.rings
          });
          m_map.add(draw_GeometryMeshPrismEffectEvent.graphicsLayer);
        })
      }

      function symbolPathPipe(params){
        let status = params.status;
        let f_layer = m_map.layers.find(item => item.id === "symbolPathPipeEvent");
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status === "hide"){
          return
        }
        // params.paths = Path.paths
        symbolPathPipeEvent = new SymbolPathPipeEvent({
          view:m_view,
          paths:params.paths,
        })
        m_map.add(symbolPathPipeEvent.graphicsLayer);
      }

      function symbolPointCube(params){
        let status = params.status;
        let f_layer = m_map.layers.find(item => item.id === "symbolPointCubeEvent");
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status === "hide"){
          return
        }
        symbolPointCubeEvent = new SymbolPointCubeEvent({
          view:m_view,
          points:params.points,
          size:params.size,
        })
        m_map.add(symbolPointCubeEvent.graphicsLayer);
      }

      function addGraphics(params){
        let status = params.status;
        let id = params.id;
        if(status === "hide"){
          let idGraphic = m_view.graphics.find(item => item.id === id);
          if(idGraphic){
            m_view.graphics.remove(idGraphic);
          }
          return
        }
        let idGraphic = m_view.graphics.find(item => item.id === id);
        if(idGraphic && JSON.stringify(params.data.geometry) == JSON.stringify(idGraphic.geometry)){
         return
        }else{
          m_view.graphics.remove(idGraphic);
          addGraphicsEvent = new AddGraphicsEvent({
            id,
            view:m_view,
            data:params.data,
            imgType:params.imgType
          })
        }
      }


      function featurePointsPlotting(params){
        let status = params.status;
        let f_layer = m_map.layers.find(item => item.id === "featurePointsPlottingEvent");
        if (f_layer) {
          m_map.remove(f_layer);
        }
        if(status === "hide"){
          return
        }
        //params.data = Path.paths_point;
        featurePointsPlottingEvent = new FeaturePointsPlottingEvent({
          view:m_view,
          data:params.data,
          imgType:params.imgType
        })
        m_map.add(featurePointsPlottingEvent.featureLayer);
      }


      function featurePolygonPlotting(params){
        let status = params.status;
        let id = params.id;
        let p_layer = m_map.layers.find(item => item.id === id+"_polygon");
        if (p_layer) {
          m_map.remove(p_layer);
        }
        let t_layer = m_map.layers.find(item => item.id === id+"_text");
        if (t_layer) {
          m_map.remove(t_layer);
        }
        if(status === "hide"){
          return
        }
        let showText = false;
        if(params.showText){
          showText = params.showText;
        }
        featurePointsPlottingEvent = new FeaturePolygonPlottingEvent({
          id,
          view:m_view,
          data:params.data,
          showText:showText
        });
      }

      function flowPathEffect(params){
        let status = params.status;
        if(addFlowPathEvent){
          addFlowPathEvent.clear();
          addFlowPathEvent = null;
        }
        if(status === "hide"){
          return
        }
        addFlowPathEvent = new AddFlowPathEvent({
          view:m_view,
          paths:params.paths,
          color:params.color,
          pipeRadius:params.pipeRadius
        })
        addFlowPathEvent.start()
      }


      function movePoint(params){
        let status = params.status;
        const connectFlyPointWebSocket = (status) => {
          if(status === "show"){
            if(flyPointSocket){
              flyPointSocket.send(JSON.stringify({
                  "flightIdS": ["EFF7AE7B8B044436997F93F327819C20","18207414-c19e-4233-87e2-e6e4743fdea0"],
                  "messageCode": 1,
                  "isShow": true
              }));
            }else{
              flyPointSocket = new WebSocket('ws://172.16.8.44:9250/low-altitude/flight/data/websocket');
              flyPointSocket.onopen = () => {
                console.log('WebSocket 连接成功');
              };
              flyPointSocket.onmessage = (messageEvent) => {
                showThreeCubeDetail({
                  "id":"movePointCube",
                  "status":"hide"
                })
                let messages = JSON.parse(messageEvent.data);
                if(movePointEvent){
                  movePointEvent.update(messages)
                }else{
                  movePointEvent = new MovePointStreamEvent({
                    view:m_view,
                    map:m_map,
                    data:messages
                  });
                }
                let data = [];
                let points = []
                if(messages.length > 0){
                  messages.forEach((item)=>{
                    if(item.surroundGrid != null&&item.surroundGrid.length > 0){
                      if(ShowMovePointCube) {
                        data = data.concat(item.surroundGrid);
                      }else {
                        item.surroundGrid.forEach((index)=>{
                          if(index.color[0] =1 && index.color[1] == 0 && index.color[2] == 0){
                             data.push(index)
                          }
                        })
                      }
                    }
                    points.push([item.x,item.y,item.z])
                  })
                    if(data.length > 0){
                      showThreeCubeDetail({
                        "id":"movePointCube",
                        "status":"show",
                        "size": {
                          x:data[0].boxSize.latLength,
                          y:data[0].boxSize.lonLength,
                          z:data[0].boxSize.height
                        },
                        "deepOpacity":true,
                        "points":data,
                        "depthTest":false
                      })
                    }
                  if(points.length > 0){
                    addLightBall({
                      id:"ball",
                      status:"show",
                      points:points,
                    })
                  }
                }
              };

              flyPointSocket.onerror = (error) => {
                console.error('WebSocket 出错:', error);
              };

              flyPointSocket.onclose = () => {
                console.log('WebSocket 连接已关闭');
              };
            }
          }else{
            if(flyPointSocket){
              if(movePointEvent){
                movePointEvent.clear();
                movePointEvent = null;
              }
              showThreeCubeDetail({
                "id":"movePointCube",
                "status":"hide"
              });
              addLightBall({
                id:"ball",
                status:"hide"
              })
              flyPointSocket.close();
              flyPointSocket = null
            }
          }
        };
        connectFlyPointWebSocket(status);
      }


      function movePaths(params){
        let status = params.status;
        if(status === "show"){
          queryPathsInfo().then(res=>{
            if(res.data.code === 200){
              let data = res.data.data;
              data.forEach((item)=>{
                pathPipe({
                  id:item.id,
                  status:"show",
                  paths:JSON.parse(item.shape).paths,
                  color: "#438EDB",
                  intensity: 1.2,
                  pipeRadius: 5
                })
              })
            }
          })
        }else{
          queryPathsInfo().then(res=>{
            if(res.data.code === 200){
              let data = res.data.data;
              data.forEach((item)=>{
                pathPipe({
                  id:item.id,
                  status:"hide"
                })
              })
            }
          })
        }
      }

      function showMovePointCube(params){
        let status = params.status;
        if(status == "show"){
          ShowMovePointCube = true;
        }else{
          ShowMovePointCube = false;
        }
      }


      //获取当前场景
      function getOccupyCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let minZ = params.minZ;
        let maxZ = params.maxZ;
        let rings = params.rings;
        let fields = params.fields;
        let deepShow = params.deepShow;
        // if(status === "hide"){
        //   showThreeCubeDetail({
        //     id:"test",
        //     status:"hide"
        //   });
        //   currentShowGridParams = null;
        //   return
        // }
        // //备用方案：根据rings四至范围生成矩形面，获取左下角的点为原点，距离分别为长、宽
        //
        // let { origin,length,width } = createBoundingBoxFromRings(rings);
        //
        // debugger
        // const cubeGrid = generateGrid({
        //   x:origin[0],
        //   y:origin[1],
        //   z:minZ,
        // }, length, width, maxZ-minZ,32);
        // showThreeCubeDetail({
        //   "id":"test",
        //   "status":"show",
        //   "size": {
        //     x:32,
        //     y:32,
        //     z:32
        //   },
        //   "points":cubeGrid,
        //   "depthTest":false
        // })
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id,
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        showThreeCubeDetail({
          id:params.lastId,
          status:"hide"
        });
        currentShowGridParams = {
          id,
          level,
          minZ,
          maxZ,
          rings,
          fields
        };
        getOccupyByPolygon({
          id,
          status,
          minZ,
          maxZ,
          level,
          fields,
          rings,
          deepShow,
          scrollId:""
        });
      }

      // 获取当前场景-递归获取权重数据
      function getOccupyByPolygon(params) {
        debugger
        getOccupyPointByPolygon({
          minZ:params.minZ,
          maxZ:params.maxZ,
          level: params.level,
          rings: params.rings,
          fields: params.fields,
          scrollId: params.scrollId,
        }).then(res =>{
          if(JSON.stringify(currentShowGridParams) === JSON.stringify({
            id:params.id,
            level:params.level,
            minZ:params.minZ,
            maxZ:params.maxZ,
            rings:params.rings,
            fields:params.fields,
          })){
            if(res.data.data.list?.length >= 100000 && res.data.data.scrollId){
              let length = 8;
              for(let i=0;i<15-params.level;i++){
                length = length * 2;
              }
              let size = {
                x:length,
                y:length,
                z:length
              }
              showThreeCubeDetail({
                "id":params.id,
                "status":params.status,
                "size":size,
                "points":res.data.data.list,
                "depthTest":params.deepShow?params.deepShow:false
              })
              params.scrollId = res.data.data.scrollId;
              getOccupyByPolygon(params);
            }else{
              if(res.data.data.list?.length > 0){
                let length = 8;
                for(let i=0;i<15-params.level;i++){
                  length = length * 2;
                }
                let size = {
                  x:length,
                  y:length,
                  z:length
                }
                showThreeCubeDetail({
                  "id":params.id,
                  "status":params.status,
                  "size":size,
                  "points":res.data.data.list,
                  "depthTest":params.deepShow?params.deepShow:false
                })
              }
            }
          }
        })
      }


      function generateGrid(startPoint,xRange, yRange, zRange, size) {
        const grid = [];

        // 计算每个方向的立方体数量
        const xCount = Math.ceil(xRange / size);
        const yCount = Math.ceil(yRange / size);
        const zCount = Math.ceil(zRange / size);

        // 生成网格点
        for (let x = 0; x < xCount; x++) {
          for (let y = 0; y < yCount; y++) {
            for (let z = 0; z < zCount; z++) {
              grid.push({
                x: startPoint.x* 1 + x * size,
                y: startPoint.y * 1 + y * size,
                z: startPoint.z * 1 + z * size,
                color: [0,1,1]
              });
            }
          }
        }

        return grid;
      }


      function createBoundingBoxFromRings(rings) {
        // 初始化四至范围
        let xmin = Infinity, ymin = Infinity;
        let xmax = -Infinity, ymax = -Infinity;

        // 遍历所有点找到四至范围
        rings.forEach(ring => {
          ring.forEach(point => {
            const [x, y] = point;
            xmin = Math.min(xmin, x);
            ymin = Math.min(ymin, y);
            xmax = Math.max(xmax, x);
            ymax = Math.max(ymax, y);
          });
        });

        // 创建矩形面坐标
        const rectangle = [
          [xmin, ymin], // 左下
          [xmax, ymin], // 右下
          [xmax, ymax], // 右上
          [xmin, ymax], // 左上
          [xmin, ymin]  // 闭合
        ];

        return {
          origin: [xmin, ymin], // 原点
          length: xmax - xmin,  // 长度
          width: ymax - ymin
        };
      }




      //获取当前场景
      function getPowerCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let minZ = params.minZ;
        let maxZ = params.maxZ;
        let deepShow = params.deepShow;
        let rings = params.rings;
        let fields = params.fields;


        // if(status === "hide"){
        //   showThreeCubeDetail({
        //     id:"test",
        //     status:"hide"
        //   });
        //   currentShowGridParams = null;
        //   return
        // }
        // //备用方案：根据rings四至范围生成矩形面，获取左下角的点为原点，距离分别为长、宽
        //
        // let { origin,length,width } = createBoundingBoxFromRings(rings);
        //
        // debugger
        // const cubeGrid = generateGrid({
        //   x:origin[0],
        //   y:origin[1],
        //   z:minZ,
        // }, length, width, maxZ-minZ,32);
        // showThreeCubeDetail({
        //   "id":"test",
        //   "status":"show",
        //   "size": {
        //     x:32,
        //     y:32,
        //     z:32
        //   },
        //   "points":cubeGrid,
        //   "depthTest":false
        // })
        //
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id,
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = {
          id,
          level,
          minZ,
          maxZ,
          rings,
          fields
        };
        getSixPowerByPolygon({
          id,
          status,
          minZ,
          maxZ,
          level,
          fields,
          rings,
          deepShow,
          scrollId:"",
        });
      }

      // 获取当前场景-递归获取权重数据
      function getSixPowerByPolygon(params) {
        getPowerPointByPolygon({
          minZ:params.minZ,
          maxZ:params.maxZ,
          level: params.level,
          rings: params.rings,
          fields: params.fields,
          scrollId: params.scrollId,
        }).then(res =>{
          if(JSON.stringify(currentShowGridParams) === JSON.stringify({
            id:params.id,
            level:params.level,
            minZ:params.minZ,
            maxZ:params.maxZ,
            rings:params.rings,
            fields:params.fields,
          })){
            if(res.data.data.list?.length >= 100000 && res.data.data.scrollId){
              let length = 8;
              for(let i=0;i<15-params.level;i++){
                length = length * 2;
              }
              let size = {
                x:length,
                y:length,
                z:length
              }
              showThreeCubeDetail({
                "id":params.id,
                "status":params.status,
                "size":size,
                "points":res.data.data.list,
                "depthTest":params.deepShow?params.deepShow:false
              })
              params.scrollId = res.data.data.scrollId;
              getSixPowerByPolygon(params);
            }else{
              if(res.data.data.list?.length > 0){
                let length = 8;
                for(let i=0;i<15-params.level;i++){
                  length = length * 2;
                }
                let size = {
                  x:length,
                  y:length,
                  z:length
                }
                showThreeCubeDetail({
                  "id":params.id,
                  "status":params.status,
                  "size":size,
                  "points":res.data.data.list,
                  "depthTest":params.deepShow?params.deepShow:false
                })
              }
            }
          }
        })
      }


      function getFunnelCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let coneHeight = params.coneHeight;
        let cylinderHeight = params.cylinderHeight;
        let topRadius = params.topRadius;
        let bottomRadius = params.bottomRadius;
        let point = params.point;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByFunnel({
          id,
          status,
          coneHeight,
          cylinderHeight,
          level,
          topRadius,
          bottomRadius,
          point
        });
      }


      function getSixPowerByFunnel(params){
        getPowerPointByFunnel({
          point:params.point,
          coneHeight:params.coneHeight,
          cylinderHeight:params.cylinderHeight,
          level: params.level,
          topRadius: params.topRadius,
          bottomRadius: params.bottomRadius,
        }).then(res =>{
          //处理返回网格结果
          feedbackCubeResult(params,res)
        }).catch(()=>{
          feedbackErrorResult()
        })
      }

      function getFrustumConeCube(params){
        let id = params.id;
        let lastId = params.lastId;
        let status = params.status;
        let level = params.level;
        let height = params.height;
        let topRadius = params.topRadius;
        let bottomRadius = params.bottomRadius;
        let point = params.point;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByFrustumCone({
          id,
          status,
          height,
          level,
          topRadius,
          bottomRadius,
          point
        });
      }


      function getSixPowerByFrustumCone(params){
        getPowerPointByFrustumCone({
          point:params.point,
          height:params.height,
          level: params.level,
          topRadius: params.topRadius,
          bottomRadius: params.bottomRadius,
        }).then(res =>{
          //处理返回网格结果
          feedbackCubeResult(params,res)
        }).catch(()=>{
          feedbackErrorResult()
        })
      }

      function getInvertedConeCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let height = params.height;
        let radius = params.radius;
        let point = params.point;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByInvertedCone({
          id,
          status,
          height,
          level,
          radius,
          point
        });
      }

      function getSixPowerByInvertedCone(params){
        getPowerPointByInvertedCone({
          point:params.point,
          height:params.height,
          level: params.level,
          radius: params.radius,
        }).then(res =>{
          //处理返回网格结果
          feedbackCubeResult(params,res)
        }).catch(()=>{
          feedbackErrorResult()
        })
      }

      //查询圆柱体
      function getCylinderCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let height = params.height;
        let rings = params.rings;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByPrism({
          id,
          status,
          height,
          level,
          rings
        });
      }

      //查询长方体
      function getCuboidCube(params){
        let id = params.id;
        let lastId = params.lastId;
        let status = params.status;
        let level = params.level;
        let height = params.height;
        let rings = params.rings;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByPrism({
          id,
          status,
          height,
          level,
          rings
        });
      }


      //查询棱柱体
      function getPrismCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let height = params.height;
        let rings = params.rings;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });

          currentShowGridParams = null;
          return
        }
        currentShowGridParams = id;
        getSixPowerByPrism({
          id,
          status,
          height,
          level,
          rings
        });
      }

      function getSixPowerByPrism(params){
        getPowerPointByPrism({
          rings:params.rings,
          height:params.height,
          level: params.level
        }).then(res =>{
          //处理返回网格结果
          feedbackCubeResult(params,res)
        }).catch(()=>{
          feedbackErrorResult()
        })
      }


      //查询航线
      function getPathCube(params){
        let id = params.id;
        let status = params.status;
        let level = params.level;
        let radius = params.radius;
        let originPaths = params.paths;
        if(status === "hide"){
          showThreeCubeDetail({
            id:params.id+ "23",
            status:"hide"
          });
          showThreeCubeDetail({
            id:params.id+ "24",
            status:"hide"
          });
          currentShowGridParams = null;
          return
        }
        let paths = [];
        originPaths[0].forEach((item)=>{
          paths.push({
            x:item[0],
            y:item[1],
            z:item[2]
          })
        })
        currentShowGridParams = id;
        getSixPowerByPath({
          id,
          status,
          radius,
          level,
          paths
        });
      }

      function getSixPowerByPath(params){
        getPowerPointByPath({
          paths:params.paths,
          radius:params.radius,
          level: params.level
        }).then(res =>{
          //处理返回网格结果
          feedbackCubeResult(params,res);
        }).catch(()=>{
          feedbackErrorResult()
        })
      }

      function feedbackCubeResult(params,res){
        bus.emit('SendMessage',{
          action:"CubeResult",
          data:{
            "message":{
              "time":new Date().getTime(),
              "data":"success"
            }
          }
        })
        if(res.data.data?.list?.length>0){
          showThreeCubeDetail({
            "id":params.id+ "23",
            "status":params.status,
            "size": {
              x:res.data.data.list[0].boxSize.latLength,
              y:res.data.data.list[0].boxSize.lonLength,
              z:res.data.data.list[0].boxSize.height
            },
            "points":res.data.data.list,
            "depthTest":false
          })
        }
        if(res.data.data?.listInfo?.length>0){
          showThreeCubeDetail({
            "id":params.id+ "24",
            "status":params.status,
            "size": {
              x:res.data.data.listInfo[0].boxSize.latLength,
              y:res.data.data.listInfo[0].boxSize.lonLength,
              z:res.data.data.listInfo[0].boxSize.height
            },
            "points":res.data.data.listInfo,
            "depthTest":false
          })
        }
      }

      function feedbackErrorResult(){
        bus.emit('SendMessage',{
          action:"CubeResult",
          data:{
            "message":{
              "time":new Date().getTime(),
              "data":"error"
            }
          }
        })
      }


      function getBasePrism(params){
        getPrism({
          paths:params.paths,
          radius:params.radius,
          level: params.level
        }).then(res =>{
          let data  = res.data.data;
          let showData = [];

          data.forEach((item)=>{
            let newShape = JSON.parse(item.shape);
            newShape.color = "red"
            showData.push({
              attributes:{
                id:item.id,
                name:item.name,
                height:newShape.height,
              },
              type:item.geoType,
              shape: newShape
            })
          })
          geometryMeshEffect({
            "status": "show",
            "id": "drawOne",
            "data": showData
          })
        })
      }

      function getBasePath(params){
        getPath({
          paths:params.paths,
          radius:params.radius,
          level: params.level
        }).then(res =>{
          let data  = res.data.data;
          let showData = [];

          data.forEach((item)=>{
            let newShape = JSON.parse(item.shape);
            newShape.color = "green"
            showData.push({
              type:"polyline",
              shape: newShape
            })
          })
          geometryMeshEffect({
            "status": "show",
            "id": "drawOne",
            "data": showData
          })
        })
      }

      function getBaseQJC(params){
        getQJC({
          paths:params.paths,
          radius:params.radius,
          level: params.level
        }).then(res =>{
          let data  = res.data.data;
          let showData = [];

          data.forEach((item)=>{
            let newShape = JSON.parse(item.shape);
            newShape.color = "green"
            showData.push({
              type:item.geoType,
              shape: newShape
            })
          })
          geometryMeshEffect({
            "status": "show",
            "id": "drawOne",
            "data": showData
          })
        })
      }

      function radarEffect(params){
        let status = params.status;
        let id = params.id;
        if(radarEffectInstance[id]){
          radarEffectInstance[id].clear();
          radarEffectInstance[id] = null;
        }
        if(status === "hide"){
          return
        }
        let points = params.points;
        let radarEffectInstance = new AddRadarEffectEvent({
          view:m_view,
          points
        })
        radarEffectInstance.start()
        // 保存实例
        lightBallInstance[id] = radarEffectInstance;
      }


    })
  }
}
</script>

<style scoped lang="scss">
#map_jk,#mapDiv,#viewDiv{
  height: 100%;
}
:deep(.esri-view-surface--touch-none::after){
  outline: none !important;
}
</style>