管道基础大数据平台系统开发-【前端】-新系統界面
Surpriseplus
2023-09-05 0d9aae8f90dfc0f0f07a3ac95da0901b2c01ad4f
src/views/Tools/LayerTree.vue
@@ -2,104 +2,141 @@
  <div class="lalala tree-container">
    <el-form ref="form">
      <el-form-item>
        <el-select v-model="$store.state.pigCode"
                   clearable
                   filterable
                   style="width :100%"
                   @change="prjChanged"
                   placeholder="请选择项目">
          <el-option v-for="item in menus"
                     :key="item.code"
                     :label="item.name"
                     :value="item.code">
        <el-select
          v-model="$store.state.pigCode"
          clearable
          filterable
          style="width :100%"
          @change="prjChanged"
          placeholder="请选择项目"
        >
          <el-option
            v-for="item in menus"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="输入关键字进行过滤"
                  v-model="filterText"
                  class="search">
        <el-input
          placeholder="输入关键字进行过滤"
          v-model="filterText"
          class="search"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <el-tree ref="tree"
             :data="treeData"
             node-key="id"
             show-checkbox
             :props="defaultProps"
             @node-click="handleLeftclick"
             @node-contextmenu="rightClick"
             @check="handleCheckChange"
             :default-checked-keys="handleTreeCheck"
             :expand-on-click-node="false"
             :filter-node-method="filterNode"
             draggable>
      <span class="slot-t-node"
            slot-scope="{ node, data }">
    <el-tree
      ref="tree"
      :data="treeData"
      node-key="id"
      show-checkbox
      :props="defaultProps"
      @node-click="handleLeftclick"
      @node-contextmenu="rightClick"
      @check="handleCheckChange"
      :default-checked-keys="handleTreeCheck"
      :expand-on-click-node="false"
      :filter-node-method="filterNode"
      draggable
    >
      <span
        class="slot-t-node"
        slot-scope="{ node, data }"
      >
        <span v-show="!data.isEdit">
          <span :class="[data.id >= 99 ? 'slot-t-node--label' : '']">{{
            node.label
          }}</span>
                              node.label
                            }}</span>
        </span>
        <span v-show="data.isEdit">
          <el-input class="slot-t-input"
                    size="mini"
                    autofocus
                    v-model="data.label"
                    :ref="'slotTreeInput' + data.id"
                    @blur.stop="nodeBlur(node, data)"
                    @keydown.native.enter="nodeBlur(node, data)"></el-input>
          <el-input
            class="slot-t-input"
            size="mini"
            autofocus
            v-model="data.label"
            :ref="'slotTreeInput' + data.id"
            @blur.stop="nodeBlur(node, data)"
            @keydown.native.enter="nodeBlur(node, data)"
          ></el-input>
        </span>
      </span>
    </el-tree>
    <el-card class="box-card"
             ref="card"
             :style="{ ...rightClickMenuStyle }"
             v-show="menuVisible">
      <div class="edit"
           @click="showLayerAttribute()"
           v-if="showProp && !shwoHistogram">
    <el-card
      class="box-card"
      ref="card"
      :style="{ ...rightClickMenuStyle }"
      v-show="menuVisible"
    >
      <div
        class="edit"
        @click="showLayerAttribute()"
        v-if="showProp && !shwoHistogram"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;属性
      </div>
      <div class="edit"
           @click="positioning()"
           v-if="showLocal">
      <div
        class="edit"
        @click="positioning()"
        v-if="showLocal"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;定位
      </div>
      <div class="edit"
           @click="pellucidity()"
           v-if="showOpacity">
      <div
        class="edit"
        @click="pellucidity()"
        v-if="showOpacity"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;透明度
      </div>
      <div class="edit"
           @click="histogram()"
           v-show="shwoHistogram">
      <div
        class="edit"
        @click="histogram()"
        v-show="shwoHistogram"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;钻孔柱状图
      </div>
      <div
        class="edit"
        v-show="shwoTileDown"
        @click="tileDownload()"
      >
        <i class="el-icon-download"></i>&nbsp;&nbsp;瓦片下载
      </div>
      <div
        class="edit"
        v-show="shwoAnnex"
        @click="annexDownload()"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;附件
      </div>
    </el-card>
  </div>
</template>
<script>
import ImageWMS from "ol/source/ImageWMS";
import Image from "ol/layer/Image";
import GeoJSON from "ol/format/GeoJSON.js";
import queryinfo from "./queryinfo.vue";
import { Vector as VectorSource } from "ol/source";
import { Vector as VectorLayer } from "ol/layer";
import { perms_selectLayers, comprehensive_selectPubById, project_selectDirAll, project_selectByDirid, } from "../../api/api.js";
import { perms_selectLayers, comprehensive_selectPubById, project_selectDirAll } from "../../api/api.js";
export default {
  name: "tree",
  components: { queryinfo },
  data () {
  data() {
    return {
      isBusy: false, // 正忙
      lastPrjCode: "", // 最后选择项目编码
      showProp: false, // 属性
      shwoHistogram: false, // 钻孔柱状图
      showLocal: false, // 定位
      showOpacity: false, // 不透明度
      shwoTileDown: false, // 瓦片下载
      menuVisible: false, // 菜单
      shwoAnnex: false,//附件
      levelArray: [ // 高程数组
        0, 40000000, 20000000, 10000000, 5000000, 2000000, 1000000, 500000,
        250000, 200000, 100000, 50000, 17000, 9000, 5000, 2000, 1000, 500, 200,
@@ -117,6 +154,7 @@
        "m_sitepoint",
      ],
      treeData: [], // 树数据
      sourceData: [], // 源数据
      defaultProps: { // 默认属性值
        children: "children",
        label: "cnName",
@@ -126,12 +164,12 @@
    };
  },
  watch: {
    filterText (val) {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  mounted () {
    this.getMenus()
  mounted() {
    this.getMenus();
    this.$bus.$on("treeDataCopy", (res) => {
      this.$store.state.treeData = this.treeData;
      this.$store.state.checkedKeys = this.$refs.tree.getCheckedKeys();
@@ -146,12 +184,12 @@
  },
  methods: {
    // 获取菜单
    async getMenus () {
    async getMenus() {
      let data = await project_selectDirAll();
      if (data && data.code == 200) this.menus = data.result;
    },
    // 初始化图层
    async layersStart () {
    async layersStart() {
      let data = await perms_selectLayers();
      if (data.code != 200) {
        return this.$message.error("图层列表查询失败");
@@ -167,22 +205,53 @@
      });
      // 存储选中图层
      this.treeData = this.setTreeData(layers);
      this.sourceData = JSON.parse(JSON.stringify(this.treeData));
      this.$refs.tree.setCheckedKeys(checkKey);
      sessionStorage.setItem("checkedLayers", JSON.stringify(checkedLayers));
    },
    // 设置树数据
    setTreeData (source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
    setTreeData(source) {
      /*let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
      return cloneData.filter((father) => {
        // 循环所有项
        let branchArr = cloneData.filter((child) => father.id == child.pid); // 对比ID,分别上下级菜单,并返回数据
        branchArr.length > 0 ? (father.children = branchArr) : ""; // 给父级添加一个children属性,并赋值
        // 属于同一对象问题,例如:令 a=b、c=1 ,然后再令 b.c=c ,那么 a.c=b.c=c=1 ;同理,后续令 c.d=2 ,那么 a.c.d 也是=2;
        return father.pid == 0; // 返回一级菜单
      });*/
      let arr = [];
      let data = JSON.parse(JSON.stringify(source));
      this.setTreeChildData(data, arr, 0);
      return arr;
    },
    // 设置树子节点数据
    setTreeChildData(data, arr, pid) {
      let i = 0;
      while (i < data.length) {
        let d = data[i];
        if (d.pid == pid) {
          arr.push(d);
          data.splice(i, 1);
          continue;
        }
        i++;
      }
      arr.sort(function (a, b) {
        return a.orderNum - b.orderNum;
      });
      for (let i in arr) {
        let children = [];
        this.setTreeChildData(data, children, arr[i].id);
        if (children.length) arr[i].children = children;
      }
    },
    // 节点获得焦点事件
    nodeBlur (node, data) {
    nodeBlur(node, data) {
      if (!data.label.length) return this.$message.error("菜单名不可为空!");
      if (data.isEdit) this.$set(data, "isEdit", false);
      this.$nextTick(() => {
@@ -190,22 +259,22 @@
      });
    },
    // 鼠标左击事件
    handleLeftclick (data, node) {
    handleLeftclick(data, node) {
      this.rmListener();
    },
    // 取消鼠标监听事件
    rmListener () {
    rmListener() {
      this.menuVisible = false;
      //  要及时关掉监听,不关掉的是一个坑,不信你试试,虽然前台显示的时候没有啥毛病,加一个alert你就知道了
      document.removeEventListener("click", this.rmListener);
    },
    // 过滤节点
    filterNode (value, data) {
    filterNode(value, data) {
      if (!value) return true;
      return data.cnName.indexOf(value) !== -1;
    },
    // 鼠标右击事件
    rightClick (event, object, node, element) {
    rightClick(event, object, node, element) {
      if (object.type == 1 || node.data.children != null) return;
      this.currentNode = node;
@@ -216,13 +285,14 @@
      this.shwoHistogram = this.showProp && object.enName == "s_explorationpoint"; // 钻孔柱状图
      this.showLocal = ["Tileset", "3DML", "Mpt", "TMS", "DOM", "DEM"].indexOf(object.serveType) > -1; // 定位
      this.showOpacity = ["Tileset", "3DML"].indexOf(object.serveType) > -1; // 不透明度
      this.menuVisible = this.showProp || this.shwoHistogram || this.showLocal || this.showOpacity; // 菜单
      this.shwoTileDown = ["TMS", "DOM"].indexOf(object.serveType) > -1 && object.pubid; // 瓦片下载
      this.menuVisible = this.showProp || this.shwoHistogram || this.showLocal || this.showOpacity || this.shwoTileDown; // 菜单
      this.shwoAnnex = ['DEM', 'TMS'].indexOf(object.serveType) > -1;//附件
      this.$refs.card.$el.style.left = event.pageX + 20 + "px";
      this.$refs.card.$el.style.top = event.pageY + "px";
    },
    // 属性显示
    showLayerAttribute (data) {
    showLayerAttribute(data) {
      this.rmListener();
      this.currentData = data ? data : this.currentData;
      let layer = this.currentData.enName.replaceAll("_", "");
@@ -231,8 +301,9 @@
      this.$store.state.mapPopBoxFlag = "2";
    },
    // 定位
    async positioning () {
    async positioning() {
      this.rmListener();
      if (["Tileset", "3DML"].indexOf(this.currentData.serveType) > -1) {
        for (let i in Viewer.scene.primitives._primitives) {
          if (Viewer.scene.primitives._primitives[i].id == this.currentData.cnName) {
@@ -256,11 +327,22 @@
      }
      if ("Mpt" == this.currentData.serveType) {
        viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(101.8, 37.9, 10000000.0) }); // 中国
        if (this.currentData.json) {
          var json = JSON.parse(this.currentData.json);
          if (json.west) {
            Viewer.camera.flyTo({
              destination: Cesium.Rectangle.fromDegrees(json.west, json.south, json.east, json.north)
            })
          }
        } else {
          Viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(101.8, 37.9, 10000000.0) }); // 中国
        }
      }
    },
    // 钻孔柱状图
    async histogram () {
    async histogram() {
      this.rmListener();
      let layer = this.currentData.enName.replaceAll("_", "");
      this.$store.state.mapSpaceQueryLayer = layer;
@@ -268,7 +350,7 @@
      this.$store.state.showPopBoxFlag = true;
    },
    // 透明度
    pellucidity () {
    pellucidity() {
      this.rmListener();
      for (let j in Viewer.scene.primitives._primitives) {
        if (Viewer.scene.primitives._primitives[j].id == this.currentData.cnName) {
@@ -279,13 +361,45 @@
      }
    },
    // 获取高度
    getHeight (level) {
    getHeight(level) {
      if (level > -1 && level < 23) return this.levelArray[level];
      return this.levelArray[this.levelArray.length - 1];
    },
    //附件下载
    annexDownload() {
      this.$bus.$emit('annexDownload', this.currentData)
    },
    // 瓦片下载
    tileDownload() {
      this.rmListener();
      var that = this;
      sgworld.Creator.createSimpleGraphic(
        "rectangle", {},
        function (entity) {
          that.getTileRectangle(entity);
          sgworld.Creator.SimpleGraphic.clear();
        }
      );
    },
    // 获取瓦片四至范围
    getTileRectangle(res) {
      var value = res.rectangle.coordinates.getValue();
      var val = {
        pubid: this.currentData.pubid,
        pwd: "",
        title: "",
        xmax: Cesium.Math.toDegrees(value.east),
        xmin: Cesium.Math.toDegrees(value.west),
        ymax: Cesium.Math.toDegrees(value.north),
        ymin: Cesium.Math.toDegrees(value.south)
      }
      this.$bus.$emit("titleDown", val);
    },
    // 图层选中事件
    handleCheckChange (data, checked) {
    handleCheckChange(data, checked) {
      if (this.isBusy) return;
      let nodes = [];
@@ -314,14 +428,14 @@
        }
      }
      if (obj.WMS.length) this.setChangeWMS(obj.WMS, checked);
      if (obj.Tileset.length) this.setChangeTileset(obj.Tileset, checked);
      if (obj.DEM.length) this.setChangeDEM(obj.DEM, checked);
      if (obj.TMS.length) this.setChangeTMS(obj.TMS, checked);
      if (obj.Mpt.length) this.setChangeMpt(obj.Mpt, checked);
      if (obj.DEM.length) this.setChangeDEM(obj.DEM, checked);
      if (obj.Tileset.length) this.setChangeTileset(obj.Tileset, checked);
      if (obj.WMS.length) this.setChangeWMS(obj.WMS, checked);
    },
    // 获取子节点
    getNodes (data, arr) {
    getNodes(data, arr) {
      if (data.children) {
        for (let i = 0, c = data.children.length; i < c; i++) {
          let node = data.children[i];
@@ -336,7 +450,7 @@
      }
    },
    // 获取节点ID
    getCheckNodesIds () {
    getCheckNodesIds() {
      let nodes = this.$refs.tree.getCheckedNodes();
      let ids = [];
      for (let i in nodes) {
@@ -346,12 +460,12 @@
      return ids;
    },
    // 切换WMS服务
    setChangeWMS (layers, checked) {
    setChangeWMS(layers, checked) {
      let value = this.$refs.tree.getCheckedNodes();
      this.$bus.$emit("showMenuLayer", value);
    },
    // 切换Tileset
    setChangeTileset (layers, checked) {
    setChangeTileset(layers, checked) {
      let ids = this.getCheckNodesIds(), arr = [];
      for (let k in layers) {
        let layer = layers[k];
@@ -378,7 +492,7 @@
      if (arr.length) this.addTilesetLayers(arr);
    },
    // 添加Tileset图层
    addTilesetLayers (layers) {
    addTilesetLayers(layers) {
      for (let i in layers) {
        let res = layers[i];
        let url = res.url.indexOf("{host}") > -1 ? res.url.replace("{host}", iisHost) : modelUrl + "/" + res.url;
@@ -389,7 +503,7 @@
            url: url,
            skipLevelOfDetail: true, // 在遍历时候跳过详情:false
            baseScreenSpaceError: 1024,
            maximumScreenSpaceError: 64, // 最大屏幕空间错误:16,数值加大能让最终成像变模糊
            maximumScreenSpaceError: url.indexOf("/pnts/") > -1 ? 16 : 64, // 最大屏幕空间错误:16,数值加大能让最终成像变模糊
            skipScreenSpaceErrorFactor: 16,
            skipLevels: 1,
            immediatelyLoadDesiredLevelOfDetail: false,
@@ -432,7 +546,7 @@
      }
    },
    // 切换TMS
    setChangeTMS (layers, checked) {
    setChangeTMS(layers, checked) {
      let ids = this.getCheckNodesIds(), arr = [];
      for (let j in layers) {
        let layer = layers[j];
@@ -452,26 +566,34 @@
      if (arr.length) this.addTMSLayers(arr);
    },
    // 添加TMS图层
    addTMSLayers (layers) {
    addTMSLayers(layers) {
      debugger
      for (let i in layers) {
        let res = layers[i];
        let url = res.url.indexOf("{host}") > -1 ? res.url.replace("{host}", iisHost) : res.url;
        res.url = res.url.indexOf("{host}") > -1 ? res.url.replace("{host}", iisHost) : res.url;
        if (res.pubid) {
          this.setQueryPubid(res);
          this.setTMSLayerByPubid(res);
          continue;
        }
        let layer = Viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
          url: url,
          url: res.url,
          maximumLevel: 22,
        }));
          enablePickFeatures: false
        }), 1);
        layer.id = res.id;
        layer.name = res.cnName;
        if (is_production) {
          Viewer.imageryLayers.raiseToTop(layer);//将图层上移一层
          Viewer.imageryLayers.lower(layer);//将图层上移一层
        }
      }
    },
    // 切换Mpt
    setChangeMpt (layers, checked) {
    setChangeMpt(layers, checked) {
      let ids = this.getCheckNodesIds(), arr = [];
      for (let j in layers) {
        let layer = layers[j];
@@ -491,64 +613,71 @@
      if (arr.length) this.addMptLayers(arr);
    },
    // 添加Mpt图层
    addMptLayers (layers) {
    addMptLayers(layers) {
      for (let i in layers) {
        let res = layers[i];
        if (res.url.indexOf("{host}") > -1) res.url = res.url.replace("{host}", iisHost);
        let urls = res.url.split(';')
        let layer = sgworld.Creator.createImageryProvider(res.cnName, "wms", {
        let urls = res.url.split(';');
        var ops = {
          url: urls[0],
          layers: urls[1]
        }, "0", undefined, true, "");
        };
        if (res && res.json) {
          var rs = JSON.parse(res.json);
          ops.rectangle = Cesium.Rectangle.fromDegrees(rs.west, rs.south, rs.east, rs.north);
        }
        let layer = sgworld.Creator.createImageryProvider(res.cnName, "wms", ops, "0", undefined, true, "");
        this.mptLayer.push(layer);
      }
    },
    // 切换DEM
    setChangeDEM (layers, checked) {
      let ids = this.getCheckNodesIds(), arr = [], isDel = false, useSG = false;
    setChangeDEM(layers, checked) {
      let ids = this.getCheckNodesIds(), arr = [];
      for (let i in layers) {
        let layer = layers[i];
        if (ids.indexOf(layer.id) != -1) {
          arr.push(layer.url);
          continue;
        }
        if (window.Viewer.terrainProvider._layers[0].resource._url == layer.url) isDel = true; // 删除DEM
      }
      if (!arr.length && isDel) useSG = true; // demLayer
      if (arr.length) this.addDEMLayers(arr[0], useSG);
      let url = arr.length ? arr[arr.length - 1] : null;
      this.addDEMLayers(url, null == url);
    },
    // 添加DEM图层
    addDEMLayer (url, useSG) {
    addDEMLayers(url, useSG) {
      if (useSG) {
        if (Viewer.terrainProvider._isMPT) return;
        let option = {
          url: window.sceneConfig.SGUrl,
          layerName: window.sceneConfig.mptName,
          requestVertexNormals: true
        };
        window.terrainLayer = sgworld.Creator.sfsterrainprovider("", option, "", true, "");
      } else {
        window.terrainLayer = new Cesium.CesiumTerrainProvider({
          url: url,
          requestVertexNormals: true
        });
        sgworld.Creator.sfsterrainprovider("", option, "", true, "");
        return;
      }
      Viewer.terrainProvider = terrainLayer;
      if (url.indexOf("{host}") > -1) url = url.replace("{host}", iisHost);
      Viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
        url: url,
        requestVertexNormals: true
      });
    },
    // 设置Tileset参数
    async setTilesetArgs (tileset, res) {
    async setTilesetArgs(tileset, res) {
      if (res.serveType == '3DML' || !res.pubid) {
        this.setTilesetHeigth(tileset, parseFloat(res.elev));
        return;
      }
      const data = await comprehensive_selectPubById({ id: res.pubid })
      if (data.code == 200) this.setTilesetCoord(tileset, data.result.json);
      if (data.code == 200 && data.result.json) this.setTilesetCoord(tileset, data.result.json);
    },
    // 设置Tileset高度
    setTilesetHeigth (tileset, height) {
    setTilesetHeigth(tileset, height) {
      //3dtile模型的边界球体
      let boundingSphere = tileset.boundingSphere;
      //迪卡尔空间直角坐标=>地理坐标(弧度制)
@@ -563,7 +692,7 @@
      // Viewer.flyTo(tileset);
    },
    // 设置Tileset坐标
    setTilesetCoord (tileset, json) {
    setTilesetCoord(tileset, json) {
      let vm = JSON.parse(json);
      let pos = Cesium.Cartesian3.fromDegrees(vm.lon, vm.lat, vm.height);
      let converter = Cesium.Transforms.eastNorthUpToFixedFrame;
@@ -572,212 +701,183 @@
      tileset._root.transform = matrix;
      // Viewer.flyTo(tileset);
    },
    async setQueryPubid (res) {
      const data = await comprehensive_selectPubById({ id: res.pubid })
      if (data.code != 200) {
        //
      } else {
        let url = data.result.url;
        if (res.url.indexOf("{host}") != -1) {
          url = res.url.replace("{host}", iisHost);
        }
        let min = data.result.min;
        let max = data.result.max;
        let layer;
        if (max > 0) {
          layer = Viewer.imageryLayers.addImageryProvider(
            new Cesium.UrlTemplateImageryProvider({
              url: url,
              minimumLevel: min,
              maximumLevel: max,
            })
          );
        } else {
          layer = Viewer.imageryLayers.addImageryProvider(
            new Cesium.UrlTemplateImageryProvider({
              url: url,
              minimumLevel: min,
            })
          );
        }
    // 根据Pubid设置TMS图层
    async setTMSLayerByPubid(res) {
      const data = await comprehensive_selectPubById({ id: res.pubid });
      if (!data || data.code != 200) return;
        layer.name = res.cnName;
        if (data.result.geom) {
          // let wkt = this.$wkt.parse(data.result.geom);
          // Viewer.camera.flyTo({
          //   destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000),
          // });
        }
        this.setChangeWMS();
      let provider = data.result.max > 0 ?
        new Cesium.UrlTemplateImageryProvider({
          url: res.url,
          minimumLevel: data.result.min,
          maximumLevel: data.result.max,
          enablePickFeatures: false
        }) :
        new Cesium.UrlTemplateImageryProvider({
          url: res.url,
          minimumLevel: data.result.min,
          enablePickFeatures: false
        });
      let layer = Viewer.imageryLayers.addImageryProvider(provider, 1);
      layer.name = res.cnName;
      if (is_production) {
        Viewer.imageryLayers.raiseToTop(layer);//将图层上移一层
        Viewer.imageryLayers.lower(layer);//将图层上移一层
      }
      // if (data.result.geom) {
      //   let wkt = this.$wkt.parse(data.result.geom);
      //   Viewer.camera.flyTo({
      //     destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000)
      //   });
      // }
    },
    // 切换项目
    async prjChanged (res) {
    prjChanged(code) {
      this.$store.state.pigCode = code;
      //if (code) {
      this.isBusy = true;
      let checkedLayers = this.getCheckedLayersByCode(code);
      let checkedKeys = [];
      for (let i in checkedLayers) {
        checkedKeys.push(checkedLayers[i].id);
      }
      this.treeData = this.getNewTreeData(code);
      this.$store.state.treeData = this.treeData;
      this.$refs.tree.setCheckedKeys(checkedKeys);
      sessionStorage.setItem("checkedLayers", JSON.stringify(checkedLayers));
      this.isBusy = false;
      //}
      for (let i = 0, c = this.treeData.length; i < c; i++) {
        this.handleCheckChange(this.treeData[i], true);
      }
    },
    // 根据项目编码获取选中图层
    getCheckedLayersByCode(code) {
      let layers = [];
      for (let i = 0, c = this.treeData.length; i < c; i++) {
        this.getCheckedChildLayersByCode(this.treeData[i], code, layers, false);
      }
    async setproChange (res) {
      if (res) {
        this.setCheeckedLayer = this.$refs.tree.getCheckedKeys();
        this.$store.state.pigCode = res;
        let st_code = this.menus.filter(rs => {
          if (rs.code == res) {
            return rs
      return layers;
    },
    // 根据项目编码获取选中子图层
    getCheckedChildLayersByCode(data, code, layers, isPrj) {
      if (data.children && data.children.length) {
        for (let i = 0, c = data.children.length; i < c; i++) {
          let layer = data.children[i];
          if (layer.children && layer.children.length) {
            let flag = layer.type == 1 && layer.isProject && layer.enName == code;
            this.getCheckedChildLayersByCode(layer, code, layers, flag);
            continue;
          }
        })
        let val = this.$store.state.oldTree.filter(rs => {
          if (rs.enName == st_code[0].code) {
            return rs
          }
        })
        this.removeAllLayer();
        let obj = {
          dirid: res,
          pageIndex: 1,
          pageSize: 10,
        }
        const data = await project_selectByDirid(obj);
        if (data.code != 200) {
          this.$message.error("列表获取失败");
          return;
        }
        if (data.result[0]) {
          let geom = data.result[0].geom
          if (geom) {
            let wkt = this.$wkt.parse(geom)
            Viewer.camera.flyTo({
              destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[0].toFixed(6), wkt.coordinates[1].toFixed(6), 5000),
            });
          }
        }
        //this.cannelTerrainLayer();
        //this.setTerrainMptLayer();
        //清空图层树选中状态
        this.$refs.tree.setCheckedKeys([]);
        if (val.length > 0) {
          if (val[0].type == 1 && val[0].isProject == 1) {//项目分类
            let std_check = [];
            for (let i in val) {
              let std_val = this.getNewTree([this.$refs.tree.getNode(val[i].id).data], [])
              for (let j in std_val) {
                std_check.push(std_val[j])
              }
            }
            let value = this.$store.state.isProjectLayer;
            for (let i in value) {
              std_check.push(value[i])
            }
            this.setProjectLayer(std_check);
          //if (layer.type == 2 && (layer.isProject || isPrj)) {
          //  layers.push(layer);
          //}
          if (code) {
            if (layer.type == 2 && (layer.isProject || isPrj)) layers.push(layer);
          } else {
            this.setChangeProLayer();
          }
        } else {
          this.setChangeProLayer();
        }
      } else {
        this.removeAllLayer();
        this.$store.state.pigCode = null;
        this.$refs.tree.setCheckedKeys(this.setCheeckedLayer);
        let std = [];
        for (let i in this.setCheeckedLayer) {
          std.push(this.$refs.tree.getNode(this.setCheeckedLayer[i]).data)
        }
        this.setProjectLayer(std);
      }
    },
    removeAllLayer () {
      for (let j in Viewer.scene.primitives._primitives) {
        Viewer.scene.primitives.remove(Viewer.scene.primitives._primitives[j])
      }
      for (let i in window.Viewer.dataSources._dataSources) {
        window.Viewer.dataSources.remove(
          window.Viewer.dataSources._dataSources[i]
        );
      }
      for (let i = 0; i < window.Viewer.imageryLayers._layers.length; i++) {
        let val_id = window.Viewer.imageryLayers._layers[i].id;
        if (val_id == 'TMS') {
          window.Viewer.imageryLayers.remove(
            window.Viewer.imageryLayers._layers[i]
          );
        }
      }
      for (let i in this.mptLayer) {
        this.mptLayer[i].deleteObject();
        this.mptLayer.splice(i, 1)
      }
      this.mptLayer = [];
    },
    setProjectLayer (res) {
      let layerid = [];
      for (let j in res) {
        layerid.push(res[j].id)
      }
      this.$refs.tree.setCheckedKeys(layerid);
      // let value = this.$refs.tree.getCheckedNodes();
      // this.$bus.$emit("showMenuLayer", value);
      let listWMS = [];
      let listWFS = [];
      let listTileset = [];
      let listTMS = [];
      let listMpt = [];
      for (let i in res) {
        if (res[i].type == 2) {
          switch (res[i].serveType) {
            case 'WMS':
              listWMS.push(res[i])
              break;
            case 'WFS':
              listWFS.push(res[i])
              break;
            case '3DML':
            case 'Tileset':
              listTileset.push(res[i])
              break;
            case 'Mpt':
              listMpt.push(res[i])
              break;
            case 'TMS':
              listTMS.push(res[i])
              break;
            if (layer.isShow) layers.push(layer);
          }
        }
        return;
      }
      // this.setChangeProLayer();
      this.setChangeWMS(listWMS, true);
      this.setChangeWFS(listWFS, true);
      this.setChangeTileset(listTileset, true);
      this.setChangeTMS(listTMS, true);
      this.setChangeMpt(listMpt, true);
    },
    getNewTree (obj, result) {
      for (const i in obj) {
        console.log(obj[i].cnName)
        result.push(obj[i])
        if (obj[i].children && obj[i].children.length > 0) {
          this.getNewTree(obj[i].children, result)
        }
      }
      return result
    },
    setChangeProLayer () {
      let value = this.$store.state.isProjectLayer;
      if (value.length != 0) {
        let std = [];
        for (let i in value) {
          std.push(value[i].id)
      if (data.type == 2 && (data.isProject || isPrj)) {
        layers.push(data);
      }
    },
    // 获取新树数据
    getNewTreeData(code) {
      let data = JSON.parse(JSON.stringify(this.sourceData));
      if (!code) return data;
      this.setSubTreeData(data, code);
      this.rmPrjTreeData(data, code);
      return data;
    },
    // 设置树数据子节点
    setSubTreeData(data, code) {
      let j = 0;
      while (j < data.length) {
        let d = data[j];
        if (d.type == 1 && d.isProject && d.enName != code) {
          data.splice(j, 1);
          continue;
        }
        this.$refs.tree.setCheckedKeys(std);
        this.$bus.$emit("showMenuLayer", value);
        j++;
      }
      for (let i = 0, c = data.length; i < c; i++) {
        if (data[i].children && data[i].children.length) {
          this.setSubTreeData(data[i].children, code);
        }
      }
    },
    // 移除项目树数据
    rmPrjTreeData(data, code) {
      /*let j = 0;
      while (j < data.length) {
        let d = data[j];
        if (d.type == 1 && d.isProject && d.enName == code) {
          data.splice(j, 1);
          data.concat(d.children);
          continue;
        }
        j++;
      }
      for (let i = 0, c = data.length; i < c; i++) {
        if (data[i].children && data[i].children.length) {
          this.rmPrjTreeData(data[i].children, code);
        }
      }*/
      let i = 0;
      while (i < data.length) {
        let d = data[i];
        if (!d.children) {
          i++;
          continue;
        }
        if (!d.children.length) {
          data.splice(i, 1);
          continue;
        }
        let j = 0;
        while (j < d.children.length) {
          let e = d.children[j];
          if (e.type == 1 && e.isProject && e.enName == code) {
            d.children.splice(j, 1);
            if (e.children && e.children.length) d.children = d.children.concat(e.children);
            continue;
          }
          j++;
        }
        i++;
      }
      for (let i = 0, c = data.length; i < c; i++) {
        if (data[i].children && data[i].children.length) {
          this.rmPrjTreeData(data[i].children, code);
        }
      }
    },
    // 添加WFS图层 *
    addWFSLayers (res) {
    addWFSLayers(res) {
      let url =
        res.resource +
        "?service=WFS&version=1.0.0&request=GetFeature&typeName=" +
@@ -857,6 +957,7 @@
.tree-container /deep/ .el-tree > .el-tree-node:after {
  border-top: none;
}
.tree-container /deep/ .el-tree > .el-tree-node:before {
  border-left: none;
}
@@ -903,14 +1004,17 @@
.tree-container {
  margin: 10px;
}
.tree-container /deep/ .el-tree .el-tree-node {
  position: relative;
}
.tree-container /deep/ .el-tree-node .el-tree-node__content {
  height: 34px;
  padding-left: 0px !important;
  border: none;
}
.tree-container /deep/ .el-tree-node .el-tree-node__content::before {
  border-left: 1px dashed #ccc;
  height: 100%;
@@ -920,6 +1024,7 @@
  margin-top: 0px;
  z-index: 8;
}
.tree-container
  /deep/
  .el-tree-node
@@ -974,9 +1079,11 @@
/deep/.el-card__body {
  padding: 10px !important;
  > div {
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
    &:hover {
      color: #409eff;
    }
@@ -994,10 +1101,12 @@
.text {
  font-size: 14px;
}
.el-tree {
  width: 100%;
  margin-top: 10px;
}
.search {
  width: 100%;
}