wujingjing
2024-11-27 c29fb5b2bf86955b681c36b72b9c0891d47a0ad5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
    <div class="h-[70vh] relative">
        <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"
                @click="toggleShowChart"
            >
                <div
                    class="ywifont -rotate-90 text-white !text-[13px]"
                    :class="{ 'ywicon-zuoyoujiantou': chartIsShow, 'ywicon-zuoyoujiantou1': !chartIsShow }"
                ></div>
            </div>
        </div>
    </div>
</template>
 
<script setup lang="ts">
import { onMounted, ref } from 'vue';
 
import equipPic from './img/equip.svg';
import type { GaoDePosition, LabelMarkerData } from '/@/model/map/GaoDeMap';
import { GaoDeMap } from '/@/model/map/GaoDeMap';
 
let gaoDeMap = new GaoDeMap();
const containerRef = ref<HTMLDivElement>(null);
const props = defineProps(['data']);
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 text-blue-600" style="padding: 12px">
            
            <div class="space-x-4 flex w-full">
                <div class="flex flex-col w-1/2 key-list">
                    
                </div>
 
                <div class="flex flex-col w-1/2 value-list">
                    
                </div>
            </div>
        </div>`;
 
    return dom;
};
 
const updateInfoWindow = (item) => {
    const cellHeight = '20px';
    const keyListDom = infoWindow.dom.querySelector('.key-list');
    const valueListDom = infoWindow.dom.querySelector('.value-list')
 
    const colsArray = props.data.cols ?? [];
    const keyItemHtml = colsArray
        .map((col) => {
            return `<span class="flex-items-center justify-start" style="height:${cellHeight}">${col.title??''}</span>`;
        })
        .join('');
 
    const valueItemHtml = colsArray
        .map((col, index) => {
            return `<span class="flex-items-center justify-end" style="height:${cellHeight}">${item[index] ??''}</span>`;
        })
        .join('');
 
    keyListDom.innerHTML = keyItemHtml;
    valueListDom.innerHTML = valueItemHtml;
};
 
const addMarkerLayer = () => {
    const map = props.data.map;
    if (map.pos_x == null && map.pos_y == null) return;
 
    const dataList = (props.data?.values ?? []).map((item) => {
        const x = item[map.pos_x];
        const y = item[map.pos_y];
 
        return {
            position: [x, y],
            // textColor: item.color,
            extData: item,
            title: item.title,
        };
    });
    gaoDeMap.addMarkerLayer(dataList, {
        markerOpt: {
            icon: {
                url: equipPic,
                size: 30,
            },
            click(e, label) {
                if (!bottomBarIsShow.value) {
                    bottomBarIsShow.value = true;
                }
                if (!chartIsShow.value) {
                    chartIsShow.value = true;
                }
                infoWindow.open(gaoDeMap.map, label.getPosition() as any);
                const extData = label.getExtData();
 
                updateInfoWindow(extData);
            },
        },
        layerOpt: {
            // allowCollision:false
        },
    });
};
 
const bottomBarIsShow = ref(false);
const chartIsShow = ref(true);
const toggleShowChart = () => {
    chartIsShow.value = !chartIsShow.value;
};
 
let infoWindow: AMap.InfoWindow;
 
onMounted(async () => {
    await gaoDeMap.init({
        container: containerRef.value,
        aMapOption: {
            resizeEnable: true,
        },
    });
    // const southWest: GaoDePosition = [props.data.minx, props.data.miny];
    // const northEast: GaoDePosition = [props.data.maxx, props.data.maxy];
    // gaoDeMap.zoomToRect(southWest, northEast);
    gaoDeMap.applyBasicPlugins();
 
    addMarkerLayer();
    gaoDeMap.map.setFitView();
 
    infoWindow = new AMap.InfoWindow({
        content: createInfoWindow(),
        // offset: [3, -34],
        anchor: 'top-left',
        closeWhenClickMap: true,
    });
});
</script>
<style scoped lang="scss">
:deep(.amap-info-content) {
    padding: 0;
}
</style>