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
127
<template>
  <mars-pannel :visible="true" right="10" top="10" width="400">
    <a-form>
      <a-form-item label="名称">
        <mars-input class="inputServe" v-model:value="serverName" placeholder="请输入查询关键字"></mars-input>
      </a-form-item>
 
      <a-form-item label="范围">
        <a-space>
          <mars-button @click="drawRectangle">框选范围</mars-button>
          <mars-button @click="drawCircle">圆形范围</mars-button>
          <mars-button @click="drawPolygon">多边形范围</mars-button>
        </a-space>
      </a-form-item>
 
      <a-form-item label="范围">
        <a-space>
          <mars-button @click="query">查询</mars-button>
          <mars-button @click="removeAll">清除</mars-button>
        </a-space>
      </a-form-item>
 
      <div v-show="showTable">
        <a-form-item>
          <mars-table
            :pagination="true"
            :dataSource="dataSource"
            :columns="columns"
            :custom-row="customRow"
            size="small"
            bordered
            :scroll="{ y: 400 }"
          />
        </a-form-item>
      </div>
    </a-form>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { computed, ref, toRaw } from "vue"
import * as mapWork from "./map.js"
import { $message } from "@mars/components/mars-ui/index"
 
interface DataItem {
  key: number
  name: string
  age: number
  address: string
  graphic: any
}
 
const serverName = ref("")
const showTable = computed(() => dataSource.value.length > 0)
 
// 表格数据
const dataSource = ref([])
 
mapWork.eventTarget.on("befortUI", function (event: any) {
  dataSource.value = []
  event.list.forEach((item: any, index: number) => {
    dataSource.value.push({ key: index, name: item["项目名称"], type: item["设施类型"], address: item["具体位置"], graphic: item.graphic })
  })
})
 
const columns = ref([
  {
    title: "名称",
    dataIndex: "name",
    key: "name"
  },
  {
    title: "类型",
    dataIndex: "type",
    key: "type",
    width: 50
  },
  {
    title: "住址",
    dataIndex: "address",
    key: "address"
  }
])
 
const customRow = (record: DataItem) => {
  return {
    onClick: () => {
      if (record.graphic == null) {
        $message(record.name + " 无经纬度坐标信息!")
        return
      }
      mapWork.flyToGraphic(toRaw(record.graphic))
    }
  }
}
 
// 绘制范围
const drawRectangle = () => {
  mapWork.drawRectangle()
}
 
const drawCircle = () => {
  mapWork.drawCircle()
}
 
const drawPolygon = () => {
  mapWork.drawPolygon()
}
 
// 查询数据
const query = () => {
  dataSource.value = []
  mapWork.clearAll(true)
  mapWork.query(serverName.value)
}
 
// 清除数据
const removeAll = () => {
  dataSource.value = []
  mapWork.clearAll()
}
</script>
<style scoped lang="less">
.inputServe {
  width: 250px;
}
</style>