|
|
|
@ -4,7 +4,7 @@ import position from '@/assets/imgs/position.png'
|
|
|
|
|
const show = ref(false) |
|
|
|
|
const AMap = (window as any).AMap |
|
|
|
|
let map: any = null |
|
|
|
|
const center = ref() |
|
|
|
|
const center = ref([121.243994, 41.539054]) |
|
|
|
|
const loading = ref(false) |
|
|
|
|
let mapSearch: any = null |
|
|
|
|
const address = ref() |
|
|
|
@ -14,38 +14,56 @@ const message = useMessage()
|
|
|
|
|
const open = async (param) => { |
|
|
|
|
show.value = true |
|
|
|
|
await nextTick(() => { |
|
|
|
|
init(param) |
|
|
|
|
init() |
|
|
|
|
}) |
|
|
|
|
if (param) { |
|
|
|
|
address.value = param.name |
|
|
|
|
addressInfo.value = param |
|
|
|
|
addMarker() |
|
|
|
|
} else { |
|
|
|
|
if (navigator.geolocation) { |
|
|
|
|
navigator.geolocation.getCurrentPosition( |
|
|
|
|
(position) => { |
|
|
|
|
console.log(position) |
|
|
|
|
center.value = [position.coords.longitude, position.coords.latitude] |
|
|
|
|
map.setCenter(center.value) |
|
|
|
|
}, |
|
|
|
|
(err) => { |
|
|
|
|
console.log(err) |
|
|
|
|
message.warning('获取当前位置失败,请手动选择') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
enableHighAccuracy: true, |
|
|
|
|
maximumAge: 0, |
|
|
|
|
timeout: 300 |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
message.warning('获取当前位置失败,请手动选择') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const emits = defineEmits(['success']) |
|
|
|
|
|
|
|
|
|
const init = (param) => { |
|
|
|
|
const init = () => { |
|
|
|
|
loading.value = true |
|
|
|
|
navigator.geolocation.getCurrentPosition((position) => { |
|
|
|
|
center.value = [position.coords.longitude, position.coords.latitude] |
|
|
|
|
map = new AMap.Map('map-container', { |
|
|
|
|
center: center.value, // 设置地图中心点坐标 |
|
|
|
|
zoom: 14, // 设置地图缩放级别 |
|
|
|
|
viewMode: '2D' |
|
|
|
|
}) |
|
|
|
|
map.on('complete', () => { |
|
|
|
|
const logo = document.getElementsByClassName('amap-logo')[0] |
|
|
|
|
const copyRight = document.getElementsByClassName('amap-copyright')[0] |
|
|
|
|
logo.setAttribute('style', 'display:none !important') |
|
|
|
|
copyRight.setAttribute('style', 'display:none !important') |
|
|
|
|
}) |
|
|
|
|
AMap.plugin('AMap.Autocomplete', () => { |
|
|
|
|
mapSearch = new AMap.Autocomplete({ |
|
|
|
|
city: '锦州' |
|
|
|
|
}) |
|
|
|
|
map = new AMap.Map('map-container', { |
|
|
|
|
center: center.value, // 设置地图中心点坐标 |
|
|
|
|
zoom: 14, // 设置地图缩放级别 |
|
|
|
|
viewMode: '2D' |
|
|
|
|
}) |
|
|
|
|
map.on('complete', () => { |
|
|
|
|
const logo = document.getElementsByClassName('amap-logo')[0] |
|
|
|
|
const copyRight = document.getElementsByClassName('amap-copyright')[0] |
|
|
|
|
logo.setAttribute('style', 'display:none !important') |
|
|
|
|
copyRight.setAttribute('style', 'display:none !important') |
|
|
|
|
loading.value = false |
|
|
|
|
}) |
|
|
|
|
AMap.plugin('AMap.Autocomplete', () => { |
|
|
|
|
mapSearch = new AMap.Autocomplete({ |
|
|
|
|
city: '锦州' |
|
|
|
|
}) |
|
|
|
|
if (param) { |
|
|
|
|
address.value = param.name |
|
|
|
|
addressInfo.value = param |
|
|
|
|
addMarker() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
loading.value = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const querySearchAsync = (queryString: string, cb: (arg: any) => void) => { |
|
|
|
|