管道基础大数据平台系统开发-【前端】-新系統界面
13693261870
2023-05-29 30fe4cd9c36002c112c5025dcf05819034f71233
src/views/Tools/LayerTree.vue
@@ -76,6 +76,11 @@
           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>
    </el-card>
  </div>
</template>
@@ -85,7 +90,7 @@
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",
@@ -98,6 +103,7 @@
      shwoHistogram: false, // 钻孔柱状图
      showLocal: false, // 定位
      showOpacity: false, // 不透明度
      shwoTileDown: false, // 瓦片下载
      menuVisible: false, // 菜单
      levelArray: [ // 高程数组
        0, 40000000, 20000000, 10000000, 5000000, 2000000, 1000000, 500000,
@@ -171,14 +177,44 @@
    },
    // 设置树数据
    setTreeData (source) {
      let cloneData = JSON.parse(JSON.stringify(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) {
@@ -215,7 +251,8 @@
      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.$refs.card.$el.style.left = event.pageX + 20 + "px";
      this.$refs.card.$el.style.top = event.pageY + "px";
@@ -283,6 +320,33 @@
      return this.levelArray[this.levelArray.length - 1];
    },
    // 瓦片下载
    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) {
      if (this.isBusy) return;
@@ -313,7 +377,7 @@
        }
      }
      this.setChangeDEM(obj.DEM, checked);
      if (obj.TMS.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.Tileset.length) this.setChangeTileset(obj.Tileset, checked);
@@ -464,7 +528,7 @@
        let layer = Viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
          url: res.url,
          maximumLevel: 22,
        }));
        }), 1); // addImageryProvider -> add
        layer.id = res.id;
        layer.name = res.cnName;
      }
@@ -505,7 +569,6 @@
    },
    // 切换DEM
    setChangeDEM (layers, checked) {
      debugger
      let ids = this.getCheckNodesIds(), arr = [];
      for (let i in layers) {
        let layer = layers[i];
@@ -546,7 +609,7 @@
      }
      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) {
@@ -589,7 +652,7 @@
          minimumLevel: data.result.min
        });
      let layer = Viewer.imageryLayers.addImageryProvider(provider);
      let layer = Viewer.imageryLayers.addImageryProvider(provider, 1);
      layer.name = res.cnName;
      // if (data.result.geom) {
@@ -602,20 +665,20 @@
    // 切换项目
    prjChanged (code) {
      this.$store.state.pigCode = code;
      if (code) {
        this.isBusy = true;
        let checkedLayers = this.getCheckedLayersByCode(code);
      //if (code) {
      this.isBusy = true;
      let checkedLayers = this.getCheckedLayersByCode(code);
        let checkedKeys = [];
        for (let i in checkedLayers) {
          checkedKeys.push(checkedLayers[i].id);
        }
        this.$refs.tree.setCheckedKeys(checkedKeys);
        sessionStorage.setItem("checkedLayers", JSON.stringify(checkedLayers));
        this.isBusy = false;
      let checkedKeys = [];
      for (let i in checkedLayers) {
        checkedKeys.push(checkedLayers[i].id);
      }
      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);
      }