2024-07-19 10:50:07 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div id="map"/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2024-07-19 16:32:36 +08:00
|
|
|
import { requestFN } from '@/utils/request'
|
2024-07-19 10:50:07 +08:00
|
|
|
|
|
|
|
let mapInstance
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2024-07-19 16:32:36 +08:00
|
|
|
this.mapInit()
|
2024-07-19 10:50:07 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
mapInstance = null
|
|
|
|
},
|
|
|
|
methods: {
|
2024-07-19 16:32:36 +08:00
|
|
|
// 地图初始化
|
|
|
|
mapInit() {
|
2024-07-19 10:50:07 +08:00
|
|
|
mapInstance = new window.BMapGL.Map('map')
|
2024-07-19 16:32:36 +08:00
|
|
|
mapInstance.centerAndZoom(new window.BMapGL.Point('119.645516', '39.934547'), 15)
|
2024-07-19 10:50:07 +08:00
|
|
|
mapInstance.enableScrollWheelZoom(true)
|
|
|
|
},
|
2024-07-19 16:32:36 +08:00
|
|
|
// 扎点
|
|
|
|
addPoint(anchor) {
|
|
|
|
if (!anchor.iconImg) throw new Error('请传入图标')
|
|
|
|
if (!anchor.imageSize) throw new Error('请传入图片大小')
|
|
|
|
if (!anchor.lng) throw new Error('请传入经度')
|
|
|
|
if (!anchor.lat) throw new Error('请传入纬度')
|
|
|
|
const imageSize = new window.BMapGL.Size(23, 30)
|
|
|
|
const icon = new window.BMapGL.Icon(anchor.iconImg, imageSize, { imageSize })
|
|
|
|
const point = new window.BMapGL.Point(anchor.lng, anchor.lat)
|
|
|
|
const marker = new window.BMapGL.Marker(point, { icon })
|
|
|
|
mapInstance.addOverlay(marker)
|
|
|
|
},
|
|
|
|
// 初始话定位点
|
|
|
|
getInfo(id) {
|
|
|
|
requestFN('/dictionaries/listTree').then((data) => {
|
|
|
|
this.treeData = JSON.parse(data.zTreeNodes)
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error('获取树形数据失败', e)
|
|
|
|
})
|
2024-07-19 10:50:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
#map {
|
|
|
|
width: calc(100vw - 210px);
|
|
|
|
height: calc(100vh - 84px);
|
|
|
|
}
|
|
|
|
</style>
|