管道基础大数据平台系统开发-【前端】-新系統界面
wulitaotao
2023-02-22 9072ac9df972f3f6388c3acbe6d6e351eba11665
src/views/Tools/LayerTree.vue
@@ -49,14 +49,14 @@
      v-show="menuVisible"
    >
      <div @click="addSameLevelNode()">
        <i class="el-icon-circle-plus-outline"></i>&nbsp;&nbsp;同级增加
        <i class="el-icon-circle-plus-outline"></i>&nbsp;&nbsp;添加图层组
      </div>
      <div
        class="add"
        @click="addChildNode()"
        v-show="firstLevel"
      >
        <i class="el-icon-circle-plus-outline"></i>&nbsp;&nbsp;子级增加
        <i class="el-icon-circle-plus-outline"></i>&nbsp;&nbsp;添加图层
      </div>
      <div
        class="delete"
@@ -69,6 +69,12 @@
        @click="editNode()"
      >
        <i class="el-icon-edit"></i>&nbsp;&nbsp;修改节点
      </div>
      <div
        class="edit"
        @click="showLayerAttribute()"
      >
        <i class="el-icon-edit"></i>&nbsp;&nbsp;属性
      </div>
      <!-- <div
        class="edit"
@@ -137,6 +143,7 @@
        >确 定</el-button>
      </span>
    </el-dialog>
     <queryinfo ref="queryinfo" />
  </div>
</template>
@@ -146,15 +153,16 @@
import Image from 'ol/layer/Image';
import GeoJSON from 'ol/format/GeoJSON.js';
import Map from 'ol/Map.js';
import {   Vector as VectorSource } from "ol/source";
import { Vector as VectorLayer,  } from "ol/layer";
import queryinfo from './queryinfo.vue';
import { Vector as VectorSource } from "ol/source";
import { Vector as VectorLayer, } from "ol/layer";
import View from 'ol/View.js';
import { Fill, Stroke, Style } from 'ol/style.js';
import { perms_selectLayers } from '../../api/api.js'
export default {
  name: 'tree',
    components: {  queryinfo },
  data() {
    return {
      eleId: '',
@@ -306,9 +314,55 @@
    deleteNode() {
      this.foo();
      var label = this.currentNode.data.label;
      if (this.currentNode.data.layerType == 'WMS') {
        for (var i in window.Viewer.imageryLayers_layers) {
          if (window.Viewer.imageryLayers_layers[i].name === label) {
            window.Viewer.imageryLayers.remove(window.Viewer.imageryLayers_layers[i])
          }
        }
      } else if (this.currentNode.data.layerType == 'WFS') {
        for (var i in window.Viewer.dataSources._dataSources) {
          if (window.Viewer.dataSources._dataSources[i].name == label) {
            window.Viewer.dataSources.remove(window.Viewer.dataSources._dataSources[i]);
            std.push(data.label)
          }
        }
      }
      var layers_ol = window.map.getAllLayers();
      for (var i in layers_ol) {
        var layerOl = layers_ol[i];
        if (layerOl.values_.name == label) {
          window.map.removeLayer(layerOl); //显示图层
        }
      }
      this.$refs.tree.remove(this.currentNode);
    },
    //属性显示
    showLayerAttribute(data) {
      this.foo();
      this.currentData = data ? data : this.currentData;
      var layer = this.currentData.layer.replaceAll('_', "");
      this.$store.state.mapSpaceQueryLayer = layer;
      // this.$store.state.mapPopBoolean = true;
      this.$store.state.mapPopBoxFlag = '2';
      this.$refs && this.$refs.queryinfo && this.$refs.queryinfo.close();
      this.$refs && this.$refs.queryinfo && this.$refs.queryinfo.open("属性", null, {
        close: () => {
          if (this.$store.state.primitLayer != null) {
            sgworld.Creator.DeleteObject(this.$store.state.primitLayer);
            this.$store.state.primitLayer = null;
          }
          if (window.Viewer.scene.primitives.length != 0) {
            window.Viewer.scene.primitives.removeAll()
          }
        }
      });
    },
    // 编辑节点
    editNode(data) {
@@ -330,7 +384,7 @@
      var node = this.currentNode;
      var data = this.currentData;
      let copyNode = this.currentNode
      debugger
      // copyNode.previousSibling = {...node. }
      // copyNode.nextSibling = {...node.nextSibling}
      // window.sessionStorage.setItem('menuNode',CircularJSON.stringify(copyNode))
@@ -382,8 +436,19 @@
      console.log('tree drop: ', dropNode.label, dropType);
    },
    handleCheckChange(data, checked, indeterminate) {
      if (data.type != 2) return;
      //做判断是否是1:100万行政界面
      if(data.layer==window.XZOutlie&&checked){
        window.ImageLayer3.show=false;
      }else{
        window.ImageLayer3.show=true;
      }
      var std = [];
      if (data.layerType == 'WMS') {
        var layers_ol = window.map.getAllLayers();
@@ -429,22 +494,34 @@
      }
    },
    setAddLayers(res) {
      if (res.layerType == 'WMS') {
        var url = geoServerURl;
        if (res.url != null && res.url != undefined) {
          url = res.url
        }
        var width = $("#mapdiv").width() +5 ;
        var height = $("#mapdiv").height()+5  ;
        var imageryLayers = window.Viewer.scene.imageryLayers;
        let layerWMS = new Cesium.WebMapServiceImageryProvider({
          url: url,
          layers: res.resource,
          parameters: {
            transparent: true,
            format: 'image/png',
        transparent: true,
                format: "image/png",
                srs: "EPSG:4490",
                styles: "",
          },
          tileWidth: width,
            tileHeight: height
        });
        layerWMS.name = res.label;
        window.Viewer.imageryLayers.addImageryProvider(layerWMS);
        //透明度
        var tdtAnnoLayer = imageryLayers.addImageryProvider(layerWMS);
        if (res.opacity) {
          tdtAnnoLayer.alpha = parseInt(res.opacity) / 100;
        }
        var layer2 = new Image({
          name: res.label,
          source: new ImageWMS({
@@ -458,6 +535,9 @@
            },
          }),
        });
        if (res.opacity) {
          layer2.setOpacity(parseInt(res.opacity) / 100);
        }
        window.map.addLayer(layer2);
      } else if (res.layerType == 'WFS') {
@@ -470,7 +550,8 @@
          success: function (data) {
            var datasource = Cesium.GeoJsonDataSource.load(data, {
              stroke: Cesium.Color.YELLOW,
              fill: Cesium.Color.YELLOW.withAlpha(0.5),
              fill: Cesium.Color.YELLOW.withAlpha(0.1),
              alpha: 0.1,
              strokeWidth: 8,
              clampToGround: true //是否贴地
            });
@@ -486,20 +567,15 @@
        });
        var vectorLayer = new VectorLayer({
           name: res.label,
          name: res.label,
          source: new VectorSource({
            url: url,
            format: new GeoJSON(),
          }),
        });
        window.map.addLayer(vectorLayer);
      }
    },
    async layersStart() {
      const data = await perms_selectLayers();
@@ -507,6 +583,7 @@
        return this.$message.error("图层列表查询失败");
      }
      this.newData = data.result;
      this.oriData = data.result;
      var std = [];
@@ -524,6 +601,7 @@
        } else if (data.result[i].type == 2) {
          if (data.result[i].url != null) {
            var layer_entity = {
              id: data.result[i].id,
              pid: data.result[i].pid,
@@ -531,6 +609,7 @@
              resource: data.result[i].url,
              type: data.result[i].type,
              isEdit: false,
              layer: data.result[i].enName,
              layerType: data.result[i].serveType
            }
            layer_list.push(layer_entity)
@@ -624,17 +703,21 @@
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  mounted() {
    this.$bus.$on("treeDataCopy", (res) => {
      this.$store.state.treeData = this.treeData;
      this.$store.state.checkedKeys = this.$refs.tree.getCheckedKeys()
    });
    if (this.$store.state.showAllLayers == true) {
      this.layersStart();
      this.$store.state.showAllLayers = false;
    } else {
      this.treelayersStart();
      this.treeData = this.$store.state.treeData;
      this.$refs.tree.setCheckedKeys(this.$store.state.checkedKeys);
    }
  },