| | |
| | | :terrain="true" |
| | | :layer-mode="4" |
| | | :boundary="false" |
| | | :zoom-to-boundary="dialogMode === 'add'" |
| | | /> |
| | | </div> |
| | | <div class="right-container"> |
| | | <div class="header"> |
| | | {{ titleEnum[dialogMode] }} |
| | | <span>{{ titleEnum[dialogMode] }}</span> |
| | | |
| | | <el-icon class="close-btn" @click.stop="visible = false"><Close /></el-icon> |
| | | </div> |
| | | |
| | | <div class="dialog-container" v-if="readonly"> |
| | | <div class="content" v-if="readonly"> |
| | | <div class="detail-title">场景详情</div> |
| | | <el-row> |
| | | <el-col :span="24"> |
| | | <div class="label">场景名称</div> |
| | | <div class="label">配置名称</div> |
| | | <div class="val">{{ formData.sceneName }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">指挥点位置</div> |
| | | <div class="val">{{ formatLocation(formData) }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">场景类型</div> |
| | | <div class="val">{{ getDictLabel(formData.sceneType, dictObj.sceneType) }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">负责人</div> |
| | | <div class="val">{{ formData.defenseLeader }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">负责人电话</div> |
| | | <div class="val">{{ formData.leaderPhone }}</div> |
| | | <div class="val">{{ getDictLabel(formData.sceneType, dictObj.CommandSceneType) }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">设备模式</div> |
| | | <div class="val">{{ getDictLabel(formData.deviceMode, dictObj.deviceMode) }}</div> |
| | | </el-col> |
| | | <el-col :span="24"> |
| | | <div class="label">防控面积</div> |
| | | <div class="val">{{ formatDefenseArea(formData.defenseArea) }}</div> |
| | | </el-col> |
| | | </el-row> |
| | | |
| | |
| | | <div class="command-table-content"> |
| | | <el-table class="command-table" ref="areaTableRef" :data="areaList" row-key="id"> |
| | | <el-table-column prop="areaName" label="区域名称" /> |
| | | <el-table-column prop="areaType" label="区域类型"> |
| | | <el-table-column prop="areaTypeKeys" label="区域类型"> |
| | | <template v-slot="{ row }"> |
| | | {{ getDictLabel(row.areaType, dictObj.areaType) }} |
| | | {{ getDictLabel(row.areaTypeKeys, dictObj.areaType) }} |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | |
| | | </div> |
| | | </div> |
| | | |
| | | <el-form class="dialog-form" v-else ref="formRef" :model="formData" :rules="rules" :disabled="readonly" |
| | | label-width="96px"> |
| | | <el-form-item label="场景名称" prop="sceneName"> |
| | | <el-input class="command-input" v-model="formData.sceneName" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="指挥点位置" prop="longitude"> |
| | | <div class="val">{{ formatLocation(formData) }}</div> |
| | | <el-form |
| | | class="dialog-form" |
| | | v-else |
| | | ref="formRef" |
| | | :model="formData" |
| | | :rules="rules" |
| | | :disabled="readonly" |
| | | label-width="96px" |
| | | > |
| | | <el-form-item label="配置名称" prop="sceneName"> |
| | | <el-input |
| | | class="command-input" |
| | | v-model="formData.sceneName" |
| | | maxlength="50" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="场景类型" prop="sceneType"> |
| | | <el-select class="command-select" popper-class="command-select-popper" |
| | | v-model="formData.sceneType" placeholder="请选择" clearable> |
| | | <el-option v-for="item in dictObj.sceneType" :key="item.dictKey" :label="item.dictValue" |
| | | :value="item.dictKey" /> |
| | | <el-select |
| | | class="command-select" |
| | | popper-class="command-select-popper" |
| | | v-model="formData.sceneType" |
| | | placeholder="请选择" |
| | | clearable |
| | | > |
| | | <el-option |
| | | v-for="item in dictObj.CommandSceneType" |
| | | :key="item.dictKey" |
| | | :label="item.dictValue" |
| | | :value="item.dictKey" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="负责人" prop="defenseLeader"> |
| | | <el-input class="command-input" v-model="formData.defenseLeader" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="负责人电话" prop="leaderPhone"> |
| | | <el-input class="command-input" v-model="formData.leaderPhone" maxlength="50" |
| | | placeholder="请输入" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="设备模式" prop="deviceMode"> |
| | | <el-select class="command-select" popper-class="command-select-popper" |
| | | v-model="formData.deviceMode" placeholder="请选择" clearable> |
| | | <el-option v-for="item in dictObj.deviceMode" :key="item.dictKey" :label="item.dictValue" |
| | | :value="item.dictKey" /> |
| | | <el-select |
| | | class="command-select" |
| | | popper-class="command-select-popper" |
| | | v-model="formData.deviceMode" |
| | | placeholder="请选择" |
| | | clearable |
| | | > |
| | | <el-option |
| | | v-for="item in dictObj.deviceMode" |
| | | :key="item.dictKey" |
| | | :label="item.dictValue" |
| | | :value="item.dictKey" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="防控面积" prop="defenseArea"> |
| | | <div class="val">{{ formatDefenseArea(formData.defenseArea) }}</div> |
| | | </el-form-item> |
| | | |
| | | <div class="search-table-container"> |
| | | <div class="search-box"> |
| | | <div class="label"> |
| | | 关联区域 |
| | | </div> |
| | | <div class="label">关联区域</div> |
| | | |
| | | <el-input class="command-input" v-model="searchName" placeholder="请输入" |
| | | clearable></el-input> |
| | | <el-input class="command-input" v-model="searchName" placeholder="请输入" clearable></el-input> |
| | | </div> |
| | | |
| | | <el-form-item prop="areaDivideIds" label-width="0"> |
| | | <el-table class="command-table" ref="areaTableRef" |
| | | :data="areaList.filter(item => item.areaName.includes(searchName))" row-key="id" |
| | | @selection-change="handleAreaSelectionChange"> |
| | | <el-table |
| | | class="command-table" |
| | | ref="areaTableRef" |
| | | :data="areaList.filter(item => item.areaName.includes(searchName))" |
| | | row-key="id" |
| | | @selection-change="handleAreaSelectionChange" |
| | | > |
| | | <el-table-column type="selection" width="55" :reserve-selection="true" /> |
| | | <el-table-column prop="areaName" label="区域名称" /> |
| | | <el-table-column prop="areaType" label="区域类型"> |
| | | <el-table-column prop="areaName" show-overflow-tooltip label="区域名称" /> |
| | | <el-table-column prop="areaTypeKeys" show-overflow-tooltip label="区域类型"> |
| | | <template v-slot="{ row }"> |
| | | {{ getDictLabel(row.areaType, dictObj.areaType) }} |
| | | {{ getDictLabel(row.areaTypeKeys, dictObj.areaType) }} |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | |
| | | </el-form> |
| | | |
| | | <div class="footer"> |
| | | <el-button color="#2B2B4C" @click="handleCancel">{{ readonly ? '关闭' : '取消' }}</el-button> |
| | | <el-button color="#284FE3" v-if="!readonly" type="primary" :loading="submitting" |
| | | :disabled="submitting" @click="handleSubmit"> |
| | | <el-button v-if="dialogMode != 'view'" color="#2B2B4C" @click="handleCancel"> |
| | | {{ readonly ? '关闭' : '取消' }} |
| | | </el-button> |
| | | <el-button |
| | | color="#284FE3" |
| | | v-if="!readonly" |
| | | type="primary" |
| | | :loading="submitting" |
| | | :disabled="submitting" |
| | | @click="handleSubmit" |
| | | > |
| | | 确定 |
| | | </el-button> |
| | | </div> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { computed, inject, nextTick, onMounted, ref, watch } from 'vue' |
| | | import { Close } from '@element-plus/icons-vue' |
| | | |
| | | import { computed, inject, nextTick, ref, watch } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { fwDefenseSceneDetailApi, fwDefenseSceneSubmitApi } from './sceneConfigApi' |
| | | import { fieldRules, geomAnalysis, getDictLabel } from '@ztzf/utils' |
| | | import { fieldRules, getDictLabel } from '@ztzf/utils' |
| | | import CommonCesiumMap from '@/components/map-container/common-cesium-map.vue' |
| | | import * as Cesium from 'cesium' |
| | | import { fwAreaDivideListApi } from '../partition/partitionApi' |
| | | import { DrawPolygon } from '@/utils/cesium/DrawPolygon' |
| | | import { fwAreaDivideDetailApi, fwAreaDivideListApi } from '../partition/partitionApi' |
| | | import { |
| | | addBufferRadiusLabelEntity, |
| | | buildEllipsePositions, |
| | | } from '@/utils/cesium/shapeTools' |
| | | import { cartesian3Convert } from '@/utils/cesium/mapUtil' |
| | | import { saveOperationLog } from '@ztzf/apis' |
| | | import { useRoute } from 'vue-router' |
| | | import { AREA_TYPE_STYLE_MAP, BUFFER_LEVEL_STYLES, DEFAULT_AREA_STYLE } from '@ztzf/constants' |
| | | |
| | | const initForm = () => ({ |
| | | sceneName: '', // 场景名称 |
| | | sceneName: '', // 配置名称 |
| | | sceneType: '', // 场景类型 |
| | | defenseLeader: '', // 负责人 |
| | | leaderPhone: '', // 负责人电话 |
| | | deviceMode: '', // 设备模式 |
| | | areaDivideIds: '', // 关联区域ID |
| | | areaCount: 0, // 区域数量 |
| | | defenseArea: 0, // 防控面积 |
| | | latitude: null, // 指挥点纬度 |
| | | longitude: null, // 指挥点经度 |
| | | }) |
| | | |
| | | const emit = defineEmits(['success']) |
| | | const formRef = ref(null) // 表单实例 |
| | | const formData = ref(initForm()) // 表单数据 |
| | | const visible = defineModel() // 弹框显隐 |
| | | const dialogMode = ref('add') // 弹框模式 |
| | | const dialogMode = ref() // 弹框模式 |
| | | const submitting = ref(false) // 提交中 |
| | | const readonly = computed(() => dialogMode.value === 'view') |
| | | const titleEnum = ref({ edit: '编辑', view: '查看', add: '新增' }) |
| | |
| | | const selectedAreaRows = ref([]) //选中列表 |
| | | const dictObj = inject('dictObj') |
| | | const mapRef = ref(null) |
| | | const route = useRoute() |
| | | let viewer |
| | | let redPointEntity |
| | | let leftClickBound = false |
| | | let areaDisplaySource |
| | | |
| | | const rules = { |
| | | sceneName: fieldRules(true, 50), |
| | | sceneType: fieldRules(true), |
| | | defenseLeader: fieldRules(true, 50), |
| | | leaderPhone: fieldRules(true, 50), |
| | | deviceMode: fieldRules(true), |
| | | longitude: fieldRules(true), |
| | | areaDivideIds: fieldRules(true), |
| | | areaDivideIds: fieldRules(false), |
| | | } |
| | | |
| | | // 关闭弹框 |
| | | function handleCancel () { |
| | | function handleCancel() { |
| | | visible.value = false |
| | | } |
| | | |
| | | // 提交新增/编辑 |
| | | async function handleSubmit () { |
| | | async function handleSubmit() { |
| | | const isValid = await formRef.value?.validate().catch(() => false) |
| | | if (!isValid) return |
| | | submitting.value = true |
| | |
| | | const ids = selectedAreaRows.value.map(item => item.id) |
| | | formData.value.areaDivideIds = ids.join(',') |
| | | formData.value.areaCount = ids.length |
| | | formData.value.defenseArea = calcDefenseArea(selectedAreaRows.value) |
| | | await fwDefenseSceneSubmitApi(formData.value) |
| | | saveOperationLog({ |
| | | requestUri: route.path, |
| | | title: `${route.name || '场景配置管理'}-${dialogMode.value === 'add' ? '新增' : '编辑'}`, |
| | | type: 1, |
| | | }) |
| | | ElMessage.success(dialogMode.value === 'add' ? '新增成功' : '更新成功') |
| | | visible.value = false |
| | | emit('success') |
| | |
| | | } |
| | | |
| | | // 加载详情 |
| | | async function loadDetail () { |
| | | async function loadDetail() { |
| | | if (!formData.value.id) return |
| | | const res = await fwDefenseSceneDetailApi({ id: formData.value.id }) |
| | | formData.value = res?.data?.data ?? initForm() |
| | | } |
| | | |
| | | // 获取区域列表 |
| | | async function getAreaList () { |
| | | async function getAreaList() { |
| | | if (areaList.value.length) return |
| | | const res = await fwAreaDivideListApi({ filterSelected: 1, sceneId: formData.value.id }) |
| | | areaList.value = res?.data?.data ?? [] |
| | | } |
| | | |
| | | // 关联区域变更 |
| | | function handleAreaSelectionChange (rows) { |
| | | selectedAreaRows.value = rows |
| | | formData.value.areaDivideIds = rows.map(item => item.id) |
| | | formData.value.areaCount = rows.length |
| | | formData.value.defenseArea = calcDefenseArea(rows) |
| | | async function handleAreaSelectionChange(rows) { |
| | | const selectedRows = await ensureAreaExtList(rows) |
| | | selectedAreaRows.value = selectedRows |
| | | const ids = selectedRows.map(item => item.id) |
| | | formData.value.areaDivideIds = ids.join(',') |
| | | formData.value.areaCount = ids.length |
| | | } |
| | | |
| | | // 渲染面 |
| | | function renderingSurface () { |
| | | geometricSource && geometricSource.entities.removeAll() |
| | | selectedAreaRows.value.forEach(item => { |
| | | if (item.geom) { |
| | | const pointList = geomAnalysis(item.geom) |
| | | const result = pointList.map(item => [item.longitude, item.latitude]).flat() |
| | | geometricSource.entities?.add({ |
| | | customType: 'control_group', |
| | | position: Cesium.Cartesian3.fromDegrees(result[0], result[1]), |
| | | function ensureAreaDisplaySource() { |
| | | if (!viewer) return null |
| | | if (!areaDisplaySource) { |
| | | areaDisplaySource = new Cesium.CustomDataSource('scene-area-display') |
| | | viewer.dataSources.add(areaDisplaySource) |
| | | } |
| | | return areaDisplaySource |
| | | } |
| | | |
| | | function clearAreaDisplay() { |
| | | if (!areaDisplaySource) return |
| | | areaDisplaySource.entities.removeAll() |
| | | } |
| | | |
| | | function normalizeShapePoint(point) { |
| | | if (!point) return null |
| | | const lng = point?.lng ?? point?.longitude |
| | | const lat = point?.lat ?? point?.latitude |
| | | const height = Number.isFinite(Number(point?.height)) ? Number(point.height) : 0 |
| | | if (!Number.isFinite(Number(lng)) || !Number.isFinite(Number(lat))) return null |
| | | return { lng: Number(lng), lat: Number(lat), height } |
| | | } |
| | | |
| | | function resolveLngLatPoint(point) { |
| | | if (!point) return null |
| | | const lng = point?.lng ?? point?.longitude |
| | | const lat = point?.lat ?? point?.latitude |
| | | if (Number.isFinite(Number(lng)) && Number.isFinite(Number(lat))) { |
| | | return { |
| | | lng: Number(lng), |
| | | lat: Number(lat), |
| | | height: Number.isFinite(Number(point?.height)) ? Number(point.height) : 0, |
| | | } |
| | | } |
| | | if (!viewer || !Number.isFinite(point?.x) || !Number.isFinite(point?.y) || !Number.isFinite(point?.z)) { |
| | | return null |
| | | } |
| | | const val = cartesian3Convert(point, viewer) |
| | | return { |
| | | lng: val.longitude, |
| | | lat: val.latitude, |
| | | height: Number.isFinite(val.height) ? val.height : 0, |
| | | } |
| | | } |
| | | |
| | | function buildShapePositions(points = []) { |
| | | const normalized = points.map(normalizeShapePoint).filter(Boolean) |
| | | return normalized.map(point => Cesium.Cartesian3.fromDegrees(point.lng, point.lat, point.height)) |
| | | } |
| | | |
| | | function getShapeDisplayPoints(shape) { |
| | | if (Array.isArray(shape?.displayPoints) && shape.displayPoints.length) { |
| | | return shape.displayPoints |
| | | } |
| | | return shape?.points || [] |
| | | } |
| | | |
| | | function getAreaTypeStyle(areaType) { |
| | | return AREA_TYPE_STYLE_MAP?.[String(areaType)] || DEFAULT_AREA_STYLE |
| | | } |
| | | |
| | | function resolveControlPoints(meta, drawType) { |
| | | if (!meta) return [] |
| | | if (Array.isArray(meta.controlPoints) && meta.controlPoints.length) { |
| | | return meta.controlPoints.map(resolveLngLatPoint).filter(Boolean) |
| | | } |
| | | if (drawType === 'buffer') { |
| | | return [resolveLngLatPoint(meta.center)].filter(Boolean) |
| | | } |
| | | if (drawType === 'ellipse') { |
| | | return [meta.center, meta.majorPoint, meta.minorPoint].map(resolveLngLatPoint).filter(Boolean) |
| | | } |
| | | return [] |
| | | } |
| | | |
| | | function parseGeomJson(geomJson) { |
| | | if (!geomJson) return null |
| | | if (typeof geomJson === 'object') return geomJson |
| | | if (typeof geomJson !== 'string') return null |
| | | const trimmed = geomJson.trim() |
| | | if (!trimmed) return null |
| | | try { |
| | | return JSON.parse(trimmed) |
| | | } catch (error) { |
| | | return null |
| | | } |
| | | } |
| | | |
| | | function resolveAreaShapes(area) { |
| | | const extList = Array.isArray(area?.fwAreaDivideExtList) ? area.fwAreaDivideExtList : [] |
| | | if (!extList.length) return [] |
| | | return extList |
| | | .map((item, index) => { |
| | | const isShapePayload = item?.drawType || item?.points |
| | | if (isShapePayload) { |
| | | return { |
| | | id: item?.id || `shape_${Date.now()}_${index}_${Math.random().toString(16).slice(2, 6)}`, |
| | | drawType: item?.drawType ?? 'polygon', |
| | | areaType: item?.areaType ?? item?.areaTypeKey ?? '', |
| | | points: Array.isArray(item?.points) ? item.points : [], |
| | | displayPoints: Array.isArray(item?.displayPoints) ? item.displayPoints : null, |
| | | meta: item?.meta ?? null, |
| | | } |
| | | } |
| | | const parsed = parseGeomJson(item?.geomJson) |
| | | if (!parsed) return null |
| | | return { |
| | | id: parsed?.id || `shape_${Date.now()}_${index}_${Math.random().toString(16).slice(2, 6)}`, |
| | | drawType: parsed?.drawType ?? 'polygon', |
| | | areaType: item?.areaTypeKey ?? parsed?.areaType ?? '', |
| | | points: Array.isArray(parsed?.points) ? parsed.points : [], |
| | | displayPoints: Array.isArray(parsed?.displayPoints) ? parsed.displayPoints : null, |
| | | meta: parsed?.meta ?? null, |
| | | } |
| | | }) |
| | | .filter(Boolean) |
| | | } |
| | | |
| | | function renderSelectedAreas() { |
| | | if (!visible.value) { |
| | | clearAreaDisplay() |
| | | return |
| | | } |
| | | if (!viewer) initMap() |
| | | const dataSource = ensureAreaDisplaySource() |
| | | if (!dataSource) return |
| | | dataSource.entities.removeAll() |
| | | selectedAreaRows.value.forEach(area => { |
| | | const shapes = resolveAreaShapes(area) |
| | | shapes.forEach(shape => { |
| | | if (shape.drawType === 'buffer' && shape.meta?.bufferRadii?.length && shape.meta?.center) { |
| | | const center = shape.meta.center |
| | | const centerCartesian = Cesium.Cartesian3.fromDegrees(center.lng, center.lat, center.height || 0) |
| | | const radii = shape.meta.bufferRadii |
| | | .map(radius => Number(radius)) |
| | | .filter(radius => Number.isFinite(radius) && radius > 0) |
| | | radii.forEach((radius, index) => { |
| | | const style = BUFFER_LEVEL_STYLES[index] || BUFFER_LEVEL_STYLES[BUFFER_LEVEL_STYLES.length - 1] |
| | | dataSource.entities.add({ |
| | | name: 'scene-area-display', |
| | | customData: { drawType: shape.drawType, level: index + 1 }, |
| | | position: centerCartesian, |
| | | ellipse: { |
| | | semiMajorAxis: radius, |
| | | semiMinorAxis: radius, |
| | | material: style.fill, |
| | | outline: false, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | | }) |
| | | const positions = buildEllipsePositions(centerCartesian, radius, radius) |
| | | dataSource.entities.add({ |
| | | name: 'scene-area-display', |
| | | customData: { drawType: shape.drawType, level: index + 1, outline: true }, |
| | | polyline: { |
| | | positions: positions.length ? [...positions, positions[0]] : positions, |
| | | clampToGround: true, |
| | | width: 2, |
| | | material: style.outline, |
| | | }, |
| | | }) |
| | | addBufferRadiusLabelEntity(dataSource, centerCartesian, radius, { |
| | | name: 'scene-area-display', |
| | | customData: { drawType: 'buffer', label: 'radius' }, |
| | | }) |
| | | }) |
| | | return |
| | | } |
| | | const positions = buildShapePositions(getShapeDisplayPoints(shape)) |
| | | if (positions.length < 3) return |
| | | const style = getAreaTypeStyle(shape.areaType) |
| | | dataSource.entities.add({ |
| | | name: 'scene-area-display', |
| | | customData: { drawType: shape.drawType }, |
| | | polygon: { |
| | | hierarchy: new Cesium.PolygonHierarchy(positions), |
| | | material: style.fill, |
| | | outline: false, |
| | | heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, |
| | | }, |
| | | polyline: { |
| | | positions: Cesium.Cartesian3.fromDegreesArray(result), |
| | | positions: positions.length ? [...positions, positions[0]] : positions, |
| | | clampToGround: true, |
| | | width: 3, |
| | | material: Cesium.Color.RED, |
| | | width: 2, |
| | | material: style.outline, |
| | | }, |
| | | }) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | watch(() => selectedAreaRows.value, renderingSurface) |
| | | function pushRadiusBoundingPoints(positions, center, radius) { |
| | | if (!center || !Number.isFinite(Number(radius)) || radius <= 0) return |
| | | const resolved = resolveLngLatPoint(center) || {} |
| | | const lng = Number(resolved.lng ?? resolved.longitude) |
| | | const lat = Number(resolved.lat ?? resolved.latitude) |
| | | if (!Number.isFinite(lng) || !Number.isFinite(lat)) return |
| | | const baseLat = Cesium.Math.toRadians(lat) |
| | | const earthRadius = Cesium.Ellipsoid.WGS84.maximumRadius |
| | | const deltaLat = radius / earthRadius |
| | | const deltaLng = radius / (earthRadius * Math.max(Math.cos(baseLat), 0.000001)) |
| | | const points = [ |
| | | { lng: Cesium.Math.toDegrees(Cesium.Math.toRadians(lng) + deltaLng), lat }, |
| | | { lng: Cesium.Math.toDegrees(Cesium.Math.toRadians(lng) - deltaLng), lat }, |
| | | { lng, lat: Cesium.Math.toDegrees(baseLat + deltaLat) }, |
| | | { lng, lat: Cesium.Math.toDegrees(baseLat - deltaLat) }, |
| | | ] |
| | | points.forEach(point => { |
| | | positions.push(Cesium.Cartesian3.fromDegrees(point.lng, point.lat, resolved.height || 0)) |
| | | }) |
| | | } |
| | | |
| | | function calcDefenseArea (rows) { |
| | | const total = rows.reduce((sum, item) => sum + (Number(item.areaSize) || 0), 0) |
| | | return _.round(total, 2) |
| | | function collectSelectedAreaPositions() { |
| | | const positions = [] |
| | | if (!viewer || !selectedAreaRows.value.length) return positions |
| | | selectedAreaRows.value.forEach(area => { |
| | | const shapes = resolveAreaShapes(area) |
| | | shapes.forEach(shape => { |
| | | let points = getShapeDisplayPoints(shape) |
| | | if (!Array.isArray(points) || !points.length) { |
| | | points = resolveControlPoints(shape?.meta, shape?.drawType) |
| | | } |
| | | if (Array.isArray(points) && points.length) { |
| | | points.forEach(point => { |
| | | const resolved = resolveLngLatPoint(point) |
| | | const normalized = normalizeShapePoint(resolved) |
| | | if (!normalized) return |
| | | positions.push( |
| | | Cesium.Cartesian3.fromDegrees(normalized.lng, normalized.lat, normalized.height) |
| | | ) |
| | | }) |
| | | } |
| | | if (shape?.drawType === 'buffer' && shape?.meta?.center && Array.isArray(shape?.meta?.bufferRadii)) { |
| | | const maxRadius = Math.max(...shape.meta.bufferRadii.filter(item => Number.isFinite(item))) |
| | | pushRadiusBoundingPoints(positions, shape.meta.center, maxRadius) |
| | | } |
| | | if (shape?.drawType === 'ellipse' && shape?.meta?.center) { |
| | | const major = Number(shape?.meta?.semiMajor) |
| | | const minor = Number(shape?.meta?.semiMinor) |
| | | const radius = Number.isFinite(major) && Number.isFinite(minor) ? Math.max(major, minor) : null |
| | | pushRadiusBoundingPoints(positions, shape.meta.center, radius) |
| | | } |
| | | }) |
| | | }) |
| | | return positions |
| | | } |
| | | |
| | | function fitViewToSelectedAreas() { |
| | | if (!viewer || !selectedAreaRows.value.length) return |
| | | const positions = collectSelectedAreaPositions() |
| | | if (positions.length < 2) return |
| | | const boundingSphere = Cesium.BoundingSphere.fromPoints(positions) |
| | | const range = Math.max(boundingSphere.radius * 2.4, 200) |
| | | viewer.camera.flyToBoundingSphere(boundingSphere, { |
| | | duration: 0, |
| | | offset: new Cesium.HeadingPitchRange(viewer.camera.heading, Cesium.Math.toRadians(-90), range), |
| | | }) |
| | | } |
| | | |
| | | watch(() => selectedAreaRows.value, renderSelectedAreas) |
| | | watch( |
| | | () => visible.value, |
| | | val => { |
| | | if (!val) clearAreaDisplay() |
| | | } |
| | | ) |
| | | |
| | | async function ensureAreaExtList(rows) { |
| | | const missingRows = rows.filter(row => row?.id && !Array.isArray(row?.fwAreaDivideExtList)) |
| | | if (!missingRows.length) return rows |
| | | const detailList = await Promise.all( |
| | | missingRows.map(row => |
| | | fwAreaDivideDetailApi({ id: row.id }) |
| | | .then(res => res?.data?.data) |
| | | .catch(() => null) |
| | | ) |
| | | ) |
| | | const detailMap = new Map(detailList.filter(Boolean).map(item => [String(item.id), item])) |
| | | if (!detailMap.size) return rows |
| | | areaList.value = areaList.value.map(item => { |
| | | const detail = detailMap.get(String(item.id)) |
| | | return detail ? { ...item, ...detail } : item |
| | | }) |
| | | return rows.map(item => { |
| | | const detail = detailMap.get(String(item.id)) |
| | | return detail ? { ...item, ...detail } : item |
| | | }) |
| | | } |
| | | |
| | | // 同步关联区域 |
| | | function syncAreaSelection () { |
| | | async function syncAreaSelection() { |
| | | if (!areaTableRef.value) return |
| | | areaTableRef.value.clearSelection() |
| | | const rows = [] |
| | | const arr = formData.value.areaDivideIds.split(',') |
| | | const areaDivideIds = formData.value.areaDivideIds |
| | | const arr = Array.isArray(areaDivideIds) |
| | | ? areaDivideIds.map(item => String(item)) |
| | | : String(areaDivideIds || '') |
| | | .split(',') |
| | | .filter(Boolean) |
| | | areaList.value.forEach(row => { |
| | | if (arr.includes(row.id)) { |
| | | if (arr.includes(String(row.id))) { |
| | | areaTableRef.value.toggleRowSelection(row, true) |
| | | rows.push(row) |
| | | } |
| | | }) |
| | | selectedAreaRows.value = rows |
| | | if (!rows.length) return |
| | | formData.value.areaCount = rows.length |
| | | formData.value.defenseArea = calcDefenseArea(rows) |
| | | const ensuredRows = await ensureAreaExtList(rows) |
| | | selectedAreaRows.value = ensuredRows |
| | | if (!ensuredRows.length) return |
| | | formData.value.areaCount = ensuredRows.length |
| | | } |
| | | |
| | | function formatDefenseArea (value) { |
| | | if (value == null || value === '') return '' |
| | | return `${value}k㎡` |
| | | } |
| | | |
| | | // 格式化指挥点位置 |
| | | function formatLocation (row) { |
| | | if (row?.longitude == null || row?.latitude == null) return '' |
| | | return `${_.round(row.longitude, 6)}, ${_.round(row.latitude, 6)}` |
| | | } |
| | | |
| | | let geometricSource |
| | | // 初始化地图实例 |
| | | function initMap () { |
| | | function initMap() { |
| | | if (viewer) return |
| | | const map = mapRef.value?.getMap() |
| | | if (!map?.viewer) return |
| | | viewer = map.viewer |
| | | if (!readonly.value && !leftClickBound) { |
| | | map.publicCesium?.addLeftClickEvent?.(null, LeftClickEvent) |
| | | leftClickBound = true |
| | | } |
| | | if (!geometricSource) { |
| | | geometricSource = new Cesium.CustomDataSource('geometricSource') |
| | | viewer.dataSources.add(geometricSource) |
| | | } |
| | | } |
| | | |
| | | function LeftClickEvent (click) { |
| | | const pos = click.position |
| | | const cartesian3 = viewer.camera.pickEllipsoid(pos, viewer.scene.globe.ellipsoid) |
| | | if (!cartesian3) return |
| | | const carto = Cesium.Cartographic.fromCartesian(cartesian3) |
| | | const longitude = Cesium.Math.toDegrees(carto.longitude) |
| | | const latitude = Cesium.Math.toDegrees(carto.latitude) |
| | | formData.value.longitude = _.round(longitude, 6) |
| | | formData.value.latitude = _.round(latitude, 6) |
| | | setMapPoint(formData.value.longitude, formData.value.latitude) |
| | | } |
| | | |
| | | function setMapPoint (longitude, latitude) { |
| | | if (!viewer || longitude == null || latitude == null) return |
| | | if (!redPointEntity) { |
| | | redPointEntity = viewer.entities.add({ |
| | | position: Cesium.Cartesian3.fromDegrees(longitude, latitude), |
| | | point: { |
| | | color: Cesium.Color.RED, |
| | | pixelSize: 10, |
| | | }, |
| | | label: { |
| | | text: `${longitude.toFixed(6)}, ${latitude.toFixed(6)}`, |
| | | font: '14px', |
| | | fillColor: Cesium.Color.WHITE, |
| | | backgroundColor: Cesium.Color.BLACK.withAlpha(0.45), |
| | | backgroundPadding: new Cesium.Cartesian2(5, 5), |
| | | pixelOffset: new Cesium.Cartesian2(0, -20), |
| | | showBackground: true, |
| | | style: Cesium.LabelStyle.FILL_AND_OUTLINE, |
| | | horizontalOrigin: Cesium.HorizontalOrigin.CENTER, |
| | | verticalOrigin: Cesium.VerticalOrigin.CENTER, |
| | | outlineWidth: 1, |
| | | outlineColor: Cesium.Color.WHITE, |
| | | eyeOffset: new Cesium.Cartesian3(0, 0, -20), |
| | | }, |
| | | }) |
| | | } else { |
| | | redPointEntity.position = Cesium.Cartesian3.fromDegrees(longitude, latitude) |
| | | redPointEntity.label.text = `${longitude.toFixed(6)}, ${latitude.toFixed(6)}` |
| | | } |
| | | } |
| | | |
| | | // 打开弹框 |
| | | async function open ({ mode, row } = {}) { |
| | | async function open({ mode, row } = {}) { |
| | | dialogMode.value = mode || 'add' |
| | | formData.value = dialogMode.value === 'add' ? initForm() : row |
| | | selectedAreaRows.value = [] |
| | | redPointEntity = null |
| | | await nextTick() |
| | | initMap() |
| | | await getAreaList() |
| | | if (dialogMode.value !== 'add') { |
| | | if (dialogMode.value === 'add') { |
| | | mapRef.value?.zoomToAdminBoundary?.() |
| | | } else { |
| | | await loadDetail() |
| | | } |
| | | await nextTick() |
| | | syncAreaSelection() |
| | | setMapPoint(formData.value.longitude, formData.value.latitude) |
| | | await syncAreaSelection() |
| | | await nextTick() |
| | | fitViewToSelectedAreas() |
| | | } |
| | | |
| | | onMounted(() => { |
| | | getAreaList() |
| | | }) |
| | | |
| | | defineExpose({ |
| | | open, |
| | | }) |