| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, onMounted, watch } from "vue"; |
| | | import { createPoint } from "@/utils/map"; |
| | | import { ref, onMounted, watch, onBeforeUnmount } from "vue"; |
| | | import { createPoint, removeEntities } from "@/utils/map"; |
| | | import { useSimStore } from "@/store/simulation"; |
| | | import { initeWaterPrimitiveView } from "@/utils/water"; //相机flyTo函数,后续options列表中有对应经纬度后弃用 |
| | | |
| | | import { useRoute, onBeforeRouteUpdate } from "vue-router"; |
| | | const simStore = useSimStore(); |
| | | // onBeforeRouteUpdate((to, from, next) => { |
| | | // if (to.path !== "/yhgl") { |
| | | // handleCleanup(); |
| | | // } |
| | | // next(); |
| | | // }); |
| | | const route = useRoute(); |
| | | |
| | | onBeforeUnmount(() => { |
| | | if (route.path !== "/yhgl") { |
| | | handleCleanup(); |
| | | } |
| | | }); |
| | | const selectValue = ref("孙胡沟"); |
| | | |
| | | const options = ref([ |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | const handleCleanup = async () => { |
| | | await Promise.all( |
| | | districtList.value.map((item) => removeEntities(item.hdId)) |
| | | ); |
| | | }; |
| | | 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 = (areaName) => { |
| | | const filterDataByArea = async (areaName) => { |
| | | handleCleanup(); |
| | | if (!areaName || !simStore.DangerPoint || simStore.DangerPoint.length === 0) { |
| | | districtList.value = []; |
| | | return; |
| | | } |
| | | |
| | | districtList.value = simStore.DangerPoint.filter((item) => |
| | | const filteredData = simStore.DangerPoint.filter((item) => |
| | | item.position?.includes(areaName) |
| | | ); |
| | | |
| | | if (JSON.stringify(districtList.value) !== JSON.stringify(filteredData)) { |
| | | districtList.value = filteredData; |
| | | await initializeDevicePoints(); |
| | | } |
| | | }; |
| | | |
| | | // 处理区域变化事件 |
| | |
| | | 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 { |
| | | handleCleanup(); |
| | | isInitialized = false; |
| | | } |
| | | } |
| | | ); |
| | | // 监听 simStore.DangerPoint 变化 |
| | | watch( |
| | | () => simStore.DangerPoint, |
| | |
| | | filterDataByArea(selectValue.value); |
| | | loading.value = false; // 数据加载完成 |
| | | } else { |
| | | handleCleanup(); |
| | | districtList.value = []; |
| | | loading.value = true; // 数据未准备就绪 |
| | | } |
| | | }, |
| | | { immediate: true } |
| | | } |
| | | ); |
| | | |
| | | onMounted(() => { |
| | | handleCleanup(); |
| | | initeWaterPrimitiveView(); |
| | | // 默认先检查一遍数据 |
| | | if (simStore.DangerPoint && simStore.DangerPoint.length > 0) { |
| | |
| | | left: 0px; |
| | | right: 0px; |
| | | bottom: 10px; |
| | | background-color: rgba(43, 43, 43, 0.5); |
| | | background-color: rgba(236, 233, 233, 0.5); |
| | | /* 半透明遮罩 */ |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | |
| | | transform: rotate(360deg); |
| | | } |
| | | } |
| | | |
| | | .district { |
| | | position: absolute; |
| | | width: 345px; |
| | |
| | | cursor: pointer; |
| | | margin-top: 10px; |
| | | } |
| | | |
| | | .district-content { |
| | | padding: 10px; |
| | | box-sizing: border-box; |
| | | } |
| | | |
| | | .district-item-icon { |
| | | background: url("@/assets/img/menu/locationicon.png") no-repeat; |
| | | background-position: 5px 5px; |
| | |
| | | /deep/ .el-select__placeholder { |
| | | color: white; |
| | | } |
| | | |
| | | /deep/ .el-select-dropdown__item.hover, |
| | | .el-select-dropdown__item:hover { |
| | | color: white !important; |