feat:完善功能

This commit is contained in:
zjc
2025-02-19 23:00:11 +08:00
parent 784d634272
commit 99860f9b50
13 changed files with 208 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ import { ref } from 'vue'
export function useMap() {
let map = ref(null)
let marker = ref(null)
// 初始化地图
const initMap = (id, lat, lng, scale = 15, satellite) => {
map.value = new BMapGL.Map(id)
@@ -27,11 +28,36 @@ export function useMap() {
// 创建标注对象并添加到地图
marker.value = new BMapGL.Marker(point, { icon: iconPath })
map.value.addOverlay(marker.value)
// marker.value.addEventListener('click', (e) => {
// console.log(e, '===')
// if (!infoBox.value) {
// setInfoBox(e.latLng)
// } else {
// if (lastInfoBox.value) lastInfoBox.value?.close()
// infoBox.value.open(e.latLng)
// lastInfoBox.value = infoBox.value
// }
// // const content = `
// // <div style="padding: 10px;">
// // <h4>标题</h4>
// // <p>这里是详细信息</p>
// // </div>
// // `
// // var infoWindow = new BMapGL.InfoWindow(content) // 创建信息窗口对象
// // console.log(map.value.getCenter())
// // map.value.openInfoWindow(infoWindow, e.latLng) // 打开信息窗口
// // const infoWindow = new BMapGL.InfoWindow('这里是一些信息') // 创建信息窗口对象
// // marker.value.openInfoWindow(infoWindow) // 打开信息窗口
// })
}
// 清除覆盖物
const clearOverlays = () => {
map.value.clearOverlays()
}
return { map, marker, initMap, addMarker, clearOverlays }
// 清除某一个覆盖物
const removeOverlay = (i) => {
map.value.removeOverlay(i)
}
return { map, marker, initMap, addMarker, clearOverlays, removeOverlay }
}