wujingjing
2025-02-10 e50196bff10f0196307b2567ed6c0829eadd8ff6
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
<template>
    <div class="layer-control bg-white h-full flex-col" style="display: flex">
        <div class="bg-white rounded flex-0">
            <div class="header flex-items-center pb-1.5" style="border-bottom: 1px solid black">
                <div class="flex-items-center">
                    <span class="ywifont ywicon-guanbi cursor-pointer mr-1.5" @click="closeClick"></span>
                    <span class="text-lg font-bold">图层</span>
                </div>
            </div>
        </div>
        <div class="content rounded-lg flex-auto overflow-y-auto">
            <el-tree
                class="w-full"
                :data="layerInfo"
                :props="defaultProps"
                show-checkbox
                node-key="id"
                default-expand-all
                ref="checkTreeRef"
                @check="handleCheck"
                @node-click="handleNodeClick"
            >
                <template #default="{ node, data }">
                    <span>{{ node.label }}</span>
                </template>
            </el-tree>
        </div>
    </div>
</template>
 
<script setup lang="ts" name="LayerControl">
import { computed, ref, watch, watchEffect } from 'vue';
import type { OLMap } from '/@/model/map/OLMap';
import { ElTree } from 'element-plus';
import { travelTree } from '/@/utils/util';
 
const props = defineProps(['olMap']);
const emit = defineEmits(['close']);
 
const defaultProps = {
    children: 'children',
    label: 'title',
};
const closeClick = () => {
    emit('close');
};
const checkTreeRef = ref<InstanceType<typeof ElTree>>();
 
let isHumanCheckTrigger = false;
const handleCheck = (data: any, node: any) => {
    const checkedKeys = node.checkedKeys;
    isHumanCheckTrigger = true;
    travelTree(layerInfo.value, (layer) => {
        if (layer.type === 'layer' || layer.type === 'equip') {
            const id = layer.id;
            if (!checkedKeys.includes(id)) {
                layer.isVisible = false;
            } else {
                layer.isVisible = true;
            }
        }
    });
};
 
const handleNodeClick = () => {};
const layerInfo = computed(() => {
    
    
    const info =(props.olMap as OLMap).layerInfo.value
    return info;
    const result = info.concat([
        {
            id: 'overlays',
            title: '监测设备',
            children: [],
 
            type: 'equip',
        },
    ])
    return result;
 
});
 
watch(
    () => layerInfo.value,
    (val) => {
        if (isHumanCheckTrigger) {
            isHumanCheckTrigger = false;
            return;
        }
        const keys = [];
        travelTree(val, (item) => {
            if (item.type === 'layer'|| item.type === 'equip') {
                if (item.isVisible) {
                    keys.push(item.id);
                }
            }
        });
        // const keys = val.filter((item) => item.isVisible).map((item) => item.id);
        checkTreeRef.value?.setCheckedKeys(keys);
    }
);
</script>
<style scoped lang="scss"></style>