fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
  <mars-pannel :visible="true" right="10" top="10" width="300">
    <div v-show="!isShow">
      <div class="f-mb">
        <a-space>
          <span>分析区域</span>
          <mars-button @click="btnDrawExtent">绘制矩形</mars-button>
          <mars-button @click="btnDraw">绘制多边形</mars-button>
        </a-space>
      </div>
 
      <div class="f-mb">
        <a-space>
          <span class="mars-pannel-item-label">最低海拔</span>
          <mars-input-number v-model:value="formState.minHeight" :step="1" />
          <span>(米)</span>
        </a-space>
      </div>
 
      <div class="f-mb">
        <a-space>
          <span class="mars-pannel-item-label">最高海拔</span>
          <mars-input-number v-model:value="formState.maxHeight" :step="1" />
          <span>(米)</span>
        </a-space>
      </div>
 
      <div class="f-mb">
        <a-space>
          <span class="mars-pannel-item-label">淹没速度</span>
          <mars-input-number v-model:value="formState.speed" :step="1" />
          <div class="miles-second">(米/秒)</div>
        </a-space>
      </div>
 
      <div class="f-tac">
        <mars-button @click="begin">开始分析</mars-button>
      </div>
    </div>
 
    <div v-show="isShow">
      <div class="f-mb">
        <a-space>
          <span class="mars-pannel-item-label">高度选择</span>
          <a-slider
            tooltipPlacement="bottom"
            v-model:value="formState.height"
            @change="onChangeHeight()"
            :min="formState.minHeight"
            :max="formState.maxHeight"
            :step="1"
          />
        </a-space>
      </div>
 
      <div class="f-mb">
        <span>当前高度:{{ formState.height }}</span>
      </div>
 
      <div class="f-tac">
        <a-space>
          <mars-button @click="startPlay">{{ isStart ? "暂停" : "播放" }}</mars-button>
          <mars-button @click="goBack">返回</mars-button>
        </a-space>
      </div>
    </div>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { reactive, ref } from "vue"
import type { UnwrapRef } from "vue"
import * as mapWork from "./map.js"
 
interface FormState {
  minHeight: any
  maxHeight: any
  speed: number
  height: number
}
 
const formState: UnwrapRef<FormState> = reactive({
  minHeight: 0,
  maxHeight: 0,
  speed: 10,
  height: 0
})
 
const isStart = ref(true)
const isShow = ref(false)
 
// 监听到高度发生变化
mapWork.eventTarget.on("heightChange", (e: any) => {
  formState.height = Math.ceil(e.height)
})
// 高度改变
const onChangeHeight = () => {
  mapWork.onChangeHeight(formState.height)
}
 
// 默认自动播放
const startPlay = () => {
  isStart.value = !isStart.value
  mapWork.startPlay()
}
 
const goBack = () => {
  mapWork.clearDraw()
 
  formState.minHeight = 0
  formState.maxHeight = 0
 
  isShow.value = false
  isStart.value = true
}
 
// 添加矩形
const btnDrawExtent = () => {
  mapWork.btnDrawExtent((min: any, max: any) => {
    formState.minHeight = Math.ceil(min)
    formState.maxHeight = Math.ceil(max)
  })
}
// 添加多边形
const btnDraw = () => {
  mapWork.btnDraw((min: any, max: any) => {
    formState.minHeight = Math.ceil(min)
    formState.maxHeight = Math.ceil(max)
  })
}
 
// 开始淹没
const begin = () => {
  mapWork.begin(formState, () => {
    isShow.value = true
  })
}
</script>
<style scoped lang="less">
.ant-slider {
  width: 140px;
}
.miles-second {
  width: 120px !important;
}
</style>