管道基础大数据平台系统开发-【前端】-新系統界面
Surpriseplus
2023-05-11 63be6c3a6e0308812cb9f0ab26a15aff293200a0
src/views/Tools/LayerTree.vue
@@ -73,30 +73,30 @@
      :style="{ ...rightClickMenuStyle }"
      v-show="menuVisible"
    >
      <div
      <!-- <div
        @click="addSameLevelNode()"
        v-show="firstLevel"
      >
        <i class="el-icon-plus"></i>&nbsp;&nbsp;添加图层组
      </div>
      <div
      </div> -->
      <!-- <div
        class="add"
        @click="addChildNode()"
      >
        <i class="el-icon-plus"></i>&nbsp;&nbsp;添加图层
      </div>
      <div
      </div> -->
      <!-- <div
        class="delete"
        @click="deleteNode()"
      >
        <i class="el-icon-delete"></i>&nbsp;&nbsp;删除
      </div>
      <div
      </div> -->
      <!-- <div
        class="edit"
        @click="editNode()"
      >
        <i class="el-icon-edit"></i>&nbsp;&nbsp;重命名
      </div>
      </div> -->
      <div
        class="edit"
        @click="showLayerAttribute()"
@@ -115,7 +115,7 @@
      <div
        class="edit"
        @click="pellucidity()"
        v-if="showlocal"
        v-if="showopaque"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;透明度
      </div>
@@ -125,6 +125,14 @@
        v-show="shwoHistogram"
      >
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;钻孔柱状图
      </div>
      <div
        class="edit"
        v-show="shwoTitle"
        @click="tileDownload()"
      >
        <i class="el-icon-download"></i>&nbsp;&nbsp;瓦片下载
      </div>
      <!-- <div
        class="edit"
@@ -218,8 +226,9 @@
import { Fill, Stroke, Style } from "ol/style.js";
import {
  perms_selectLayers, inquiry_selectDomains, comprehensive_selectPubById,
  project_selectDirAll, project_selectByDirid
  project_selectDirAll, project_selectByDirid, dataQuerySelectWktById
} from "../../api/api.js";
import { conditions } from '../Archive/Archive.js';
export default {
  name: "tree",
  components: { queryinfo },
@@ -227,6 +236,7 @@
    return {
      shwoHistogram: false,
      showlocal: false,
      showopaque: false,
      eleId: "",
      isShow: false,
      currentData: "",
@@ -270,10 +280,47 @@
      mptLayer: [],
      optionts: [],
      proValue: null,
      setCheeckedLayer: [],
      shwoTitle: false,
    };
  },
  methods: {
    //瓦片下载
    tileDownload() {
      var that = this;
      this.menuVisible = false
      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)
    },
    //转孔柱状图
    async histogram() {
      this.menuVisible = false
@@ -316,29 +363,42 @@
    },
    // 鼠标右击事件
    rightClick(event, object, Node, element) {
      if (object.type == 1) {
        return
      }
      this.currentData = object;
      this.currentNode = Node;
      this.$store.state.propertiesName = this.currentData;
      if (this.currentData.serveType == "Tileset") {
      this.showModelAttach = false;
      this.shwoTitle = false;
      if (this.currentData.serveType == 'TMS') {
        this.shwoTitle = true
      } else if (this.currentData.serveType == "Tileset") {
        this.showModelAttach = true;
      } else {
        this.showModelAttach = false;
      }
      if (this.currentData.enName == "s_explorationpoint") {
        this.shwoHistogram = true;
      } else {
        this.shwoHistogram = false;
      }
      if (Node.level === 3) {
      if (Node.data.children == null) {
        this.firstLevel = false;
      } else {
        this.firstLevel = true;
      }
      if (Node.level === 3 && Node.data.serveType == "Tileset") {
      if (Node.data.children == null && Node.data.serveType == "Tileset") {
        this.showlocal = true;
      } else if (Node.level === 3 && Node.data.serveType != "Tileset") {
        this.showopaque = true;
      } else if (Node.data.children == null && Node.data.serveType == "TMS") {
        this.showlocal = true;
        this.showopaque = false;
      } else if (Node.data.children == null && Node.data.serveType != "Tileset") {
        this.showlocal = false;
        this.showopaque = false;
      }
      this.menuVisible = true;
@@ -480,15 +540,27 @@
    //模型定位
    positioning() {
    async positioning() {
      this.menuVisible = false
      for (var i in Viewer.scene.primitives._primitives) {
        if (
          Viewer.scene.primitives._primitives[i].id == this.currentData.cnName
        ) {
          Viewer.flyTo(Viewer.scene.primitives._primitives[i]);
      if (this.currentData.serveType == 'Tileset') {
        for (var i in Viewer.scene.primitives._primitives) {
          if (
            Viewer.scene.primitives._primitives[i].id == this.currentData.cnName
          ) {
            Viewer.flyTo(Viewer.scene.primitives._primitives[i]);
          }
        }
      } else if (this.currentData.serveType == 'TMS' && this.currentData.pubid) {
        const data = await comprehensive_selectPubById({ id: this.currentData.pubid })
        if (data.result.geom) {
          var wkt = this.$wkt.parse(data.result.geom);
          Viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000),
          });
        }
      }
    },
    // 编辑节点
    editNode(data) {
@@ -562,6 +634,7 @@
      console.log("tree drop: ", dropNode.label, dropType);
    },
    handleCheckChange(data, checked, indeterminate) {
      if (data.type == 1) {
        this.childOption = [];
        this.getchilds(data);
@@ -570,6 +643,7 @@
        var listTileset = [];
        var listTMS = [];
        var listMpt = [];
        var listDem = [];
        for (var i in this.childOption) {
          switch (this.childOption[i].serveType) {
            case 'WMS':
@@ -587,7 +661,9 @@
            case 'TMS':
              listTMS.push(this.childOption[i])
              break;
            case 'DEM':
              listDem.push(this.childOption[i])
              break;
          }
        }
        this.setChangeWMS(listWMS, checked);
@@ -595,6 +671,7 @@
        this.setChangeTileset(listTileset, checked);
        this.setChangeTMS(listTMS, checked);
        this.setChangeMpt(listMpt, checked);
        this.setChangeDem(listDem, checked);
      } else if (data.type == 2) {
        if (data.serveType == "WMS") {
          this.setChangeWMS([data], checked);
@@ -604,75 +681,46 @@
          this.setChangeTMS([data], checked);
        } else if (data.serveType == "Mpt") {
          this.setChangeMpt([data], checked);
        } else if (data.serveType == "DEM") {
          this.setChangeDem([data], checked);
        }
      }
      // if (data.type != 2) return;
      // if (data.serveType == "WFS") {
      //   if (window.Viewer.dataSources._dataSources.length == 0) {
      //     this.setAddLayers(data);
      //   } else {
      //   }
      // } else if (data.serveType == "Tileset") {
      //   if (Viewer.scene.primitives._primitives.length == 0) {
      //     this.setAddLayers(data);
      //   } else {
      //     var std = [];
      //     for (var i in Viewer.scene.primitives._primitives) {
      //       Viewer.scene.primitives._primitives[i].show = checked;
      //       if (Viewer.scene.primitives._primitives[i].id == data.cnName) {
      //         std.push(data.id);
      //         Viewer.flyTo(Viewer.scene.primitives._primitives[i]);
      //       }
      //     }
      //   }
      //   if (std.length == 0 && checked == true) {
      //     this.setAddLayers(data);
      //   } else {
      //     window.map.getLayers().getArray().forEach(item => {
      //       if (item.get("name") == data.cnName) {
      //         item.setVisible(checked);
      //       }
      //     });
      //   }
      // } else if (data.serveType == "TMS") {
      //   if (data.pubid) {
      //   } else {
      //     var res;
      //     if (data.url.indexOf("{host}") != -1) {
      //       res = data.url.replace("{host}", iisHost);
      //     } else {
      //       res = data.url
      //     }
      //     var url = res.split(';')
      //     window.sgworld.Creator.createImageryProvider('mpt影像', "wms", {
      //       url: url[0],
      //       layers: url[1]
      //     }, "0", undefined, true, "");
      //   }
      // }
      // var layers_ol = window.map.getAllLayers();
      // for (var i in layers_ol) {
      //   var layerOl = layers_ol[i];
      //   if (layerOl.values_.name == data.label) {
      //     layerOl.setVisible(checked); //显示图层
      //   }
      // }
    },
    setChangeDem(data, checked) {
      this.cannelTerrainLayer();
      var val = this.$refs.tree.getCheckedKeys();
      var std = [];
      for (var i = 0; i < val.length; i++) {
        var res = this.$refs.tree.getNode(val[i]).data;
        if (res.serveType && res.serveType != 'DEM') {
          std.push(val[i])
        }
      }
      var result = data[0]
      if (this.$refs.tree.getNode(result.id).checked) {
        std.push(result.id);
        var base_ulr = result.url;
        if (base_ulr.indexOf('{host}') > -1) {
          base_ulr = base_ulr.replace("{host}", iisHost)
        }
        this.setTerrainDemLayer(base_ulr);
      } else {
        this.setTerrainMptLayer();
      }
      this.$refs.tree.setCheckedKeys(std)
      //
      // this.$nextTick(() => {
      //
      // });
      // setTimeout(() => {
      //
      // }, 500);
    },
    setChangeWMS(result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      this.$bus.$emit("showMenuLayer", value);
@@ -728,20 +776,6 @@
          }
        }
      }
      // if (checked.checkedKeys) {
      //   for (var i in result) {
      //
      //   }
      // } else {
      //   for (var j in result) {
      //     console.log(result[j])
      //     //
      //   }
      // }
    },
    setChangeMpt(result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
@@ -802,7 +836,7 @@
      }
    },
    setAddLayers(res) {
    async setAddLayers(res) {
      if (res.serveType == "WMS") {
        var resource = geoServerURl;
@@ -942,13 +976,15 @@
        if (res.pubid) {
          this.setQueryPubid(res);
        } else {
          var layer = Viewer.imageryLayers.addImageryProvider(
            new Cesium.UrlTemplateImageryProvider({
              url: url,
              maximumLevel: 18,
              maximumLevel: 22,
            })
          );
          layer.name = res.cnName;
          layer.id = "TMS"
          this.setChangeWMS();
        }
@@ -993,23 +1029,39 @@
      } else {
        var url = data.result.url;
        if (res.url.indexOf("{host}") != -1) {
          url = res.url.replace("{host}", iisHost);
        }
        var layer = Viewer.imageryLayers.addImageryProvider(
          new Cesium.UrlTemplateImageryProvider({
            url: url,
            maximumLevel: 18,
          })
        );
        var min = data.result.min;
        var max = data.result.max;
        var 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,
            })
          );
        }
        layer.name = res.cnName;
        if (data.result.geom) {
          var wkt = this.$wkt.parse(data.result.geom);
          Viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000),
          });
        }
        // if (data.result.geom) {
        //   var wkt = this.$wkt.parse(data.result.geom);
        //   Viewer.camera.flyTo({
        //     destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000),
        //   });
        // }
        this.setChangeWMS();
      }
    },
@@ -1020,7 +1072,7 @@
      var hpr = new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(vm.yaw), 0, 0);
      var matrix = Cesium.Transforms.headingPitchRollToFixedFrame(pos, hpr, Cesium.Ellipsoid.WGS84, converter);
      tileset._root.transform = matrix;
      Viewer.flyTo(tileset);
      // Viewer.flyTo(tileset);
    },
    tileSet(tileset, height) {
      //3dtile模型的边界球体
@@ -1034,13 +1086,21 @@
      var translation = Cesium.Cartesian3.subtract(Cartesian3_offset, Cartesian3_original, new Cesium.Cartesian3());
      //修改模型矩阵
      tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
      Viewer.flyTo(tileset);
      // Viewer.flyTo(tileset);
    },
    setTreeData(source) {
      let cloneData = JSON.parse(JSON.stringify(source)); // 对源数据深度克隆
      return cloneData.filter((father) => {
        // 循环所有项
        let branchArr = cloneData.filter((child) => father.id == child.pid); // 对比ID,分别上下级菜单,并返回数据
        let branchArr = cloneData.filter((child) => father.id == child.pid);
        if (branchArr.length > 0) {
          branchArr.sort(function (a, b) {
            return a.orderNum - b.orderNum
          })
        }
        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;
        // 由此循环多次后,就能形成相应的树形数据结构
@@ -1145,17 +1205,42 @@
      }
      this.$refs.tree.setCheckedKeys(std);
    },
    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
    },
    // 查询
    filterNode(value, data) {
      if (!value) return true;
      return data.cnName.indexOf(value) !== -1;
    },
    async setproChange(res) {
      this.$store.state.pigCode = res;
      if (res) {
        this.setCheeckedLayer = this.$refs.tree.getCheckedKeys();
        this.$store.state.pigCode = res;
        var st_code = this.optionts.filter(rs => {
          if (rs.code == res) {
            return rs
          }
        })
        var val = this.$store.state.oldTree.filter(rs => {
          if (rs.enName == st_code[0].code) {
            return rs
          }
        })
        this.removeAllLayer();
        var obj = {
          dirid: res,
          pageIndex: 1,
@@ -1167,23 +1252,162 @@
          this.$message.error("列表获取失败");
          return;
        }
        if (data.result[0]) {
          var geom = data.result[0].geom
          var wkt = this.$wkt.parse(geom)
          Viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[0].toFixed(6), wkt.coordinates[1].toFixed(6), 5000),
          });
          if (geom) {
            var wkt = this.$wkt.parse(geom)
            Viewer.camera.flyTo({
              destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[0].toFixed(6), wkt.coordinates[1].toFixed(6), 5000),
            });
          }
        }
        this.setChangeProLayer();
      } else {
        this.cannelTerrainLayer();
        this.setTerrainMptLayer();
        //清空图层树选中状态
        this.$refs.tree.setCheckedKeys([]);
        if (val.length > 0) {
        this.$store.state.pigCode = null
        this.setChangeWMS();
          if (val[0].type == 1 && val[0].isProject == 1) {//项目分类
            var std_check = [];
            for (var i in val) {
              var std_val = this.getNewTree([this.$refs.tree.getNode(val[i].id).data], [])
              for (var j in std_val) {
                std_check.push(std_val[j])
              }
            }
            var value = this.$store.state.isProjectLayer;
            for (var i in value) {
              std_check.push(value[i])
            }
            this.setProjectLayer(std_check);
          } else {
            this.setChangeProLayer();
          }
        } else {
          this.setChangeProLayer();
        }
      } else {
        this.removeAllLayer();
        this.$store.state.pigCode = null;
        this.$refs.tree.setCheckedKeys(this.setCheeckedLayer);
        var std = [];
        for (var i in this.setCheeckedLayer) {
          std.push(this.$refs.tree.getNode(this.setCheeckedLayer[i]).data)
        }
        this.setProjectLayer(std);
      }
    },
    cannelTerrainLayer() {
      //清空地形
      if (window.terrainMptLayer) {
        window.terrainMptLayer.deleteObject();
        window.terrainMptLayer = null;
      }
      if (window.terrainDemLayer) {
        Viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
        window.terrainDemLayer = null;
      }
    },
    setTerrainMptLayer() {
      //默认地形MPT
      var option = {
        url: window.sceneConfig.SGUrl,
        layerName: window.sceneConfig.mptName,
        requestVertexNormals: true,
      };
      window.terrainMptLayer = sgworld.Creator.sfsterrainprovider("", option, "", true, "");
    },
    setTerrainDemLayer(res) {
      window.terrainDemLayer = new Cesium.CesiumTerrainProvider({
        url: res
      });
      Viewer.terrainProvider = window.terrainDemLayer
    },
    setProjectLayer(res) {
      var layerid = [];
      for (var i in res) {
        layerid.push(res[i].id)
      }
      this.$refs.tree.setCheckedKeys(layerid);
      // var value = this.$refs.tree.getCheckedNodes();
      // this.$bus.$emit("showMenuLayer", value);
      var listWMS = [];
      var listWFS = [];
      var listTileset = [];
      var listTMS = [];
      var listMpt = [];
      var listDem = [];
      for (var 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 'Tileset':
              listTileset.push(res[i])
              break;
            case 'Mpt':
              listMpt.push(res[i])
              break;
            case 'TMS':
              listTMS.push(res[i])
              break;
            case 'DEM':
              listDem.push(this.childOption[i])
              break;
          }
        }
      }
      this.setChangeDem(listDem, true);
      this.setChangeWMS(listWMS, true);
      this.setChangeWFS(listWFS, true);
      this.setChangeTileset(listTileset, true);
      this.setChangeTMS(listTMS, true);
      this.setChangeMpt(listMpt, true);
    },
    removeAllLayer() {
      for (var j in Viewer.scene.primitives._primitives) {
        Viewer.scene.primitives.remove(Viewer.scene.primitives._primitives[j])
      }
      for (var i in window.Viewer.dataSources._dataSources) {
        window.Viewer.dataSources.remove(
          window.Viewer.dataSources._dataSources[i]
        );
      }
      for (var i = 0; i < window.Viewer.imageryLayers._layers.length; i++) {
        var val_id = window.Viewer.imageryLayers._layers[i].id;
        if (val_id == 'TMS') {
          window.Viewer.imageryLayers.remove(
            window.Viewer.imageryLayers._layers[i]
          );
        }
      }
      for (var i in this.mptLayer) {
        this.mptLayer[i].deleteObject();
        this.mptLayer.splice(i, 1)
      }
      this.mptLayer = [];
    },
    setChangeProLayer() {
      var value = this.$store.state.isProjectLayer;
      if (value.length != 0) {
        var std = [];
@@ -1214,13 +1438,17 @@
    this.getMenuProject()
    this.$bus.$on("treeDataCopy", (res) => {
      this.$store.state.treeData = this.treeData;
      this.$store.state.checkedKeys = this.$refs.tree.getCheckedKeys();
      if (this.$refs.tree.getCheckedKeys().length > 0) {
        this.$store.state.checkedKeys = this.$refs.tree.getCheckedKeys();
      }
    });
    if (this.$store.state.showAllLayers == true) {
      this.layersStart();
      this.$store.state.showAllLayers = false;
    } else {
      this.treeData = this.$store.state.treeData;
      this.$refs.tree.setCheckedKeys(this.$store.state.checkedKeys);
    }