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
<template>
  <mars-pannel customClass="gaodeRoutePannel" :visible="true">
    <a-form>
      <a-form-item label="方式">
        <mars-select v-model:value="selectWay" :options="selectWayOptions" @change="onHiddenRoam"> </mars-select>
      </a-form-item>
 
      <a-form-item label="起点">
        <a-space>
          <mars-input v-model:value="strat" disabled></mars-input>
          <mars-button @click="startPoint">选点</mars-button>
        </a-space>
      </a-form-item>
      <a-form-item label="终点">
        <a-space>
          <mars-input v-model:value="end" disabled></mars-input>
          <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>
          <mars-button @click="saveGeoJSON">保存GeoJSON</mars-button>
        </a-space>
      </div>
 
      <div v-if="allDiatance" class="showRoam">
        <p style="color: #cad1d1">总距离:{{ allDiatance }}</p>
        <p style="color: #cad1d1">预计时间:{{ useTime }}</p>
        <p style="color: #cad1d1">导航:{{ routePath }}</p>
      </div>
    </a-form>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { ref } from "vue"
import * as mapWork from "./map.js"
 
const strat = ref("")
const end = ref("")
const selectWay = ref("1")
const allDiatance = ref("")
const useTime = ref("")
const routePath = ref("")
 
// 下拉菜单
const selectWayOptions = ref([
  {
    // 1-步行路线
    value: "1",
    label: "步行路线查询"
  },
  {
    // 2-行车路线
    value: "3",
    label: "驾车路线查询"
  }
])
 
const onHiddenRoam = () => {
  if (strat.value && end.value) {
    mapWork.btnAnalyse(selectWay.value)
  }
}
mapWork.eventTarget.on("analyse", function (event: any) {
  useTime.value = event.allTime
  allDiatance.value = event.allDistance
  routePath.value = event.dhHtml
})
 
// 起点
const startPoint = async () => {
  strat.value = await mapWork.startPoint(selectWay.value)
}
 
// 终点
const endPoint = async () => {
  end.value = await mapWork.endPoint(selectWay.value)
}
 
// 开始分析
const btnAnalyse = () => {
  mapWork.btnAnalyse(selectWay.value)
}
 
// 清除数据
const removeAll = () => {
  mapWork.removeAll()
  strat.value = ""
  end.value = ""
  allDiatance.value = ""
  useTime.value = ""
  routePath.value = ""
}
 
// 保存GeoJSON
const saveGeoJSON = () => {
  mapWork.saveGeoJSON()
}
</script>
 
<style lang="less">
.gaodeRoutePannel {
  right: 10px !important;
  top: 10px !important;
  max-height: calc(100% - 51px) !important;
  overflow: auto !important;
}
</style>
<style scoped lang="less">
.showRoam {
  top: 250px;
  word-break: break-all;
  width: 300px;
  padding: 5px;
  line-height: 25px;
}
.ant-select {
  width: 250px;
}
</style>