无人机管理后台前端(已迁走)
张含笑
2025-11-03 4fffb89303d9e11cb6b46131a4ae27f5c03fe4a4
feat:添加闭合点
3 files modified
43 ■■■■■ changed files
src/views/layerManagement/components/leftList.vue 2 ●●● patch | view | raw | blame | history
src/views/layerManagement/components/rightEdit.vue 5 ●●●● patch | view | raw | blame | history
src/views/layerManagement/index.vue 36 ●●●●● patch | view | raw | blame | history
src/views/layerManagement/components/leftList.vue
@@ -120,7 +120,7 @@
    loading.value = true;
    const res = await treeDataApi();
    treeAllData.value = res.data.data;
    console.log('接口数据', treeAllData.value);
    setupWatch();
  } catch (error) {
    console.error('获取数据失败:', error);
src/views/layerManagement/components/rightEdit.vue
@@ -147,7 +147,7 @@
  control_start_time: '',
  control_end_time: '',
  geo_data: '',
  altitude: '',
});
const detailData = ref(null);
const fenceArea = ref(0);
@@ -171,8 +171,6 @@
watch(
  () => layerParams.value.editDetailData,
  newVal => {
    console.log('newVal', newVal);
    if (newVal && layerParams.value.editingIsProhibited) {
      // 当editDetailData有值时,填充表单
      formData.value = {
@@ -269,7 +267,6 @@
    control_start_time: formData.value.control_start_time,
    control_end_time: formData.value.control_end_time,
  };
  // 如果是编辑模式,才添加 id
  if (layerParams.value.decideWhetherToAddOrEdit === 2) {
    params.id = detailData.value.id;
src/views/layerManagement/index.vue
@@ -140,12 +140,31 @@
  });
};
// 编辑围栏区域
// const handleEdit = val => {
// console.log('编辑数据',val.geo_data);
//   viewer.entities.removeAll();
//   layerParams.value.editDetailData = val;
//   drawPolygonExample.editThePatch(true);
//   drawPolygonExample.drawTheArea(true);
//   const positions = parseGeoDataToPositions(val.geo_data, val.altitude);
//   if (positions.length < 3) return; // 少于3个点无法构成多边形
//   drawPolygonExample.initPolygon(viewer, positions, true);
// };
// 编辑围栏区域
const handleEdit = val => {
  viewer.entities.removeAll();
  layerParams.value.editDetailData = val;
  drawPolygonExample.editThePatch(true);
  drawPolygonExample.drawTheArea(true);
  const positions = parseGeoDataToPositions(val.geo_data, val.altitude);
  drawPolygonExample.drawTheArea(true);
  // 移除最后一个点
  let geoDataArr = JSON.parse(val.geo_data);
  if (geoDataArr.length > 0) {
    geoDataArr.pop();
  }
  const processedGeoData = JSON.stringify(geoDataArr);
  // 使用处理后的 geo_data 解析坐标
  const positions = parseGeoDataToPositions(processedGeoData, val.altitude);
  if (positions.length < 3) return; // 少于3个点无法构成多边形
  drawPolygonExample.initPolygon(viewer, positions, true);
};
@@ -182,7 +201,7 @@
  tbJwdList = [];
  dataList.forEach(item => {
    let positions = parseGeoDataToPositions(item.geo_data, item.altitude);
    positions.push(positions[0]);
    // positions.push(positions[0]);
    if (positions.length < 3) {
      console.warn(`数据 ${item.name} 坐标点不足,无法绘制`);
      return;
@@ -305,7 +324,6 @@
    },
  });
};
// 编辑/绘制
const loadPlanarRoute = async (positions = null, save = false) => {
  isShowWaringTip.value = false;
@@ -322,8 +340,10 @@
      };
    });
  }
  let polygon = curPolygonPosition.map(item => [item?.lng, item?.lat]);
 if(polygon.length > 0){
      polygon.push([curPolygonPosition[0]?.lng, curPolygonPosition[0]?.lat])
 }
  let polygonString = JSON.stringify(polygon);
  layerParams.value.polygonPosition = polygon.length > 0 ? polygonString : null;
  if (polygon.length >= 3) {
@@ -378,27 +398,22 @@
  }
};
provide('layerParams', layerParams);
onMounted(() => {
  initMap();
  cesiumContextMenu();
  getdataFolderApi();
  // 监听单个实体删除事件
  EventBus.on('deleteMapEntityById', deleteMapEntityById);
  // 监听文件夹下所有实体删除事件
  EventBus.on('deleteMapEntitiesByFolderId', deleteMapEntitiesByFolderId);
});
onBeforeUnmount(() => {
  destroyMap();
  cesiumContextMenu(false);
  // 移除事件监听
  EventBus.off('deleteMapEntityById', deleteMapEntityById);
  EventBus.off('deleteMapEntitiesByFolderId', deleteMapEntitiesByFolderId);
});
// 删除单个地图实体
const deleteMapEntityById = entityId => {
  if (!viewer) return;
@@ -409,7 +424,6 @@
  // 更新选中数据列表
  selectDataList.value = selectDataList.value.filter(item => item.id !== entityId);
};
// 删除文件夹下所有地图实体
const deleteMapEntitiesByFolderId = folderId => {
  if (!viewer) return;