月球大数据地理空间分析展示平台-【前端】-月球2期前端
surprise
2023-11-29 36fbd1e5a40e319e6ac5f43d11c99ba4b66e93a3
src/views/plotting/plottingInquire.vue
@@ -4,21 +4,22 @@
      <div>标绘查询</div>
      <div>
        <el-icon @click="isShow = false" :size="20" style="cursor: pointer">
        <el-icon @click="setMenuClose" :size="20" style="cursor: pointer">
          <Close />
        </el-icon>
      </div>
    </div>
    <div class="inquireContent">
      <div class="inquireContent_title">
        <div>用户新建要素</div>
      </div>
      <div class="inquireContent_name">
        <div class="plotting_list_tr_name">
          <img :src="require(`../../assets/img/${inquireData.icon}`)" class="ico" alt="" /><span>{{ inquireData.name
          }}</span>
          <img :src="require(`../../assets/img/${inquireData.icon}`)" class="ico" alt />
          <span>
            {{ inquireData.name
            }}
          </span>
        </div>
        <div class="plotting_list_tr_wkt" v-show="geoWktFlag">{{ geoWkt }}</div>
        <div class="plotting_list_tr_btn">
@@ -40,7 +41,7 @@
                >
                  <template #append>km</template>
                </el-input>
              </div> -->
              </div>-->
              <div class="inquireContent_input_right" v-show="!chartIsshow">
                <div class="label">范围框内最大像素值</div>
                <el-select v-model="ScopeBox.pixel" class="m-2" placeholder="像素值" size="small" @change="pixelChange">
@@ -66,7 +67,7 @@
                    link
                    class="del linkBtn"
                    @click="deleteChart(e)"
                  ></el-button> -->
                  ></el-button>-->
                </div>
                <Bar-graph :width="'100%'" :height="'260px'" :layerData="layerData"></Bar-graph>
                <div class="select">
@@ -82,7 +83,7 @@
                  <el-button size="small" @click="addCharts"
                    >添加图表</el-button
                  >
                </div> -->
                </div>-->
              </div>
            </div>
@@ -102,22 +103,27 @@
                  m/px</span
                >
              </div>
            </div> -->
            </div>-->
            <div class="inquireContent_table" v-if="!chartIsshow">
              <div class="table">
                <div class="table_head">
                  <div class="table_head_td">序号</div>
                  <div class="table_head_td">
                    <span> 图层名 </span>
                    <span> 分析结果 </span>
                    <span>图层名</span>
                    <span>最大值</span>
                    <span>最小值</span>
                    <span>分析结果</span>
                  </div>
                </div>
                <div class="table_content">
                  <div class="table_tr" v-for="(e, i) in resultList" :key="i">
                    <div class="table_td">{{ i + 1 }}</div>
                    <div class="table_td">
                      <span> {{ e.layerName }}</span>
                      <span> {{ e.avg }}</span>
                      <span>{{ e.layerName }} <label v-show="e.unit"> [{{ e.unit }}]</label></span>
                      <span>{{ e.max }}</span>
                      <span>{{ e.min }}</span>
                      <span>{{ e.avg }}</span>
                    </div>
                  </div>
                </div>
@@ -133,9 +139,11 @@
  </div>
  <div class="dialog" v-if="dialogShow" @click.self="dialogShow = false">
    <div class="chart">
      <i @click.capture="closeDialog"><el-icon>
      <i @click.capture="closeDialog">
        <el-icon>
          <Close />
        </el-icon></i>
        </el-icon>
      </i>
      <BarGraphAxisLine :width="'856px'" :height="'636px'" :layerData="layerData"></BarGraphAxisLine>
    </div>
  </div>
@@ -160,11 +168,17 @@
  saveFSDZJsonToExcel,
  saveFSDZJsonToExcelLine,
} from "@/utils/downloadCSV.js";
import { selectByPoint, selectByPolygon, selectByPolyline } from "@/api/api";
import {
  selectByPoint,
  selectByPolygon,
  selectByPolyline,
  rasterAnalysis_selectByWktForPost,
} from "@/api/api";
import { ElMessage } from "element-plus";
import { Search, Delete, Download, Close } from "@element-plus/icons-vue";
import WKT from "terraformer-wkt-parser";
import * as turf from "@turf/turf";
import { getToken } from "../../utils/auth";
const store = useStore(); // 该方法用于返回store 实例
const emits = defineEmits(["setCloseplotting"]);
let isShow = ref(false);
@@ -272,6 +286,7 @@
let layerNameNum = 0;
let geoWkt = ref(null);
let geoWktFlag = ref(false);
let wktType = ref(null);
//新增图表
const addCharts = () => {
  layerArr.value.push({ layerName: `null${layerNameNum}`, points: [] });
@@ -300,17 +315,25 @@
  // if (store.state.plottingInquireData.entitiesData.icon == "d.png") {
  // }
  selectPoint({
    pixel: val,
    wkt: store.state.plottingInquireData.entitiesData.wkt,
  });
  // selectPoint({
  //   pixel: val,
  //   wkt: store.state.plottingInquireData.entitiesData.wkt,
  // });
  setOptionStart();
  setWebScoKet("Point", store.state.plottingInquireData.entitiesData.wkt, val);
};
//节点选择
const nodesChange = (val) => {
  selectPolyline({
    nodes: val,
    wkt: store.state.plottingInquireData.entitiesData.wkt,
  });
  setOptionStart();
  setWebScoKet(
    "PolyLine",
    store.state.plottingInquireData.entitiesData.wkt,
    val
  );
  // selectPolyline({
  //   nodes: val,
  //   wkt: store.state.plottingInquireData.entitiesData.wkt,
  // });
};
//图层选择
@@ -367,8 +390,11 @@
    e.min = e.minList.toString();
    e.lng = store.state.plottingInquireData.entitiesData.lng;
    e.lat = store.state.plottingInquireData.entitiesData.lat;
    resultList.value.push(e);
  });
  console.log(resultList.value);
};
//面查询接口
const selectPolygon = async (res) => {
@@ -416,12 +442,12 @@
      });
    });
  });
  console.log(dt.result);
  layeroptions.value = dt.result;
  layerValue.value = layeroptions.value[0].layerName;
  layerArr.value.push(dt.result[0]);
  chartIsshow.value = true;
  layerData.value = dt.result[0];
  // dt.result.forEach((e) => {
@@ -458,6 +484,12 @@
      };
      //   store.commit("SET_plotting", obj);
      store.state.plottingInquireData = obj;
      setCloseWebSocket();
      inquireData.value = {
        name: "path #9",
        icon: "q.png",
      };
      isShow.value = false;
      break;
    }
@@ -468,53 +500,154 @@
//     emits("setCloseplotting", false);
//   };
let chartIsshow = ref(false);
const setMenuClose = () => {
  isShow.value = false;
  setCloseWebSocket();
  store.state.plottingInquireData = null;
  inquireData.value = {
    name: "path #9",
    icon: "q.png",
  };
};
const setCloseWebSocket = () => {
  if (Window.ws) {
    Window.ws.close();
    Window.ws.onclose = () => {
      console.log("服务器关闭");
    };
    Window.ws = null;
  }
};
const setWebScoKet = async (type, wkt, node) => {
  const data = await rasterAnalysis_selectByWktForPost({
    wkt: wkt,
    size: node,
  });
  if (data) {
    return;
  }
};
const setOptionStart = () => {
  resultList.value = [];
  layerArr.value = [];
  layeroptions.value = [];
  layerValue.value = '';
};
const setWebSocketStart = () => {
  // if (Window.ws) {
  //   setCloseWebSocket();
  // }
  setOptionStart();
  var token = getToken();
  var url = socketUrl + "?token=" + token;
  Window.ws = new WebSocket(url);
  Window.ws.option = () => { };
  Window.ws.onmessage = (msg) => {
    // console.log('来自服务器端的数据:' + msg.data); //监听接受来自服务端的信息
    if (msg.data != "连接成功") {
      var val = JSON.parse(msg.data);
      if (val.analysisForPost && val.analysisForPost.token == token) {
        var data = val.analysisForPost;
        console.log(data)
        switch (wktType.value) {
          case "Point":
            setWebSocketPoint(data);
            break;
          case "Polygon":
            setWebSocketPoint(data);
            break;
          case "LineString":
            setWebSocketPLine(data);
            break;
        }
      }
    }
  };
};
const setWebSocketPoint = (res) => {
  var obj = {
    avg: res.avgList.length <= 0 ? "--" : res.avgList.toString(),
    layerName: res.layerName,
    max: res.maxList.length <= 0 ? "--" : res.maxList.toString(),
    min: res.minList.length <= 0 ? "--" : res.minList.toString(),
    lng: store.state.plottingInquireData.entitiesData.lng,
    lat: store.state.plottingInquireData.entitiesData.lat,
    unit: res.unit
  };
  resultList.value.push(obj);
};
const setWebSocketPLine = (res) => {
  res.points.forEach((element) => {
    element.vals.forEach((v) => {
      v = keepThreeNum(v);
    });
  });
  layeroptions.value.push(res);
  var data = layeroptions.value[0];
  layerValue.value = data.layerName;
  layerArr.value.push(data);
  layerData.value = data;
};
watch(
  () => store.state.plottingInquireData,
  (nVal, oVal) => {
    isShow.value = nVal.isshow;
    inquireData.value = nVal.entitiesData;
    geoWktFlag.value = false;
    if (inquireData.value.wkt) {
      var wkt = WKT.parse(inquireData.value.wkt);
    setOptionStart();
    setCloseWebSocket();
    if (!nVal) return;
    if (nVal.entitiesData.name != inquireData.value.name) {
      isShow.value = nVal.isshow;
      inquireData.value = nVal.entitiesData;
      geoWktFlag.value = false;
      if (inquireData.value.wkt) {
        var wkt = WKT.parse(inquireData.value.wkt);
        wktType.value = wkt.type;
        if (wkt.type == "Point") {
          geoWkt.value =
            wkt.coordinates[0].toFixed(6) + " " + wkt.coordinates[1].toFixed(6);
          geoWktFlag.value = true;
        }
        if (wkt.type == "Polygon") {
          var Polygon = turf.multiPolygon([wkt.coordinates]);
          var center = turf.center(Polygon);
          geoWkt.value =
            center.geometry.coordinates[0].toFixed(6) +
            " " +
            center.geometry.coordinates[1].toFixed(6);
          geoWktFlag.value = true;
        }
      }
      setWebSocketStart();
      if (wkt.type == "Point") {
        geoWkt.value =
          wkt.coordinates[0].toFixed(6) + " " + wkt.coordinates[1].toFixed(6);
        geoWktFlag.value = true;
      if (nVal.entitiesData.icon == "x.png") {
        pixelIsShow.value = true;
        chartIsshow.value = true;
        setWebScoKet("pline", nVal.entitiesData.wkt, ScopeBox.value.nodes);
        // selectPolyline({
        //   nodes: ScopeBox.value.nodes,
        //   wkt: nVal.entitiesData.wkt,
        // });
      }
      if (wkt.type == "Polygon") {
        var Polygon = turf.multiPolygon([wkt.coordinates]);
        var center = turf.center(Polygon);
        geoWkt.value =
          center.geometry.coordinates[0].toFixed(6) +
          " " +
          center.geometry.coordinates[1].toFixed(6);
        geoWktFlag.value = true;
      if (nVal.entitiesData.icon == "m.png") {
        chartIsshow.value = false;
        // if (nVal.entitiesData.name == oVal.entitiesData.name) {
        //   return;
        // }
        pixelIsShow.value = false;
        // selectPolygon({ wkt: nVal.entitiesData.wkt });
        setWebScoKet("polygon", nVal.entitiesData.wkt, 0);
      }
    }
    if (nVal.entitiesData.icon == "x.png") {
      pixelIsShow.value = true;
      selectPolyline({
        nodes: ScopeBox.value.nodes,
        wkt: nVal.entitiesData.wkt,
      });
    }
    if (nVal.entitiesData.icon == "m.png") {
      chartIsshow.value = false;
      if (nVal.entitiesData.name == oVal.entitiesData.name) {
        return;
      if (nVal && nVal.entitiesData.icon == "d.png") {
        chartIsshow.value = false;
        pixelIsShow.value = true;
        // selectPoint({
        //   pixel: ScopeBox.value.pixel,
        //   wkt: nVal.entitiesData.wkt,
        // });
        setWebScoKet("polygon", nVal.entitiesData.wkt, ScopeBox.value.pixel);
      }
      pixelIsShow.value = false;
      selectPolygon({ wkt: nVal.entitiesData.wkt });
    }
    if (nVal && nVal.entitiesData.icon == "d.png") {
      chartIsshow.value = false;
      pixelIsShow.value = true;
      selectPoint({
        pixel: ScopeBox.value.pixel,
        wkt: nVal.entitiesData.wkt,
      });
    }
  },
  { deep: true }
@@ -526,7 +659,7 @@
  position: absolute;
  right: 26px;
  top: 80px;
  width: 320px;
  width: 400px;
  background: rgba(7, 8, 14, 0.8);
  z-index: 100;
@@ -691,17 +824,15 @@
            align-items: center;
            border-right: 1px solid rgba(214, 228, 255, 0.4);
            box-sizing: border-box;
          }
          .table_head_td:nth-child(2) {
            width: 237px;
            width: 16.34375vw;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 10px;
            border-right: 0;
          }
        }
@@ -727,11 +858,18 @@
              border-right: 1px solid rgba(214, 228, 255, 0.4);
              box-sizing: border-box;
              div {
                width: 100%;
                background: skyblue;
                height: 100%;
              }
              // padding: 5px;
              // white-space: nowrap;
              span {
                display: block;
                width: 50%;
                width: 17%;
                word-wrap: break-word;
                // white-space: pre;
                text-align: left;
@@ -742,21 +880,18 @@
                // justify-content: flex-end;
                // margin-left: 5%;
                //  float: right;
                width: 40%;
                text-align: right;
                // width:16.34375vw;
                text-align: center;
                // background: skyblue;
              }
            }
            .table_td:nth-child(2) {
              width: 237px;
              width: 16.34375vw;
              display: flex;
              justify-content: space-between;
              align-items: center;
              // padding: 0 10px;
              padding-left: 10px;
              padding-right: 10px;
              padding-top: 5px;
              padding-bottom: 5px;
              padding: 0 10px;
              border-right: 0;
            }
          }