管道基础大数据平台系统开发-【前端】-新系統界面
1
13693261870
2023-05-23 d690c11330cff652773685b552376289b8574668
src/views/Tools/LayerTree.vue
@@ -58,18 +58,17 @@
             v-show="menuVisible">
      <div class="edit"
           @click="showLayerAttribute()"
           v-if="!showlocal && !shwoHistogram"
           v-show="!firstLevel">
           v-if="showProp && !shwoHistogram">
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;属性
      </div>
      <div class="edit"
           @click="positioning()"
           v-if="showlocal">
           v-if="showLocal">
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;定位
      </div>
      <div class="edit"
           @click="pellucidity()"
           v-if="showlocal">
           v-if="showOpacity">
        <i class="el-icon-tickets"></i>&nbsp;&nbsp;透明度
      </div>
      <div class="edit"
@@ -95,13 +94,20 @@
  components: { queryinfo },
  data () {
    return {
      shwoHistogram: false,
      showlocal: false,
      showProp: false, // 属性
      shwoHistogram: false, // 钻孔柱状图
      showLocal: false, // 定位
      showOpacity: false, // 不透明度
      menuVisible: false, // 菜单
      levelArray: [ // 调试数组
        0, 40000000, 20000000, 10000000, 5000000, 2000000, 1000000, 500000,
        250000, 200000, 100000, 50000, 17000, 9000, 5000, 2000, 1000, 500, 200,
        100, 50, 25, 10, 0,
      ],
      eleId: "",
      isShow: false,
      currentData: "",
      currentNode: "",
      menuVisible: false,
      firstLevel: false,
      filterText: "",
      appendNodetitle: "",
@@ -193,7 +199,6 @@
        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; // 返回一级菜单
      });
    },
@@ -215,48 +220,24 @@
      //  要及时关掉监听,不关掉的是一个坑,不信你试试,虽然前台显示的时候没有啥毛病,加一个alert你就知道了
      document.removeEventListener("click", this.rmListener);
    },
    //转孔柱状图
    async histogram () {
      this.menuVisible = false
      var layer = this.currentData.enName.replaceAll("_", "");
      this.$store.state.mapSpaceQueryLayer = layer;
      this.$store.state.mapPopBoxFlag = "2";
      this.$store.state.showPopBoxFlag = true;
    // 过滤节点
    filterNode (value, data) {
      if (!value) return true;
      return data.cnName.indexOf(value) !== -1;
    },
    // 鼠标右击事件
    rightClick (event, object, Node, element) {
      if (object.type == 1) {
        return
      }
    rightClick (event, object, node, element) {
      if (object.type == 1 || node.data.children != null) return;
      this.currentNode = node;
      this.currentData = object;
      this.currentNode = Node;
      this.$store.state.propertiesName = object;
      this.$store.state.propertiesName = this.currentData;
      if (this.currentData.serveType == "Tileset" || this.currentData.serveType == "3DML") {
        this.showModelAttach = true;
      } else {
        this.showModelAttach = false;
      }
      if (this.currentData.enName == "s_explorationpoint") {
        this.shwoHistogram = true;
      } else {
        this.shwoHistogram = false;
      }
      if (Node.data.children == null) {
        this.firstLevel = false;
      } else {
        this.firstLevel = true;
      }
      if (Node.data.children == null && Node.data.serveType == "Tileset" || Node.data.serveType == "3DML") {
        this.showlocal = true;
      } else if (Node.data.children == null && Node.data.serveType != "Tileset" || Node.data.serveType == "3DML") {
        this.showlocal = false;
      }
      this.menuVisible = true;
      this.showProp = object.serveType == "WMS"; // 属性
      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.$refs.card.$el.style.left = event.pageX + 20 + "px";
      this.$refs.card.$el.style.top = event.pageY + "px";
@@ -264,207 +245,175 @@
    // 属性显示
    showLayerAttribute (data) {
      this.rmListener();
      this.menuVisible = false
      this.currentData = data ? data : this.currentData;
      var layer = this.currentData.enName.replaceAll("_", "");
      this.$store.state.mapSpaceQueryLayer = layer;
      this.$store.state.showPopBoxFlag = true;
      this.$store.state.mapPopBoxFlag = "2";
    },
    // 模型设置透明度
    // 定位
    async positioning () {
      this.rmListener();
      if (["Tileset", "3DML"].indexOf(this.currentData.serveType) > -1) {
        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]);
            break;
          }
        }
        return;
      }
      if (["TMS", "DOM", "DEM"].indexOf(this.currentData.serveType) > -1 && this.currentData.pubid) {
        var data = await comprehensive_selectPubById({ id: this.currentData.pubid });
        if (data.result && data.result.geom) {
          var wkt = this.$wkt.parse(data.result.geom);
          var height = this.getHeight(wkt.coordinates[2]);
          Viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], height), // 2000
          });
        }
        return;
      }
      if ("Mpt" == this.currentData.serveType) {
        viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(101.8, 37.9, 10000000.0) }); // 中国
      }
    },
    // 钻孔柱状图
    async histogram () {
      this.rmListener();
      var layer = this.currentData.enName.replaceAll("_", "");
      this.$store.state.mapSpaceQueryLayer = layer;
      this.$store.state.mapPopBoxFlag = "2";
      this.$store.state.showPopBoxFlag = true;
    },
    // 透明度
    pellucidity () {
      this.rmListener();
      this.menuVisible = false
      var tile = this.currentData
      for (var j in Viewer.scene.primitives._primitives) {
        if (Viewer.scene.primitives._primitives[j].id == tile.cnName) {
        if (Viewer.scene.primitives._primitives[j].id == this.currentData.cnName) {
          this.$store.state.setAlphaDity = this.currentData;
          this.$bus.$emit("showPellucidity", true);
          break;
        }
      }
    },
    // 模型定位
    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]);
        }
      }
    },
    // 编辑节点
    editNode (data) {
      this.rmListener();
      this.menuVisible = false
      this.currentData = data ? data : this.currentData;
      if (!this.currentData.isEdit) {
        this.$set(this.currentData, "isEdit", true);
      }
      // 获取焦点
      this.$nextTick(() => {
        this.$refs["slotTreeInput" + this.currentData.id].focus();
      });
    },
    menuMoveF (type) {
      // 将变动之前的node备份
      var node = this.currentNode;
      var data = this.currentData;
      let copyNode = this.currentNode;
    // 获取高度
    getHeight (level) {
      if (level > -1 && level < 23) return this.levelArray[level];
      let nodeData = {};
      if (type === "up") {
        // 上移
        if (node.previousSibling) {
          // 删除原先的node
          this.$refs.tree.remove(node.data);
          // 拿到copy的node
          // nodeData = CircularJSON.parse(window.sessionStorage.getItem('menuNode'))
          // // 复制该node到指定位置(参数:1. 要增加的节点的 data 2. 要增加的节点的后一个节点的 data、key 或者 node)
          // this.$refs.tree.insertBefore(nodeData.data,nodeData.previousSibling.data)
          window.sessionStorage.removeItem("menuNode");
        } else {
          this.$message.warning("该菜单已经是当前层最上级");
        }
      } else {
        // 下移
        if (node.nextSibling) {
          this.$refs.tree.remove(node.data);
          nodeData = CircularJSON.parse(
            window.sessionStorage.getItem("menuNode")
          );
          // 参数:1. 要增加的节点的 data 2. 要增加的节点的前一个节点的 data、key 或者 node
          this.$refs.tree.insertAfter(nodeData.data, nodeData.nextSibling.data);
          window.sessionStorage.removeItem("menuNode");
        } else {
          this.$message.warning("该菜单已经是当前层最下级");
      return this.levelArray[this.levelArray.length - 1];
    },
    // 图层选中事件
    handleCheckChange (data, checked) {
      let nodes = [];
      this.getNodes(data, nodes);
      let obj = { WMS: [], Tileset: [], TMS: [], Mpt: [], DEM: [] };
      for (let i = 0, c = nodes.length; i < c; i++) {
        let node = nodes[i];
        switch (node.serveType) {
          case "WMS":
            obj.WMS.push(node);
            break;
          case "3DML":
          case "Tileset":
            obj.Tileset.push(node);
            break;
          case "TMS":
            obj.TMS.push(node);
            break;
          case "Mpt":
            obj.Mpt.push(node);
            break;
          case "DEM":
            obj.DEM.push(node);
            break;
        }
      }
      if (obj.WMS.length) this.setChangeWMS(obj.WMS, checked);
      if (obj.Tileset.length) this.setChangeTileset(obj.Tileset, 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);
    },
    handleDragStart (node, ev) {
      console.log("drag start", node);
    },
    handleDragEnter (draggingNode, dropNode, ev) {
      console.log("tree drag enter: ", dropNode.label);
    },
    handleDragLeave (draggingNode, dropNode, ev) {
      console.log("tree drag leave: ", dropNode.label);
    },
    handleDragOver (draggingNode, dropNode, ev) {
      console.log("tree drag over: ", dropNode.label);
    },
    handleDragEnd (draggingNode, dropNode, dropType, ev) {
      console.log("tree drag end: ", dropNode && dropNode.label, dropType);
    },
    handleDrop (draggingNode, dropNode, dropType, ev) {
      console.log("tree drop: ", dropNode.label, dropType);
    },
    handleCheckChange (data, checked, indeterminate) {
      if (data.type == 1) {
        this.childOption = [];
        this.getchilds(data);
        var listWMS = [];
        var listWFS = [];
        var listTileset = [];
        var listTMS = [];
        var listMpt = [];
        for (var i in this.childOption) {
          switch (this.childOption[i].serveType) {
            case 'WMS':
              listWMS.push(this.childOption[i])
              break;
            case 'WFS':
              listWFS.push(this.childOption[i])
              break;
            case '3DML':
              listTileset.push(this.childOption[i])
              break;
            case 'Tileset':
              listTileset.push(this.childOption[i])
              break;
            case 'Mpt':
              listMpt.push(this.childOption[i])
              break;
            case 'TMS':
              listTMS.push(this.childOption[i])
              break;
    // 获取子节点
    getNodes (data, arr) {
      if (data.children) {
        for (let i = 0, c = data.children.length; i < c; i++) {
          var node = data.children[i];
          if (node.children) {
            this.getNodes(node, arr)
          } else {
            arr.push(node);
          }
        }
        this.setChangeWMS(listWMS, checked);
        this.setChangeWFS(listWFS, checked);
        this.setChangeTileset(listTileset, checked);
        this.setChangeTMS(listTMS, checked);
        this.setChangeMpt(listMpt, checked);
      } else if (data.type == 2) {
        if (data.serveType == "WMS") {
          this.setChangeWMS([data], checked);
        } else if (data.serveType == "Tileset" || data.serveType == "3DML") {
          this.setChangeTileset([data], checked);
        } else if (data.serveType == "TMS") {
          this.setChangeTMS([data], checked);
        } else if (data.serveType == "Mpt") {
          this.setChangeMpt([data], checked);
        }
      } else {
        arr.push(data);
      }
    },
    setChangeWMS (result, checked) {
    // 切换WMS服务
    setChangeWMS (layers, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      this.$bus.$emit("showMenuLayer", value);
    },
    setChangeWFS (result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      var std = [];
      for (var i in value) {
        std.push(value[i].id)
      }
      for (var i in result) {
        var tile = result[i]
        if (std.indexOf(tile.id) != -1) {
          this.setAddLayers(tile)
        } else {
          for (var i in window.Viewer.dataSources._dataSources) {
            if (window.Viewer.dataSources._dataSources[i].name == tile.cnName) {
              window.Viewer.dataSources.remove(window.Viewer.dataSources._dataSources[i]);
            }
          }
    // 切换Tileset
    setChangeTileset (layers, checked) {
      let ids = this.getCheckNodesIds();
      for (var i in layers) {
        var layer = layers[i];
        if (ids.indexOf(layer.id) != -1) {
          this.setAddLayers(layer);
          continue;
        }
          var layers_ol = window.map.getAllLayers();
          for (var i in layers_ol) {
            var layerOl = layers_ol[i];
            if (layerOl.values_.name == tile.cnName) {
              window.map.removeLayer(layerOl)
            }
        for (var j in Viewer.scene.primitives._primitives) {
          if (Viewer.scene.primitives._primitives[j].id == layer.cnName) {
            Viewer.scene.primitives.remove(Viewer.scene.primitives._primitives[j]);
            break;
          }
        }
        var list = this.$store.state.setAlphaList;
        for (var i = 0; i < list.length; i++) {
          if (list[i].name == layer.cnName) {
            list.splice(i, 1);
          }
        }
      }
    },
    setChangeTileset (result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      var std = [];
      for (var i in value) {
        std.push(value[i].id)
    // 获取节点ID
    getCheckNodesIds () {
      var nodes = this.$refs.tree.getCheckedNodes();
      var ids = [];
      for (var i in nodes) {
        ids.push(nodes[i].id);
      }
      for (var i in result) {
        var tile = result[i]
        if (std.indexOf(tile.id) != -1) {
          this.setAddLayers(tile)
        } else {
          for (var j in Viewer.scene.primitives._primitives) {
            if (Viewer.scene.primitives._primitives[j].id == tile.cnName) {
              Viewer.scene.primitives.remove(Viewer.scene.primitives._primitives[j])
            }
          }
          var list = this.$store.state.setAlphaList;
          for (var i = 0; i < list.length; i++) {
            if (list[i].name == tile.cnName) {
              list.splice(i, 1)
            }
      return ids;
    },
    // 切换TMS
    setChangeTMS (layers, checked) {
      let ids = this.getCheckNodesIds();
      for (var i in layers) {
        var layer = layers[i];
        if (ids.indexOf(layer.id) != -1) {
          this.setAddLayers(layer);
          continue;
        }
        for (var i = 0; i < window.Viewer.imageryLayers._layers.length; i++) {
          if (window.Viewer.imageryLayers._layers[i].name == layer.cnName) {
            window.Viewer.imageryLayers.remove(window.Viewer.imageryLayers._layers[i]);
            break;
          }
        }
      }
    },
    // 切换Mpt
    setChangeMpt (result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      var std = [];
@@ -486,42 +435,9 @@
        }
      }
    },
    setChangeTMS (result, checked) {
      var value = this.$refs.tree.getCheckedNodes();
      var std = [];
      for (var i in value) {
        std.push(value[i].id)
      }
      for (var i in result) {
        var tile = result[i]
        if (std.indexOf(tile.id) != -1) {
          this.setAddLayers(tile)
        } else {
          for (var i = 0; i < window.Viewer.imageryLayers._layers.length; i++) {
            var val_id = window.Viewer.imageryLayers._layers[i].name;
            if (val_id == tile.cnName) {
              window.Viewer.imageryLayers.remove(
                window.Viewer.imageryLayers._layers[i]
              );
            }
          }
        }
      }
    },
    getchilds (source) {
      if (source.children) {
        var child = source.children
        for (var i in child) {
          if (child[i].children) {
            this.getchilds(child[i])
          } else {
            this.childOption.push(child[i])
          }
        }
      } else {
        this.childOption.push(source)
      }
    // 切换DEM
    setChangeDEM () {
      //
    },
    async setAddLayers (res) {
      if (res.serveType == "WMS") {
@@ -737,10 +653,10 @@
        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),
          });
          // var wkt = this.$wkt.parse(data.result.geom);
          // Viewer.camera.flyTo({
          //   destination: Cesium.Cartesian3.fromDegrees(wkt.coordinates[1], wkt.coordinates[0], 2000),
          // });
        }
        this.setChangeWMS();
      }
@@ -767,12 +683,6 @@
      //修改模型矩阵
      tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
      // Viewer.flyTo(tileset);
    },
    // 查询
    filterNode (value, data) {
      if (!value) return true;
      return data.cnName.indexOf(value) !== -1;
    },
    async setproChange (res) {
      if (res) {