管道基础大数据平台系统开发-【前端】-新系統界面
王旭
2023-05-10 7a0c7de021aebbef3ec137f2f94ff73ab41014d7
src/views/exportMap/index.vue
@@ -36,7 +36,7 @@
        <el-form-item>
          <el-link
            @click="setMapAddDraw()"
            @click="drawRegularPolygon()"
            :underline="false"
          ><i class="el-icon-edit-outline"></i>绘制</el-link>
        </el-form-item>
@@ -75,13 +75,13 @@
            :underline="false"
          >矢量</el-link>
        </el-form-item>
        <el-form-item label="旋转角度">
        <!-- <el-form-item label="旋转角度">
          <el-input
            v-model="formInline.role"
            placeholder="请输入内容"
            @change="setMapRole"
          ></el-input>
        </el-form-item>
        </el-form-item> -->
      </el-form>
    </div>
    <div
@@ -109,7 +109,7 @@
              node-key="id"
              :props="defaultProps"
              :default-expanded-keys="[1]"
              @check-change="handleTreeNodeClick"
              @check="handleTreeNodeClick"
              ref="tree"
            >
            </el-tree>
@@ -131,6 +131,12 @@
      >
        <el-form-item label="出图名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="旋转角度">
          <el-input
            v-model="formInline.role"
            placeholder="请输入旋转角度(0-360)"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <div style="padding: 1%;  ">
@@ -174,6 +180,7 @@
        ref="singleTable"
        :data="exportable"
        style="width: 100%"
        border
        height="200"
        @selection-change="handleSelectionChange"
      >
@@ -278,6 +285,8 @@
import TileLayer from "ol/layer/Tile"
import { transform } from "ol/proj"
import Draw, { createRegularPolygon, createBox } from "ol/interaction/Draw.js"
import { OSM, Vector as VectorSource } from "ol/source"
import { Vector as VectorLayer } from "ol/layer"
import LayerVector from "ol/layer/Vector"
@@ -317,15 +326,18 @@
        { label: "A2", value: "A2" },
        { label: "A3", value: "A3" },
        { label: "A4", value: "A4" },
        { label: "A5", value: "A5" },
        { label: "A6", value: "A6" },
        // { label: "A5", value: "A5" },
        // { label: "A6", value: "A6" },
      ],
      value: "A4",
      treeData: [],
      arrList: [],
      layername: [
        1, 2, 5, 13, 15, 16, 31
      ],
      defaultProps: {
        children: "children",
        label: "label",
        label: "cnName",
      },
      draw: null,
      vector: null,
@@ -337,99 +349,97 @@
        pageIndex: 1,
      },
      count: 0,
    }
  },
  mounted() {
    this.LayerStart()
    this.initMap()
    this.showMapLayer()
  },
  methods: {
    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; // 返回一级菜单
      });
    },
    async LayerStart() {
      const data = await perms_selectLayers()
      if (data.code != 200) {
        return this.$message.error("图层列表查询失败")
      }
      var std = []
      var layer_list = []
      var layer_groups = []
      for (var i in data.result) {
        if (data.result[i].type == 1) {
          layer_groups.push({
            id: data.result[i].id,
            label: data.result[i].cnName,
            type: data.result[i].type,
            isEdit: false,
            children: [],
          })
        } 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,
              label: data.result[i].cnName,
              resource: data.result[i].url,
              type: data.result[i].type,
              isEdit: false,
            }
            layer_list.push(layer_entity)
            if (data.result[i].isShow == 1) {
              std.push(data.result[i].id)
              this.tableData.push({
                name: layer_entity.label,
              })
              this.showMapLayer(layer_entity)
            }
          }
        }
      }
      for (var i in layer_list) {
        for (var j in layer_groups) {
          if (layer_list[i].pid === layer_groups[j].id) {
            layer_groups[j].children.push(layer_list[i])
          }
        }
      }
      layer_groups = layer_groups.filter((res) => {
        if (res.children != null && res.children.length != 0) {
          return res
        }
      })
      this.treeData = layer_groups;
      var res = data.result;
      // for (var i in data.result) {
      //   if (data.result[i].type == 2 && data.result[i].url != null) {
      //     for (var j = 0; j <  window.mapView.imageryLayers._layers.length; j++) {
      //       var val_id = window.mapView.imageryLayers._layers[j]
      //       if (val_id.show == true) {
      //         if (val_id.imageryProvider.name == data.result[i].cnName) {
      //           std.push(data.result[i].id)
      //         }
      //       }
      //     }
      //   }
      // }
      debugger
      var val = [];
      var std = [];
      var layerWMS = [];
      for (var i in res) {
        var str = res[i];
        if (str.type == 1 && str.icon == 1) {
          val.push(str)
        } else if (str.url != null && str.type == 2 && str.icon == 1) {
          if (str.isShow == 1) {
            std.push(str.id)
            layerWMS.push(str)
            this.tableData.push({
              name: str.cnName,
              ename: str.enName,
            })
          }
          val.push(str)
        }
      }
      var res = this.setTreeData(val);
      this.treeData = res;
      this.$refs.tree.setCheckedKeys(std)
      this.showMapLayer(layerWMS);
    },
    setClearMap() {
      var layers_ol = mapView.getAllLayers();
      for (var i in layers_ol) {
        var layerOl = layers_ol[i];
        if (layerOl.values_.name == "Wms_Layer") {
          mapView.removeLayer(layers_ol[i]); //显示图层
        }
      }
    },
    showMapLayer(val) {
      debugger
      if (val == undefined) return;
      var layer2 = new Image({
        name: val.label,
        source: new ImageWMS({
          crossOrigin: "anonymous",
          url: geoServerURl,
      if (val) {
        this.setClearMap();
        var url = [];
        for (var i in val) {
          if (val[i].url) {
            url.push(val[i].url)
          }
          params: {
            FORMAT: "image/png",
            VERSION: "1.1.1",
            LAYERS: val.resource,
          },
        }),
      })
      mapView.addLayer(layer2)
        }
        url = url.reverse()
        console.log(url)
        var layer2 = new Image({
          name: "Wms_Layer",
          source: new ImageWMS({
            crossOrigin: "anonymous",
            url: geoServerURl,
            params: {
              FORMAT: "image/png",
              VERSION: "1.1.1",
              LAYERS: url.toString(),
            },
          }),
        });
        mapView.addLayer(layer2)
      }
    },
    showLeftMenu(res) {
      switch (res) {
@@ -498,7 +508,7 @@
        resolution: "20米",
        date: this.getYMD(),
        layers: res.toString(),
        rotation: 0,
        rotation: this.form.role,
        xmin: this.layerExtent.xmin,
        ymin: this.layerExtent.ymin,
        xmax: this.layerExtent.xmax,
@@ -534,7 +544,7 @@
      var token = "?token=" + getToken()
      var a = document.createElement("a") // 创建一个a标签元素
      a.style.display = "none" // 设置元素不可见
      a.href = BASE_URL + "/mark/downloadFile" + token + "&guid=" + guid
      a.href = BASE_URL + "/export/downloadFile" + token + "&guid=" + guid
      document.body.appendChild(a) // 加入
      a.click() // 触发点击,下载
@@ -546,7 +556,53 @@
      }
      this.layerExtent = null
    },
    stopDraw() {
      // if (this.draw !== null) {
      //   this.map.removeInteraction(this.draw)
      // }
      if (this.draw != null) {
        mapView.removeLayer(this.vector)
      }
      this.layerExtent = null
    },
    drawRegularPolygon() {
      this.stopDraw();
      this.source = new VectorSource({ wrapX: false })
      this.vector = new VectorLayer({
        source: this.source,
      })
      mapView.addLayer(this.vector)
      let type = 'Circle'
      let geometryFunction2 = createRegularPolygon(4)
      this.draw = new Draw({
        source: this.source,
        type: type,
        geometryFunction: geometryFunction2
      })
      mapView.addInteraction(this.draw)
      this.draw.on("drawend", e => {
        let feature = e.feature
        let geom = feature.getGeometry()
        var extent = geom.getExtent()
        var a1 = transform([extent[0], extent[1]], "EPSG:3857", "EPSG:4326")
        var a2 = transform([extent[2], extent[3]], "EPSG:3857", "EPSG:4326")
        this.layerExtent = {
          xmin: a1[0],
          ymin: a1[1],
          xmax: a2[0],
          ymax: a2[1],
        }
        mapView.removeInteraction(this.draw)
      })
    },
    //绘制图形
    setMapAddDraw() {
      this.setMapRemoveDraw()
@@ -598,13 +654,13 @@
      this.loading = true
      var val_data = []
      for (var i in this.tableData) {
        val_data.push(this.tableData[i].name)
        val_data.push(this.tableData[i].ename)
      }
      if (this.isActive) {
        val_data.push("矢量图")
        val_data.push("高德矢量")
      } else {
        val_data.push("影像注记")
        val_data.push("影像图")
        // val_data.push("影像注记")
        val_data.push("高德影像")
      }
      this.setExportMapLayer(val_data)
      this.showMapApply = false
@@ -612,36 +668,55 @@
    },
    handleClose() { },
    handleTreeNodeClick(data, nodes) {
      if (data.children != null) return
      var layers = mapView.getAllLayers()
      for (var i in layers) {
        var layer = layers[i]
        var str = 0
        if (layer.values_.name == data.label) {
          layer.setVisible(nodes) //显示图层
          if (nodes == true) {
            str++
            this.tableData.push({
              name: data.label,
            })
          } else {
            this.tableData.some((item, i) => {
              if (item.name === data.label) {
                this.tableData.splice(i, 1)
              }
            })
          }
      var value = this.$refs.tree.getCheckedNodes();
      this.showMapLayer(value)
      var std = [];
      for (var i in value) {
        if (value[i].type == 2) {
          var str = value[i]
          std.push({
            name: str.cnName,
            ename: str.enName,
          })
        }
      }
      if (str == 0 && nodes == true) {
        this.showMapLayer(data)
        this.tableData.push({
          name: data.label,
        })
      }
      this.tableData = std;
      // if (data.children != null) return
      // this.tableData = this.arrList
      // var layers = mapView.getAllLayers()
      // for (var i in layers) {
      //   var layer = layers[i]
      //   var str = 0
      //   if (layer.values_.name == data.cnName) {
      //     layer.setVisible(nodes) //显示图层
      //     if (nodes == true) {
      //       str++
      //       this.tableData.push({
      //         name: data.cnName,
      //         ename: data.enName
      //       })
      //     } else {
      //       this.tableData.some((item, i) => {
      //         if (item.name === data.cnName) {
      //           this.tableData.splice(i, 1)
      //         }
      //       })
      //     }
      //   }
      // }
      // if (str == 0 && nodes == true) {
      //   this.showMapLayer(data)
      //   // this.tableData.push({
      //   //   name: data.cnName,
      //   //   ename: data.enName,
      //   // })
      // }
      // // this.tableData = this.arrList
    },
    setAddMapLayer() {
      this.dialogVisible = false
@@ -673,14 +748,14 @@
          url: "http://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=6",
        }),
      })
      var GaoDeTitle = new TileLayer({
        source: new XYZ({
          url: "http://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8",
        }),
      })
      // var GaoDeTitle = new TileLayer({
      //   source: new XYZ({
      //     url: "http://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=8",
      //   }),
      // })
      window.mapView = new Map({
        target: "mapView",
        layers: [TiandiLayer, GaoDeLayer, GaoDeTitle],
        layers: [TiandiLayer, GaoDeLayer],
        view: new View({
          center: transform([105.02, 34.9], "EPSG:4326", "EPSG:3857"),
          zoom: 4,
@@ -701,11 +776,11 @@
    setLayerVisible() {
      if (this.isActive == true) {
        mapView.getLayers().item(1).setVisible(false)
        mapView.getLayers().item(2).setVisible(false)
        // mapView.getLayers().item(2).setVisible(false)
        mapView.getLayers().item(0).setVisible(true)
      } else {
        mapView.getLayers().item(1).setVisible(true)
        mapView.getLayers().item(2).setVisible(true)
        // mapView.getLayers().item(2).setVisible(true)
        mapView.getLayers().item(0).setVisible(false)
      }
    },
@@ -725,6 +800,7 @@
    width: 100%;
    height: 70px;
    padding-left: 20px;
    margin: 0;
  }
  .left_Menu {
    z-index: 40;
@@ -797,5 +873,14 @@
  /deep/.el-form-item {
    margin-top: 10px;
  }
  /deep/ .el-tree-node {
    .is-leaf + .el-checkbox .el-checkbox__inner {
      display: inline-block;
    }
    .el-checkbox .el-checkbox__inner {
      display: none;
    }
  }
}
</style>