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
<template>
  <mars-pannel :visible="true" right="10" top="10" height="90">
    <a-space>
      <mars-button @click="shoRailway">铁路</mars-button>
      <mars-button @click="showExpressway">高速公路</mars-button>
      <mars-button @click="showMeteorological">气象等值面</mars-button>
      <mars-button @click="showGDP">国家GDP数据</mars-button>
      <mars-button @click="showSafetyNotice">海上安全通告</mars-button>
    </a-space>
    <div class="f-pt">
      <layer-state />
    </div>
  </mars-pannel>
 
  <mars-pannel :visible="true" right="10" top="110" width="200" customClass="pannel">
    <mars-tree checkable :tree-data="treeData" @check="checkedChange" v-model:checkedKeys="selectedKeys" v-model:expandedKeys="expandedKeys">
      <template #title="{ title }">
        <span :title="title">{{ title }}</span>
      </template>
    </mars-tree>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { nextTick, ref } from "vue"
import LayerState from "@mars/components/mars-sample/layer-state.vue"
import * as mapWork from "./map.js"
 
const treeData = ref<any[]>([
  {
    title: "全部",
    key: 0,
    id: -1,
    children: []
  }
])
const selectedKeys = ref<string[]>([])
const expandedKeys = ref<any[]>([])
expandedKeys.value.push(0)
 
const layersObj: any = {}
 
mapWork.treeEvent.on("tree", (event: any) => {
  initTree(event)
})
 
const checkedChange = (_keys: string[], checkedNodes: any) => {
  const node = checkedNodes.node
  if (!node.children && node.checked) {
    layersObj[node.key].show = false
  }
  if (!node.children && !node.checked) {
    layersObj[node.key].show = true
  }
 
  if (node.id === -1 && node.checked) {
    node.children.forEach((element: any) => {
      layersObj[element.key].show = false
    })
  }
  if (node.id === -1 && !node.checked) {
    node.children.forEach((element: any) => {
      layersObj[element.key].show = true
    })
  }
  mapWork.flyToEntity()
}
 
// 初始化树控件
function initTree(event: any) {
  const modelList = event.treeData
 
  const tree = []
  const selects: string[] = []
  for (let i = 0; i < modelList.length; i++) {
    const node = modelList[i].graphic
 
    if (node) {
      const nodeList: any = {
        title: node.name || "未命名",
        key: node.id
      }
      tree.push(nodeList)
      selects.push(nodeList.key)
      layersObj[nodeList.key] = node
    }
  }
  treeData.value[0].children = tree
 
  nextTick(() => {
    selectedKeys.value = selects
  })
}
 
const shoRailway = () => {
  selectedKeys.value = []
 
  mapWork.shoRailway()
}
const showExpressway = () => {
  selectedKeys.value = []
 
  mapWork.showExpressway()
}
const showMeteorological = () => {
  selectedKeys.value = []
 
  mapWork.showMeteorological()
}
const showGDP = () => {
  selectedKeys.value = []
 
  mapWork.showGDP()
}
const showSafetyNotice = () => {
  selectedKeys.value = []
 
  mapWork.showSafetyNotice()
}
</script>
<style lang="less">
.pannel {
  max-height: 750px;
  overflow-y: auto;
}
</style>