AreaPlan.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="float-panel" :class="{ 'move-tool-spread': layoutStore.toolSpread === 'ky' }">
  3. <div class="panel-title">空域划设</div>
  4. <el-form
  5. ref="formRef"
  6. class="p-form mt-7"
  7. :model="form"
  8. :rules="rules"
  9. label-position="left"
  10. size="large"
  11. hide-required-asterisk>
  12. <el-form-item label="空域名称" prop="name">
  13. <el-input v-model="form.name" clearable></el-input>
  14. </el-form-item>
  15. <el-form-item label="高度" prop="height">
  16. <el-input v-model="form.height" type="number">
  17. <template #suffix>
  18. <span>米</span>
  19. </template>
  20. </el-input>
  21. </el-form-item>
  22. <el-form-item label="绘制">
  23. <el-button class="btn-secondary" @click="handleDraw">绘制</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <div class="text-center">
  27. <el-button class="btn-main" :disabled="!hasDraw" @click="handleCalc">开始计算</el-button>
  28. <el-button class="btn-main" @click="handleClear">清空</el-button>
  29. </div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import useLayoutStore from '@/store/layout'
  34. import { useMapStore } from '@/store/map'
  35. import { DrawPolygon, InspectCube, clearDraw, showShapes } from '@/utils/map/addLayer'
  36. import { wait } from '@/utils/tools'
  37. import { ref, watch, onBeforeUnmount } from 'vue'
  38. import { hexToRgb } from '@/utils/tools'
  39. const mapStore = useMapStore()
  40. const layoutStore = ref(useLayoutStore())
  41. const form = ref({
  42. name: '',
  43. drawType: 'polygon',
  44. height: '100',
  45. })
  46. const rules = {
  47. name: [{ required: true, message: '请输入空域名称', trigger: 'none' }],
  48. }
  49. const hasDraw = ref(false)
  50. let drawGeometry
  51. watch(
  52. () => mapStore.draw_geometry,
  53. (val) => {
  54. console.log('draw_geometry:', val)
  55. drawGeometry = val
  56. hasDraw.value = true
  57. },
  58. { deep: true }
  59. )
  60. watch(
  61. () => mapStore.cubeResult,
  62. (val) => {
  63. console.log('cubeResult', val)
  64. if (val.data == 'error') {
  65. ElMessage({ type: 'error', message: '核查结果为空' })
  66. }
  67. layoutStore.value.toggleGlobalLoading(false)
  68. },
  69. { deep: true }
  70. )
  71. async function handleDraw() {
  72. handleInspect(false)
  73. if (hasDraw.value) {
  74. showShapes({
  75. id: 'kyhs_drew_non_editable',
  76. data: null,
  77. })
  78. await wait(500)
  79. }
  80. // 处理绘制
  81. DrawPolygon({ hasZ: true })
  82. }
  83. function getShapeInfo() {
  84. return {
  85. height: +form.value.height,
  86. rings: drawGeometry.rings,
  87. level: '15',
  88. }
  89. }
  90. function handleInspect(show = true) {
  91. const shape = show ? getShapeInfo() : {}
  92. InspectCube({
  93. type: 'polygon',
  94. id: 'inspect_kyhs',
  95. show,
  96. shape,
  97. })
  98. }
  99. const formRef = ref(null)
  100. function handleCalc() {
  101. formRef.value.validate((valid) => {
  102. if (valid) {
  103. layoutStore.value.toggleGlobalLoading('正在分析...')
  104. clearDraw()
  105. showShapes({
  106. id: 'kyhs_drew_non_editable',
  107. data: [
  108. {
  109. type: 'polygon',
  110. shape: {
  111. ...getShapeInfo(),
  112. color: hexToRgb('#00FF00', 0.5),
  113. },
  114. },
  115. ],
  116. })
  117. handleInspect(true)
  118. }
  119. })
  120. }
  121. function handleClear() {
  122. clearDraw()
  123. handleInspect(false)
  124. showShapes({
  125. id: 'kyhs_drew_non_editable',
  126. data: null,
  127. })
  128. }
  129. onBeforeUnmount(() => {
  130. handleClear()
  131. })
  132. </script>
  133. <style lang="scss" scoped>
  134. :deep(.p-form) {
  135. .el-form-item__label {
  136. width: 100px;
  137. }
  138. }
  139. </style>