wujingjing
2024-11-29 a7c0c52ed984e5dbae736a469fdac701d1a68a7f
src/components/chat/chatComponents/summaryCom/components/recordSetTable/map/Map.vue
@@ -1,6 +1,6 @@
<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"
@@ -19,6 +19,8 @@
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';
@@ -26,13 +28,14 @@
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">
@@ -69,7 +72,7 @@
   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;
@@ -90,6 +93,7 @@
         icon: {
            url: equipPic,
            size: 30,
            selectUrl: equipSelectPic,
         },
         click(e, label) {
            // if (!bottomBarIsShow.value) {
@@ -98,6 +102,9 @@
            // 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);
@@ -117,7 +124,12 @@
};
let infoWindow: AMap.InfoWindow;
const restoreLabel = () => {
   // 关闭恢复图片
   curMarkerLabel?.setIcon({
      image: equipPic,
   });
};
onMounted(async () => {
   await gaoDeMap.init({
      container: containerRef.value,
@@ -132,7 +144,6 @@
   addMarkerLayer();
   gaoDeMap.map.setFitView();
   infoWindow = new AMap.InfoWindow({
      content: createInfoWindow(),
@@ -140,11 +151,21 @@
      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">