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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
  <mars-pannel :visible="true" right="10" top="10" width="300">
    <a-form>
      <a-form-item label="方式">
        <mars-select class="selectWidth" v-model:value="selectWay" :options="selectWayOptions" @change="onHiddenRoam"> </mars-select>
      </a-form-item>
 
      <a-form-item label="起点">
        <a-space>
          <mars-input class="inputWidth" v-model:value="strat" disabled></mars-input>
          <mars-button @click="startPoint">选点</mars-button>
        </a-space>
      </a-form-item>
      <a-form-item label="终点">
        <a-space>
          <p class="inputWidth">
            共<span style="color: red">{{ count }}</span
            >条POI点
          </p>
          <mars-button @click="endPoint">查询</mars-button>
        </a-space>
      </a-form-item>
 
      <div class="f-tac">
        <a-space>
          <mars-button @click="btnAnalyse">开始分析</mars-button>
          <mars-button @click="removeAll">清除</mars-button>
        </a-space>
      </div>
 
      <div v-show="dataSource.length > 0">
        <mars-table
          :pagination="false"
          :dataSource="dataSource"
          :columns="columns"
          :custom-row="customRow"
          size="small"
          bordered
          :scroll="{ y: 300 }"
        ></mars-table>
      </div>
    </a-form>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { ref } from "vue"
import * as mapWork from "./map.js"
 
interface DataItem {
  key: number
  index: number
  name: string
  length: number
  time: string
  graphic: any
}
 
const strat = ref("")
const count = ref(0)
const selectWay = ref("1")
 
// 表格数据
const dataSource = ref<any[]>([])
const columns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    width: 50
  },
  {
    title: "名称",
    dataIndex: "name",
    key: "name"
  },
  {
    title: "总距离",
    dataIndex: "length",
    key: "length"
  },
  {
    title: "时间",
    dataIndex: "time",
    key: "time"
  }
]
 
const customRow = (record: DataItem) => {
  return {
    onClick: () => {
      mapWork.centerAtRoute(record.graphic)
    }
  }
}
// 下拉菜单
const selectWayOptions = ref([
  {
    // 1-步行路线
    value: "1",
    label: "步行路线查询"
  },
  {
    // 2-行车路线
    value: "3",
    label: "驾车路线查询"
  }
])
 
// 起点
const startPoint = async () => {
  const stratPoint: any = await mapWork.startPoint()
  strat.value = stratPoint
}
 
// 终点POI
const endPoint = () => {
  mapWork.endPoint()
}
 
mapWork.eventTarget.on("end", (event: any) => {
  count.value = event.count
})
 
const onHiddenRoam = (data) => {
  if (strat.value && count.value !== 0) {
    btnAnalyse()
  }
}
// 开始分析
const btnAnalyse = () => {
  dataSource.value = []
  mapWork.btnAnalyse(selectWay.value, count.value)
}
 
mapWork.eventTarget.on("analyse", (event: any) => {
  dataSource.value.push({
    key: event.i,
    index: event.i + 1,
    name: event.name,
    length: event.distance,
    time: event.time,
    graphic: event.id
  })
})
 
// 清除数据
const removeAll = () => {
  mapWork.removeAll()
  dataSource.value = []
  strat.value = ""
  count.value = 0
}
</script>
<style scoped lang="less">
.selectWidth {
  width: 210px;
}
.inputWidth {
  width: 150px;
}
</style>