123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <template>
- <div class="map-pg" ref="el"></div>
- <PageLoading :loading="loading" />
- </template>
-
- <script setup>
- import { onMounted, ref, watch } from 'vue';
- import PageLoading from '@/components/PageLoading.vue';
- import countryGPS from '@/utils/country_gps';
- import { getCountry } from '@/utils/maputil';
-
- const emit = defineEmits(['click']);
-
- const el = ref();
- const mapRef = ref();
- const loading = ref(false);
-
-
- const mockCountries = [
- '中国',
- '俄罗斯',
- '哈萨克斯坦',
- '伊朗',
- '印度',
- '泰国',
- ];
-
-
-
- onMounted(() => {
- const map = new BMap.Map(el.value);
- const point = new BMap.Point(116.404, 39.915);
- map.centerAndZoom(point, 3);
- mapRef.value = map;
-
-
- map.addEventListener('click', (e) => {
- console.log('-----start-----')
- loading.value = true;
- const { point } = e;
- getCountry(point.lng, point.lat).then(x => {
- emit('click', x);
- loading.value = false;
- console.log('-----end-----')
- }).catch((err) => {
- console.error(err);
- loading.value = false;
- });
- });
-
-
- const icon = new BMap.Icon('./images/logo.png', new BMap.Size(16, 16));
- mockCountries.forEach(country => {
- const target = countryGPS[country];
- if (!target) {
- console.error(`${country} 在世界GPS列表中不存在`)
- return;
- }
-
- const point = new BMap.Point(target[0], target[1]);
- const marker = new BMap.Marker(point, { icon });
- map.addOverlay(marker);
- marker.setAnimation(BMAP_ANIMATION_BOUNCE);
-
-
-
-
-
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- });
-
- </script>
-
- <style lang="less" scoped>
- .map-pg {
- width: 100%;
- height: 100%;
- }
- </style>
|