guonan
2025-06-10 2280e8be717608bb36c3cf921f129db24349396d
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<template>
  <div class="district">
    <div class="left-top">
      <span>监测位置</span>
    </div>
 
    <div class="left-content district-content">
      <div style="margin-left: 5px; margin-bottom: 5px">
        <span style="color: white">北京市:</span>
        <el-select
          @change="handleChange1"
          v-model="selectValue1"
          placeholder="Select"
          size="mini"
          style="width: 240px"
        >
          <el-option
            v-for="item in BJoptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div style="margin-left: 5px">
        <span style="color: white">重点沟:</span>
        <el-select
          @change="handleChange"
          v-model="selectValue"
          placeholder="Select"
          size="mini"
          style="width: 240px"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
 
      <!-- 滚动区域 -->
      <div style="overflow-y: auto; height: 91%; position: relative">
        <!-- 加载遮罩层 -->
        <div v-if="loading" class="loading-overlay">
          <div class="loading-content">
            <el-icon class="loading-icon"><Loading /></el-icon>
            <span class="loading-text">数据加载中...</span>
          </div>
        </div>
        <div
          v-else
          v-for="(item, key) in districtList"
          :key="key"
          class="district-item"
          @click="handleClick(item)"
        >
          <div class="district-item-icon"></div>
          <div class="district-item-text">{{ item.hdName }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { ref, onMounted, watch, onBeforeUnmount } from "vue";
import { createPoint,clearAllPoints } from "@/utils/map";
import { useSimStore } from "@/store/simulation";
import { initeWaterPrimitiveView } from "@/utils/water"; //相机flyTo函数,后续options列表中有对应经纬度后弃用
import { useRoute, onBeforeRouteUpdate } from "vue-router";
import { Loading } from "@element-plus/icons-vue";
 
const districtList = ref([]);
 
 
const simStore = useSimStore();
 
const route = useRoute();
 
onBeforeUnmount(() => {
  if (route.path !== "/yhgl") {
    clearAllPoints();
  }
});
const selectValue = ref("孙胡沟");
 
const selectValue1 = ref("北京市");
 
const BJoptions = ref([]);
 
const options = ref([
  {
    value: "孙胡沟",
    label: "孙胡沟",
  },
  {
    value: "鱼水洞后沟",
    label: "鱼水洞后沟",
  },
  {
    value: "于家西沟",
    label: "于家西沟",
  },
  {
    value: "北河沟",
    label: "北河沟",
  },
  {
    value: "龙泉峪村",
    label: "龙泉峪村",
  },
]);
 
const loading = ref(true); // 控制加载状态
 
function handleClick(district) {
  // 此处调用是因为GisView页面会在点击下一乡镇之前把上一个选择的区域的隐患点清除掉(如果刚好选择了孙胡沟,那么下一个点击将会清空孙胡沟的隐患点)
  initializeDevicePoints();
  const entity = viewer.entities.getById(district.hdId);
  if (entity) {
    viewer.flyTo(entity, {
      offset: {
        heading: Cesium.Math.toRadians(0),
        pitch: Cesium.Math.toRadians(-45),
        range: 4000,
      },
    });
  }
}
 
const initializeDevicePoints = async () => {
  await Promise.all(
    districtList.value.map(async (item, index) => {
      // 根据需求可增删
      item.id = item.hdId;
      item.name = item.hdName;
      item.latitude = item.lat;
      item.longitude = item.lon;
      item.showBillboard = true;
      item.type = item.disasterType;
      item.className = "district";
      await createPoint(item);
      // 打印每个设备的名称和设备类型
      // console.log(`设备名称: ${item.id}, 设备类型: ${item.name}`);
    })
  );
};
 
const filterDataByArea = async (areaName) => {
  clearAllPoints();
  if (!areaName || !simStore.DangerPoint || simStore.DangerPoint.length === 0) {
    districtList.value = [];
    return;
  }
  const filteredData = simStore.DangerPoint.filter((item) =>
    item.position?.includes(areaName)
  );
 
  if (JSON.stringify(districtList.value) !== JSON.stringify(filteredData)) {
    districtList.value = filteredData;
 
    await initializeDevicePoints();
  }
};
 
// 处理区域变化事件
const handleChange = (item) => {
  const areaName = item;
  if (!areaName) {
    ElMessage.warning("请选择一个区域");
    return;
  }
  filterDataByArea(areaName);
};
let isInitialized = false;
 
// watch(
//   () => simStore.DangerShowSwitch,
//   async (newValue, oldValue) => {
//     console.log("当前状态:", newValue);
 
//     if (newValue) {
//       if (!isInitialized) {
//         await initializeDevicePoints();
//         isInitialized = true;
//       }
//     } else {
//       clearAllPoints();
//       isInitialized = false;
//     }
//   }
// );
// 监听 simStore.DangerPoint 变化
watch(
  () => simStore.DangerPoint,
  (newVal) => {
    if (newVal && newVal.length > 0) {
      filterDataByArea(selectValue.value);
      loading.value = false; // 数据加载完成
    } else {
      clearAllPoints();
      districtList.value = [];
      loading.value = true; // 数据未准备就绪
    }
  }
);
 
onMounted(() => {
  clearAllPoints();
  // initeWaterPrimitiveView();
  // 默认先检查一遍数据
  if (simStore.DangerPoint && simStore.DangerPoint.length > 0) {
    filterDataByArea("孙胡沟");
    loading.value = false;
  } else {
    loading.value = true;
  }
});
</script>
 
<style lang="less" scoped>
.district {
  position: absolute;
  width: 345px;
  top: 100px;
  left: 30px;
  bottom: 55px;
  z-index: 99;
}
 
.district-item {
  height: 30px;
  cursor: pointer;
  margin-top: 10px;
}
 
.district-content {
  padding: 10px;
  box-sizing: border-box;
  height: calc(100% - 70px);
  position: relative;
}
 
.district-item-icon {
  background: url("@/assets/img/menu/locationicon.png") no-repeat;
  background-position: 5px 5px;
  width: 30px;
  height: 30px;
  float: left;
}
 
.district-item-text {
  color: white;
  line-height: 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  // background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  // border-radius: 4px;
}
 
.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
}
 
.loading-icon {
  font-size: 24px;
  margin-bottom: 8px;
  animation: rotating 2s linear infinite;
}
 
.loading-text {
  font-size: 14px;
}
 
@keyframes rotating {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
 
/deep/ .el-select__placeholder {
  color: white;
}
 
/deep/ .el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  color: white !important;
  background-color: rgb(38, 124, 124, 0.5);
}
</style>