guonan
2025-07-10 e92dd671ed1f79243bee0083aecbc5627b5cc7f6
src/components/menu/CrossSectionalAnalysis.vue
@@ -75,8 +75,15 @@
<script setup>
import { ElMessage } from 'element-plus';
import { ref, onMounted, defineExpose } from "vue";
import { getCrossSection } from '@/api/trApi.js'; // 假设你有真实接口
import { useSimStore } from '@/store/simulation';
import { storeToRefs } from 'pinia';
import { EventBus } from "@/eventBus";
const simStore = useSimStore();
const { selectedScheme } = storeToRefs(simStore);
const viewer = window.viewer;
let selectedSchemeId = selectedScheme.value.id
let pickedPointsCross = ref([]);
let pickHandlerCross = null;
@@ -110,7 +117,13 @@
// 选取两个断面点坐标并绘制断面截面
function addPointToViewer(point) {
   if (pickedPointsCross.value.length >= 2) {
      clearPoints();
      for (const id of pickedEntitiesIds.value) {
         viewer.entities.remove(viewer.entities.getById(id));
      }
      pickedPointsCross.value = [];
      pickedEntitiesIds.value = [];
      isWallCreated.value = false;
      isUploaded.value = false;
   }
   pickedPointsCross.value.push(point);
   drawPointOnMap(point);
@@ -164,14 +177,14 @@
   );
   const cylinderBottomHeight = 0;
   const cylinderTopHeight = terrainHeight + 190;
   const cylinderTopHeight = terrainHeight + 100;
   const cartesianBottom = viewer.scene.globe.ellipsoid.cartographicToCartesian(
      Cesium.Cartographic.fromDegrees(midLon, midLat, cylinderBottomHeight)
   );
   const CrosscylinderEntity = viewer.entities.add({
      position: cartesianBottom,
      cylinder: {
         length: 190.0,
         length: 100.0,
         topRadius: 1.0,
         bottomRadius: 1.0,
         material: Cesium.Color.YELLOW,
@@ -218,6 +231,15 @@
   pickedEntitiesIds.value = [];
   isWallCreated.value = false;
   isUploaded.value = false;
   if (pickHandlerCross) {
      pickHandlerCross.destroy();
      pickHandlerCross = null;
   }
   isPicking.value = false;
    simStore.crossSection = []
   EventBus.emit("clear-dM")
   console.log('这里发送请求,清空郭楠的echarts2');
}
function initPickHandler() {
   if (isPicking.value) {
@@ -249,7 +271,9 @@
   pickHandlerCross.setInputAction(clickAction, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
function confirmPoints() {
async function confirmPoints() {
   console.log(selectedSchemeId,'这里拿的是方案的数据');
   if (pickedPointsCross.value.length < 2) {
      ElMessage.warning('请先选择两个点后再进行确认!');
      return;
@@ -257,6 +281,7 @@
   const point1 = pickedPointsCross.value[0];
   const point2 = pickedPointsCross.value[1];
console.log(point1,point2);
   console.log('第一个点信息:', {
      longitude: point1.longitude,
@@ -269,11 +294,35 @@
      latitude: point2.latitude,
      cartesian: point2.cartesian
   });
   const startPoint = `${point1.longitude},${point1.latitude}`;
   const endPoint = `${point2.longitude},${point2.latitude}`;
   const result = await getCrossSectionInfo(startPoint, endPoint);
   simStore.crossSection = result
   console.log(result,'这里是郭楠需要的断面数据');
   isUploaded.value = true;
   ElMessage.success('正在进行--断面截面--数据分析上传,请稍等...');
}
  // 获取真实数据
function getCrossSectionInfo(a, b) {
  const params = {
    startPoint: a,
    endPoint: b,
    id: selectedSchemeId
  };
  return getCrossSection(params).then(data => {
    if (data && data.code === 200) {
      return data.data; // 返回原始数据数组
    } else {
      return [];
    }
  }).catch(error => {
    console.error('获取数据时发生错误:', error);
    ElMessage.warning('数据有误,请联系管理员或重新进行模拟!');
    return [];
  });
}
defineExpose({
   clearPoints
});