1.注册/登录高德开放平台
首先/注册开发者账号,成为高德开放平台开发者
登陆之后,在进入「应用管理」 页面「创建新应用」
为应用添加 Key
添加成功后,可获取到key值和安全密钥jscode
(自2021年12月02日升级,升级之后所申请的 key 必须配备安全密钥 jscode 一起使用;
安装高德第三方包
npm i @amap/amap-jsapi-loader --save
<template>
<div id="amapcontainer"></div>
</template>
<script>
import AMapLoader from "@amap/amap-jsapi-loader";
window._AMapSecurityConfig = {
securityJsCode: "",
};
export default {
data() {
return {
map: null,
};
},
mounted() {
this.initMap();
},
created() {
this.initMap();
},
methods: {
initMap() {
AMapLoader.load({
key: "",
version: "2.0",
plugins: [],
})
.then((AMap) => {
console.log(AMap);
this.AMap = AMap
this.map = new AMap.Map("amapcontainer", {
resizeEnable: true,
viewMode: "2D",
zoomEnable: true,
dragEnable: true,
doubleClickZoom: true,
zoom: 10.2,
center: [119.858881, 30.794178],
mapStyle: 'amap://styles/189339a13af61c9cb69dab5bed0ba152',
})
})
.catch((e) => {
console.log(e);
});
},
},
};
</script>
<style scoped>
#amapcontainer{
overflow: hidden;
width: 500px;
height: 500px;
margin: 0;
}
</style>
插件
地图样式