| | |
| | | <template> |
| | | <div class="h-[60vh] relative"> |
| | | <div ref="containerRef" class="h-full"></div> |
| | | <div ref="containerRef" class="h-full"></div> |
| | | <!-- <div v-if="bottomBarIsShow" class="absolute w-full bottom-0 bg-white border-gray-300 border border-solid"> |
| | | <div |
| | | class="w-28 h-5 absolute left-1/2 -translate-x-1/2 -translate-y-[100%] cursor-pointer bg-[#4974f3] rounded-t-lg flex-center" |
| | |
| | | import { onMounted, ref } from 'vue'; |
| | | |
| | | import equipPic from './img/equip.svg'; |
| | | import equipSelectPic from './img/equip-select.svg'; |
| | | |
| | | import type { GaoDePosition, LabelMarkerData } from '/@/model/map/GaoDeMap'; |
| | | import { GaoDeMap } from '/@/model/map/GaoDeMap'; |
| | | |
| | |
| | | const containerRef = ref<HTMLDivElement>(null); |
| | | const props = defineProps(['data']); |
| | | |
| | | const emit = defineEmits(['equipClick','closeInfoWindow']); |
| | | const emit = defineEmits(['equipClick', 'closeInfoWindow']); |
| | | const createInfoWindow = () => { |
| | | // title |
| | | // <div class="title flex-center bg-[#ca0dab] text-white py-0.5 mb-2 w-full over-ellipsis"> |
| | | // 罗汉鱼 |
| | | // </div> |
| | | const dom = `<div class="rounded-md text-nowrap flex flex-col w-fit border border-solid border-blue-600 " style="padding: 12px"> |
| | | const dom = `<div class="rounded-md text-nowrap flex flex-col w-fit border border-solid border-blue-600 relative" style="padding: 12px"> |
| | | <span class="guanbi absolute ywifont ywicon-guanbi right-[4px] top-[-2px] font-bold text-[#c3c3c3] cursor-pointer" ></span> |
| | | |
| | | <div class="space-x-4 flex w-full"> |
| | | <div class="flex flex-col w-1/2 key-list"> |
| | |
| | | keyListDom.innerHTML = keyItemHtml; |
| | | valueListDom.innerHTML = valueItemHtml; |
| | | }; |
| | | |
| | | let curMarkerLabel: AMap.LabelMarker; |
| | | const addMarkerLayer = () => { |
| | | const map = props.data.map; |
| | | if (map.pos_x == null && map.pos_y == null) return; |
| | |
| | | icon: { |
| | | url: equipPic, |
| | | size: 30, |
| | | selectUrl: equipSelectPic, |
| | | }, |
| | | click(e, label) { |
| | | // if (!bottomBarIsShow.value) { |
| | |
| | | // if (!chartIsShow.value) { |
| | | // chartIsShow.value = true; |
| | | // } |
| | | |
| | | curMarkerLabel && curMarkerLabel !== label && restoreLabel(); |
| | | curMarkerLabel = label; |
| | | infoWindow.open(gaoDeMap.map, label.getPosition() as any); |
| | | const extData = label.getExtData(); |
| | | emit('equipClick', extData); |
| | |
| | | }; |
| | | |
| | | let infoWindow: AMap.InfoWindow; |
| | | |
| | | const restoreLabel = () => { |
| | | // 关闭恢复图片 |
| | | curMarkerLabel?.setIcon({ |
| | | image: equipPic, |
| | | }); |
| | | }; |
| | | onMounted(async () => { |
| | | await gaoDeMap.init({ |
| | | container: containerRef.value, |
| | |
| | | |
| | | addMarkerLayer(); |
| | | gaoDeMap.map.setFitView(); |
| | | |
| | | |
| | | infoWindow = new AMap.InfoWindow({ |
| | | content: createInfoWindow(), |
| | |
| | | anchor: 'top-left', |
| | | closeWhenClickMap: true, |
| | | }); |
| | | |
| | | const closeBtnDom = infoWindow.dom.querySelector('.amap-info-close'); |
| | | closeBtnDom.addEventListener('click', () => { |
| | | (infoWindow as any).on('close', (...a) => { |
| | | restoreLabel(); |
| | | curMarkerLabel = null; |
| | | |
| | | emit('closeInfoWindow'); |
| | | }); |
| | | |
| | | // 自带关闭去掉,自带关闭监听 close 会多次触发 close 事件 |
| | | const closeBtnDom = infoWindow.dom.querySelector('.amap-info-close'); |
| | | closeBtnDom.remove(); |
| | | const myCloseBtn = infoWindow.dom.querySelector('.guanbi'); |
| | | myCloseBtn.addEventListener('click', () => { |
| | | infoWindow.close(); |
| | | }); |
| | | |
| | | }); |
| | | </script> |
| | | <style scoped lang="scss"> |