2023-08-17 10:01:53 +08:00
|
|
|
|
<template>
|
2023-08-17 11:23:12 +08:00
|
|
|
|
<div id="container" ref="map"></div>
|
2023-08-17 10:01:53 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup name="mapContainer">
|
|
|
|
|
import AMapLoader from "@amap/amap-jsapi-loader";
|
|
|
|
|
import { shallowRef } from "@vue/reactivity";
|
|
|
|
|
|
|
|
|
|
const map = shallowRef(null);
|
|
|
|
|
|
|
|
|
|
const initMap = () => {
|
|
|
|
|
AMapLoader.load({
|
2023-08-17 11:23:12 +08:00
|
|
|
|
key: "4f8f55618010007147aab96fc72bb408", // 申请好的Web端开发者Key,首次调用 load 时必填
|
2023-08-17 10:01:53 +08:00
|
|
|
|
version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
|
|
|
plugins: [""], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
|
|
|
})
|
|
|
|
|
.then((AMap) => {
|
2023-08-17 11:23:12 +08:00
|
|
|
|
map.value = new AMap.Map("container", {
|
2023-08-17 10:01:53 +08:00
|
|
|
|
//设置地图容器id
|
|
|
|
|
viewMode: "2D", //是否为3D地图模式
|
2023-08-17 11:23:12 +08:00
|
|
|
|
zoom: 10, //初始化地图级别
|
2023-08-17 10:01:53 +08:00
|
|
|
|
center: [105.602725, 37.076636], //初始化地图中心点位置
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((e) => {
|
2023-08-17 11:23:12 +08:00
|
|
|
|
console.log("地图错误", e);
|
|
|
|
|
ElMessage.error("未知错误");
|
2023-08-17 10:01:53 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2023-08-17 11:23:12 +08:00
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
initMap();
|
|
|
|
|
});
|
2023-08-17 10:01:53 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
#container {
|
|
|
|
|
padding: 0px;
|
|
|
|
|
margin: 0px;
|
2023-08-17 11:23:12 +08:00
|
|
|
|
width: 400px;
|
|
|
|
|
height: 400px;
|
2023-08-17 10:01:53 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|