wangjuncheng
2025-07-14 263bf9730455a7bcc4fdc6471f8f9d0c96e47c9e
src/views/left/KGSimOption/PredictiveSimulation.vue
@@ -254,9 +254,11 @@
// 打开保存方案对话框
const openSaveDialog = async () => {
  // 在 setup 内部更新 geom 的值
  printDamEntities();
  try {
    forms.geom = props.selectedArea;
    await simStore.addSimCheme(forms);
    // 打印拦挡坝所需要的数据
    resetForm();
    EventBus.emit("close-selectArea");
  } catch (err) {}
@@ -304,6 +306,70 @@
const openPlan = () => {
  console.log("打开方案按钮被点击");
};
// ========================================拦挡坝===============================================================
// 获取拦挡坝数据
function printDamEntities() {
  const entities = viewer.entities.values;
  const damDataList = [];
  for (let i = 0; i < entities.length; i++) {
    const entity = entities[i];
    if (entity.name && (entity.name === '栏档坝1' || entity.name === '栏档坝2')) {
      let position = entity.position?._value;
      // 如果有位置信息,就将其从笛卡尔坐标转为经纬度和高度
      let cartographic = undefined;
      if (position) {
        cartographic = Cesium.Cartographic.fromCartesian(position);
      }
      damDataList.push({
        name: entity.name,
        position: position ? {
          x: position.x,
          y: position.y,
          z: position.z
        } : null,
        cartographic: cartographic ? {
          longitude: Cesium.Math.toDegrees(cartographic.longitude), // 经度(度)
          latitude:  Cesium.Math.toDegrees(cartographic.latitude),  // 纬度(度)
          height:    cartographic.height                           // 高度(米)
        } : null,
        heading: entity.heading?._value ?? entity.heading,
        pitch: entity.pitch?._value ?? entity.pitch,
        roll: entity.roll?._value ?? entity.roll,
        modelScale: entity.model?.scale?._value ?? entity.model?.scale
      });
    }
  }
  if (damDataList.length > 0) {
    console.log("【栏档坝实体数据列表】:", damDataList);
    deleteDamEntitiesAfterDelay();
  } else {
    console.log("未找到任何名为 '栏档坝1' 或 '栏档坝2' 的实体");
  }
}
// 保存方案后定时清除新建的拦挡坝数据
function deleteDamEntitiesAfterDelay() {
  setTimeout(() => {
    const entities = Array.from(viewer.entities.values);
    const damsToDelete = entities.filter(
      entity => entity.name === '栏档坝1' || entity.name === '栏档坝2'
    );
    damsToDelete.forEach(entity => {
      viewer.entities.remove(entity);
    });
    if (damsToDelete.length > 0) {
      console.log(`【已删除】共 ${damsToDelete.length} 个栏档坝实体`);
    } else {
      console.log("未找到任何可删除的栏档坝实体");
    }
  }, 5000);
}
</script>
<style lang="less" scoped>