2023-11-27 17:18:03 +08:00
|
|
|
|
<script setup>
|
2023-11-29 18:49:31 +08:00
|
|
|
|
import { onMounted, onUnmounted, ref } from "vue";
|
2023-11-27 17:18:03 +08:00
|
|
|
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
|
|
|
|
|
|
|
|
let map = null;
|
|
|
|
|
|
2023-11-29 18:49:31 +08:00
|
|
|
|
const loading = ref(true);
|
|
|
|
|
|
2023-11-27 17:18:03 +08:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
AMapLoader.load({
|
|
|
|
|
key: "f14dcaeb4df441ab84ed0a0768f04f95", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
|
|
version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
|
|
plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
|
|
|
})
|
|
|
|
|
.then((AMap) => {
|
2023-11-29 18:49:31 +08:00
|
|
|
|
map = new AMap.Map("container-left", {
|
2023-11-27 17:18:03 +08:00
|
|
|
|
// 设置地图容器id
|
|
|
|
|
viewMode: "2D", // 是否为3D地图模式
|
|
|
|
|
zoom: 15, // 初始化地图级别
|
|
|
|
|
center: [105.441866, 28.87098], // 初始化地图中心点位置
|
|
|
|
|
mapStyle: "amap://styles/darkblue",
|
|
|
|
|
});
|
2023-11-29 18:49:31 +08:00
|
|
|
|
// 监听地图加载完成事件
|
|
|
|
|
map.on('complete', () => {
|
|
|
|
|
// 地图加载完成后执行的操作
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}, 500)
|
|
|
|
|
});
|
2023-11-27 17:18:03 +08:00
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
map?.destroy();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2023-11-29 18:49:31 +08:00
|
|
|
|
<div class="c-box">
|
|
|
|
|
<div id="container-left"></div>
|
|
|
|
|
<div class="loading" v-if="loading">
|
|
|
|
|
<dv-loading>加载中...</dv-loading>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-11-27 17:18:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
2023-11-29 18:49:31 +08:00
|
|
|
|
<style scoped lang ="scss">
|
|
|
|
|
.c-box {
|
2023-11-27 17:18:03 +08:00
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2023-11-29 18:49:31 +08:00
|
|
|
|
position: relative;
|
|
|
|
|
#container-left {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
.loading {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
background-color: #05273d;
|
|
|
|
|
}
|
2023-11-27 17:18:03 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|