MapComponent.vue
2.5 KB
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
<script lang="ts">
export default {
inheritAttrs: false,
};
</script>
<script lang="ts" setup>
import { computed, nextTick, onMounted, ref, unref } from 'vue';
import { RadioRecord } from '../../detail/config/util';
import { useScript } from '/@/hooks/web/useScript';
import { BAI_DU_MAP_URL } from '/@/utils/fnUtils';
import { MapComponentLayout, MapComponentValue } from './map.config';
import {
ClockCircleOutlined,
PlayCircleOutlined,
PauseCircleOutlined,
} from '@ant-design/icons-vue';
import { Button, Tooltip } from 'ant-design-vue';
withDefaults(
defineProps<{
value?: MapComponentValue;
layout?: MapComponentLayout;
radio?: RadioRecord;
}>(),
{}
);
const wrapRef = ref<HTMLDivElement | null>(null);
const { toPromise } = useScript({ src: BAI_DU_MAP_URL });
async function initMap() {
await toPromise();
await nextTick();
const wrapEl = unref(wrapRef);
if (!wrapEl) return;
const BMap = (window as any).BMap;
const map = new BMap.Map(wrapEl);
const point = new BMap.Point(116.404, 39.915);
map.centerAndZoom(point, 15);
map.enableScrollWheelZoom(true);
}
onMounted(() => {
initMap();
});
const getTimeRange = computed(() => {
return ` - 从 ${'2020-10-20 10:10:10'} 到 ${'2020-10-20 10:10:10'}`;
});
const handleTrackSwitch = () => {};
const pauseFlag = ref(true);
const handlePlay = () => {
pauseFlag.value = false;
};
const handlePause = () => {
pauseFlag.value = true;
};
</script>
<template>
<div class="w-full h-full flex justify-center items-center flex-col">
<div class="w-[95%] flex">
<Button type="text" class="!px-2 flex-auto !text-left truncate" @click="handleTrackSwitch">
<div class="w-full truncate text-gray-500 flex items-center">
<ClockCircleOutlined />
<span class="mx-1">实时</span>
<Tooltip :title="getTimeRange.replace('-', '')">
<span class="truncate">
{{ getTimeRange }}
</span>
</Tooltip>
</div>
</Button>
<Button v-show="pauseFlag" type="text" class="!px-2 !text-gray-500" @click="handlePlay">
<PlayCircleOutlined />
<span>播放轨迹</span>
</Button>
<Button v-show="!pauseFlag" type="text" class="!px-2 !text-gray-500" @click="handlePause">
<PauseCircleOutlined />
<span>暂停播放</span>
</Button>
</div>
<div ref="wrapRef" class="w-[95%] h-[95%]"></div>
</div>
</template>