| | |
| | | import { flyVisual } from '@/utils/cesium/mapUtil'; |
| | | import rightEdit from '@/views/layerManagement/components/rightEdit.vue'; |
| | | import leftList from '@/views/layerManagement/components/leftList.vue'; |
| | | import nationalSpatialPlanning from '@/views/layerManagement/components/nationalSpatialPlanning.vue'; |
| | | import { DrawPolygon } from '@/views/layerManagement/components/utils'; |
| | | import * as Cesium from 'cesium'; |
| | | import { PublicCesium } from '@/utils/cesium/publicCesium'; |
| | | import _, { cloneDeep, throttle } from 'lodash'; |
| | | import { ElButton } from 'element-plus'; |
| | | |
| | | import { provide } from 'vue'; |
| | | import { useStore } from 'vuex'; |
| | | const store = useStore(); |
| | |
| | | }; |
| | | // 编辑文件夹 |
| | | const handleFolder = val => { |
| | | parentMethod() |
| | | layerParams.value.editFolderData = val; |
| | | }; |
| | | // 新增开启绘制 |
| | |
| | | let publicCesiumInstance = null; |
| | | let viewer = null; |
| | | const viewInstance = shallowRef(null); |
| | | const homeViewer = shallowRef(null); |
| | | const drawPolygonExample = new DrawPolygon(); |
| | | // 地图初始化 |
| | | const initMap = () => { |
| | |
| | | layerMode: 4, |
| | | contour: false, |
| | | }); |
| | | |
| | | viewer = publicCesiumInstance.getViewer(); |
| | | viewInstance.value = publicCesiumInstance; |
| | | |
| | | const nanChangPosition = Cesium.Cartesian3.fromDegrees( |
| | | 115.892151, // 经度 |
| | | 28.676493, // 纬度 |
| | |
| | | let polygonString = JSON.stringify(polygon); |
| | | layerParams.value.polygonPosition = polygon.length > 0 ? polygonString : null; |
| | | if (polygon.length >= 3) { |
| | | // 确保多边形闭合:最后一个点与第一个点一致(避免计算偏差) |
| | | // 确保多边形闭合:最后一个点与第一个点一致 |
| | | const firstPoint = polygon[0]; |
| | | const lastPoint = polygon[polygon.length - 1]; |
| | | const isClosed = |
| | | _.round(firstPoint[0], 6) === _.round(lastPoint[0], 6) && |
| | | _.round(firstPoint[1], 6) === _.round(lastPoint[1], 6); |
| | | // 若未闭合,手动添加闭合点 |
| | | const closedPolygon = isClosed ? polygon : [...polygon, firstPoint]; |
| | | // 转换为 turf 支持的 GeoJSON 格式(Polygon 类型需外层嵌套数组) |
| | | const turfPolygon = turf.polygon([closedPolygon]); |
| | | // 计算面积(turf.area() 返回平方米,保留2位小数) |
| | | const area = _.round(turf.area(turfPolygon), 2); |
| | | // 赋值给 layerParams, |
| | | layerParams.value.fenceArea = area; |
| | | } else { |
| | | // 坐标点不足3个时,清空面积 |
| | | layerParams.value.fenceArea = 0; |
| | | } |
| | | }; |