This commit is contained in:
zk
2023-11-27 14:34:08 +08:00
parent 462dd54ce1
commit c28a49e45c
4 changed files with 76 additions and 58 deletions
+9 -37
View File
@@ -61,7 +61,7 @@
import { onMounted, ref } from 'vue';
import * as echarts from 'echarts';
import mapJson from '/@/components/chinaMap/json/c';
import { tabList, mapIcons, legendList } from './chinaHooks.ts';
import { tabList, mapIcons, legendList, getTimeStr, getKmStr } from './chinaHooks.ts';
import { message } from 'ant-design-vue';
const bgImg = new URL('/@/assets/images/china-textur.jpg', import.meta.url).href;
@@ -226,6 +226,13 @@
showRoutePanel.value = false;
}
function setTitle({ time, distance }) {
let str = '全程';
str += getTimeStr(time);
str += getKmStr(distance);
panelTitle.value = str;
}
function searchRoute() {
showRoutePanel.value = false;
panelTitle.value = '';
@@ -256,46 +263,11 @@
}
});
AMap.Event.addListener(driving, 'complete', (res) => {
// console.log(JSON.stringify(res));
const data = JSON.parse(JSON.stringify(res));
console.log('data', data);
if (data.info == 'OK') {
const { routes } = data;
const { distance, time } = routes[0];
function convertSeconds(seconds) {
let hours = Math.floor(seconds / 3600);
let minutes = Math.floor((seconds % 3600) / 60);
let remainingSeconds = seconds % 60;
return {
hours: hours,
minutes: minutes,
seconds: remainingSeconds,
};
}
function convertMetersToKilometers(meters) {
var kilometers = meters / 1000;
return Math.round(kilometers * 100) / 100;
}
let str = '全程';
const { hours, minutes } = convertSeconds(time);
if (hours) {
str += hours + '小时';
}
if (minutes) {
str += minutes + '分钟';
}
let d = convertMetersToKilometers(distance);
let dr = d >= 1 ? d + '公里' : d * 100 + '米';
str += `(${dr})`;
console.log('str', str);
panelTitle.value = str;
setTitle(routes[0]);
let arr = [];
console.log('routes', routes);
arr.push(data.originName);
routes[0].steps.map((item) => {
arr.push(item.instruction);