suerprisePlus
2024-07-30 e5e65bb50cbfb973f98191993ab559767eff7a53
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
<template>
    <Popup ref="pop" top="20px" left="calc(100% - 600px)" :title="title" @close="close(true)" width="300px"
        @cancel="close(false)">
 
        <div class="layerBox">
            <el-tree show-checkbox :data="treeData" ref="tree" node-key="id" :default-checked-keys="defaultLayer"
                @check-change="handleCheckChange" :props="defaultProps"></el-tree>
        </div>
    </Popup>
</template>
 
<script>
import Popup from '@/components/Tool/Popup.vue';
import store from "@/store";
import mapServer from '@/assets/js/mapSdk/mapServe';
 
export default {
    name: 'layerManager',
    components: { Popup },
    computed: {
        getlayerTree() {
            return store.getters.getlayerTree
        }
    },
    data() {
        return {
            title: '图层管理',
            defaultProps: {
                children: 'children',
                label: 'cnName'
            },
            treeData: [],
            defaultLayer: [],
            ids: [],
        };
    },
    methods: {
        // 关闭弹窗
        close(isCloseBtn, removeLayer = true) {
            // 重置data值
            Object.assign(this.$data, this.$options.data());
            !isCloseBtn && this.$refs.pop.close();
        },
        // 打开弹窗
        open() {
            this.close(true);
            this.$refs.pop.open();
            this.$nextTick(() => {
                this.setLayerStart();
            })
        },
        setLayerStart() {
            if (store.getters && store.getters.layerTree) {
                this.defaultLayer = store.getters.defaultLayer;
                this.ids = this.defaultLayer;
                this.treeData = store.getters.layerTree
            }
 
        },
        handleCheckChange(data, checked, indeterminate) {
            const checkIds = this.$refs.tree.getCheckedKeys()
            if (this.ids === checkIds) return
            this.ids.map(o => {
                if (checkIds.indexOf(o) < 0) {
                    const obj = this.$refs.tree.getNode(o);
                    console.log(obj.checked);
                    if (obj.checked) {
                        mapServer.addLayer(obj.data)
                    } else {
                        mapServer.removeLayer(obj.data)
                    }
                }
            })
 
            checkIds.map(n => {
                if (this.ids.indexOf(n) < 0) {
                    const obj = this.$refs.tree.getNode(n);
                    if (obj.checked) {
                        mapServer.addLayer(obj.data)
                    } else {
                        mapServer.removeLayer(obj.data)
                    }
                }
            })
 
 
 
            this.$store.dispatch('mapLayers/changeLayerTree', this.treeData)
            const ids = this.$refs.tree.getCheckedKeys()
            this.ids = ids;
            this.$store.dispatch('mapLayers/changeDefaultLayer', ids)
        },
        setServerLayerChange(data, checked) {
            if (checked) {
                mapServer.addLayer(data)
            } else {
                mapServer.removeLayer(data)
            }
 
        },
        getNodeList(list, checked) {
            list.map(item => {
                if (item.type == 1) {
                    if (item.children && item.children.length > 0) {
                        this.getNodeList(item.children)
                    }
                } else {
                    this.setServerLayerChange(item, checked)
                }
            })
        },
    },
 
 
};
</script>
 
<style lang="scss" scoped>
.layerBox {
    height: 680px;
 
    ::v-deep.el-tree {
        background: transparent !important;
 
        .el-tree-node__content:hover {
            color: #409EFF;
        }
    }
 
}
</style>