feat: 调用高德接口

server_ui_dongxiaodong
lijiayao 2024-03-27 22:24:10 +08:00
parent 0da5b6c201
commit da3265ad9d
4 changed files with 133 additions and 6 deletions

View File

@ -36,6 +36,7 @@
"url": "https://gitee.com/y_project/MuYu-Cloud.git"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"@riophae/vue-treeselect": "0.4.0",
"axios": "0.24.0",
"clipboard": "2.0.8",
@ -53,6 +54,7 @@
"screenfull": "5.0.2",
"sortablejs": "1.10.2",
"vue": "2.6.12",
"vue-amap": "^0.5.10",
"vue-count-to": "1.0.13",
"vue-cropper": "0.5.5",
"vue-meta": "2.4.0",

View File

@ -37,6 +37,10 @@ import DictTag from '@/components/DictTag'
import VueMeta from 'vue-meta'
// 字典数据组件
import DictData from '@/components/DictData'
// 高德地图
import AMapLoader from "@amap/amap-jsapi-loader"
import VueAMap from "vue-amap";
// 全局方法挂载
Vue.prototype.getDicts = getDicts
@ -84,3 +88,26 @@ new Vue({
store,
render: h => h(App)
})
// 高德地图
Vue.use(VueAMap);
// 初始化vue-amap
VueAMap.initAMapApiLoader({
// 高德的key
key: "b5f283177b02e0bdd7f4981f4f219432", // 换成你自己的key,这是我随便写的
// 插件集合
plugin: [
"AMap.Autocomplete",
"AMap.PlaceSearch",
"AMap.Scale",
"AMap.OverView",
"AMap.ToolBar",
"AMap.MapType",
"AMap.PolyEditor",
"AMap.CircleEditor",
],
// 高德 sdk 版本,默认为 1.4.4
v: "1.4.4",
});

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!-- 设置高德地图安全密钥 -->
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode: 'd4afcbb16c37bab037fe756ffb063e51', // 你的密钥
}
</script>
</body>
</html>

View File

@ -1,11 +1,93 @@
<script setup>
</script>
<template>
<div class="mapBox">
<!-- 使用高德地图的组件-->
<el-amap vid="amapDemo" :zoom="zoom" :center="center" style="height: 600px">
<!-- el-amap-marker>: 通过v-for指令循环遍历markers数组-->
<!-- 并为每个标记创建一个el-amap-marker组件将标记的位置(position)绑定到数组中的相应数据-->
<el-amap-marker
v-for="marker in markers"
:position="marker.position"
:events="marker.events"
:key="marker.index"
></el-amap-marker>
<el-amap-info-window
v-for="window in windows"
:offset="window.offset"
:position="window.position"
:content="window.content"
:open="window.open"
:key="window.index"
></el-amap-info-window>
</el-amap>
</div>
</template>
<style scoped lang="scss">
<script>
export default {
components: {},
data() {
return {
//
unit: "xxxxx政府司法局",
address: "xx省xx市xxxxx大道东433号",
// markerswindows
markers: [],
windows: [],
center: [116.39, 39.9],
zoom: 16,
// currentPosition: null, //
label: {
content: "自定义标题",
offset: [10, 12],
},
};
},
async mounted() {
this.initMap();
},
methods: {
//
initMap(map) {
this.markers.push({
// position: [116.407387, 39.904179],
position: [116.39, 39.9],
// position: this.currentPosition,
});
this.windows.push({
position: [116.39, 39.9],
// position: this.currentPosition,
content:
"<h2 style='font-weight: bold;width: 400px;margin: 10px'>" +
this.unit +
"</h2>" +
"<div style='margin: 10px'>" +
"地址:" +
this.address +
"</div>",
offset: [0, -20],
open: true,
});
// var map = new AMap.Map("container", {
// zoomEnable: true, //
// zoom: 12, //
// dragEnable: false, //
// cursor: "hand", //
// });
// //
// map.plugin(["AMap.ToolBar"], function () {
// map.addControl(new AMap.ToolBar());
// });
},
},
};
</script>
<style lang="scss" scoped>
.mapBox {
position: relative;
width: 100%;
height: 600px;
}
</style>