|
@@ -5,12 +5,13 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="Map">
|
|
|
-import { useAMap } from '@/hooks/AMap/useAMap';
|
|
|
-import { useDrawTool } from '@/hooks/AMap/useDrawTool';
|
|
|
-import { getDictLabel } from '@/utils/dict';
|
|
|
-import { pointDetailTemplate } from './mapData';
|
|
|
+import {useAMap} from '@/hooks/AMap/useAMap';
|
|
|
+import {useDrawTool} from '@/hooks/AMap/useDrawTool';
|
|
|
+import {getDictLabel} from '@/utils/dict';
|
|
|
+import {pointDetailTemplate} from './mapData';
|
|
|
import {getPointInfoList} from "@/api/globalMap";
|
|
|
-import { methodList, titleList } from './data';
|
|
|
+import {methodList, titleList} from './data';
|
|
|
+
|
|
|
interface EventDetails {
|
|
|
'event_id': String;
|
|
|
'event_title': String;
|
|
@@ -24,16 +25,17 @@ interface EventDetails {
|
|
|
'latitude': String;
|
|
|
'longitude': String
|
|
|
}
|
|
|
+
|
|
|
interface Props {
|
|
|
activeMap: string;
|
|
|
pointType: [];
|
|
|
- eventDetails: EventDetails;
|
|
|
+ eventDetails?: EventDetails;
|
|
|
zoom?: number
|
|
|
}
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {});
|
|
|
-const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
-const { point_type } = toRefs<any>(proxy?.useDict('point_type'));
|
|
|
+const {proxy} = getCurrentInstance() as ComponentInternalInstance;
|
|
|
+const {point_type} = toRefs<any>(proxy?.useDict('point_type'));
|
|
|
|
|
|
const emits = defineEmits(['onLoadCompleted', 'selectGraphics', 'unSelectGraphics', 'showTextEditBox', 'onDrawCompleted', 'handleShowVideo', 'handleShowWarehouse']);
|
|
|
|
|
@@ -70,7 +72,7 @@ const mapUtils = useAMap({
|
|
|
} else {
|
|
|
map.removeLayer();
|
|
|
}
|
|
|
- drawTool.initMouseTool({ container: 'aMap', map, AMap });
|
|
|
+ drawTool.initMouseTool({container: 'aMap', map, AMap});
|
|
|
handleResize();
|
|
|
emits('onLoadCompleted')
|
|
|
},
|
|
@@ -107,7 +109,7 @@ const mapUtils = useAMap({
|
|
|
const div = document.createElement('div');
|
|
|
div.className = 'point-item point-item-hover';
|
|
|
div.innerHTML =
|
|
|
- '<div class="td4">' + getDictLabel(point_type.value, item.dataType.toString()) + '</div><div class="td4">' + item.name + '</div>';
|
|
|
+ '<div class="td4">' + getDictLabel(point_type.value, item.dataType.toString()) + '</div><div class="td4">' + item.name + '</div>';
|
|
|
div.addEventListener('click', () => {
|
|
|
handlePointDetails(item);
|
|
|
});
|
|
@@ -140,86 +142,116 @@ const {
|
|
|
handleHover,
|
|
|
creatMask,
|
|
|
trackPlayback
|
|
|
-} = { ...mapUtils };
|
|
|
+} = {...mapUtils};
|
|
|
const handlePointDetails = (data) => {
|
|
|
- let method = methodList[data.dataType];
|
|
|
- let title = !!titleList[data.dataType] ? titleList[data.dataType] : '信息';
|
|
|
- if (!method) return;
|
|
|
- method(data.id).then((res) => {
|
|
|
- if (!!pointDetailTemplate[data.dataType]) {
|
|
|
- let div = document.createElement('div');
|
|
|
- div.className = 'point-info';
|
|
|
- let titleDom = document.createElement('div');
|
|
|
- titleDom.className = 'title-box';
|
|
|
- titleDom.innerHTML = '<div class="gradient-text">' + title + '</div></div>';
|
|
|
- div.appendChild(titleDom);
|
|
|
- if (data.dataType === 2) {
|
|
|
- let btnBox = document.createElement('div');
|
|
|
- let btn = document.createElement('div');
|
|
|
- btnBox.className = 'flex';
|
|
|
- btn.className = 'btn';
|
|
|
- btn.innerHTML = '<div class="video-icon"></div><div>物资详情</div>';
|
|
|
- btn.onclick = () => {
|
|
|
- emits('handleShowWarehouse', data);
|
|
|
- };
|
|
|
- btnBox.appendChild(btn);
|
|
|
- div.appendChild(btnBox);
|
|
|
- } else if (data.dataType === 4) {
|
|
|
- let btnBox = document.createElement('div');
|
|
|
- let btn = document.createElement('div');
|
|
|
- btnBox.className = 'flex';
|
|
|
- btn.className = 'btn';
|
|
|
- btn.innerHTML = '<div class="video-icon"></div><div>附近视频</div>';
|
|
|
- btn.onclick = () => {
|
|
|
- emits('handleShowVideo', data);
|
|
|
- };
|
|
|
- btnBox.appendChild(btn);
|
|
|
- div.appendChild(btnBox);
|
|
|
+ const method = methodList[data.dataType];
|
|
|
+ if (!!method) {
|
|
|
+ // 请求接口获取详情
|
|
|
+ method(data.id).then((res) => {
|
|
|
+ if (!!pointDetailTemplate[data.dataType]) {
|
|
|
+ createInfo(data, res);
|
|
|
}
|
|
|
- let icon1 = document.createElement('div');
|
|
|
- icon1.className = 'icon1';
|
|
|
- let icon2 = document.createElement('div');
|
|
|
- icon2.className = 'icon2';
|
|
|
- let icon3 = document.createElement('div');
|
|
|
- icon3.className = 'icon3';
|
|
|
- let icon4 = document.createElement('div');
|
|
|
- icon4.className = 'icon4';
|
|
|
- div.appendChild(icon1);
|
|
|
- div.appendChild(icon2);
|
|
|
- div.appendChild(icon3);
|
|
|
- div.appendChild(icon4);
|
|
|
- let table = document.createElement('div');
|
|
|
- table.className = 'table-box';
|
|
|
- let content = '';
|
|
|
- content += '<div class="table">';
|
|
|
- const newData = filterTd(res.rows[0], data.dataType);
|
|
|
- newData.forEach((item) => {
|
|
|
- content += '<div class="point-item2">';
|
|
|
- content += '<div class="td1">' + item.data[0].label + '</div><div class="td2">' + item.data[0].value + '</div>';
|
|
|
+ });
|
|
|
+ } else if (!!pointDetailTemplate[data.detailType]) {
|
|
|
+ // 直接用现有数据展示
|
|
|
+ createInfo(data)
|
|
|
+ }
|
|
|
+};
|
|
|
+const createInfo = (data, res) => {
|
|
|
+ let dataType = '';
|
|
|
+ if (!!titleList[data.dataType]) {
|
|
|
+ dataType = data.dataType;
|
|
|
+ } else if (!!titleList[data.detailType]) {
|
|
|
+ dataType = data.detailType;
|
|
|
+ }
|
|
|
+ let title = titleList[dataType] ? titleList[dataType] : '信息';
|
|
|
+ let div = document.createElement('div');
|
|
|
+ div.className = 'point-info';
|
|
|
+ let titleDom = document.createElement('div');
|
|
|
+ titleDom.className = 'title-box';
|
|
|
+ titleDom.innerHTML = '<div class="gradient-text">' + title + '</div></div>';
|
|
|
+ div.appendChild(titleDom);
|
|
|
+ if (data.dataType === 2) {
|
|
|
+ let btnBox = document.createElement('div');
|
|
|
+ let btn = document.createElement('div');
|
|
|
+ btnBox.className = 'flex';
|
|
|
+ btn.className = 'btn';
|
|
|
+ btn.innerHTML = '<div class="video-icon"></div><div>物资详情</div>';
|
|
|
+ btn.onclick = () => {
|
|
|
+ emits('handleShowWarehouse', data);
|
|
|
+ };
|
|
|
+ btnBox.appendChild(btn);
|
|
|
+ div.appendChild(btnBox);
|
|
|
+ } else if (data.dataType === 4) {
|
|
|
+ let btnBox = document.createElement('div');
|
|
|
+ let btn = document.createElement('div');
|
|
|
+ btnBox.className = 'flex';
|
|
|
+ btn.className = 'btn';
|
|
|
+ btn.innerHTML = '<div class="video-icon"></div><div>附近视频</div>';
|
|
|
+ btn.onclick = () => {
|
|
|
+ emits('handleShowVideo', data);
|
|
|
+ };
|
|
|
+ btnBox.appendChild(btn);
|
|
|
+ div.appendChild(btnBox);
|
|
|
+ }
|
|
|
+ let icon1 = document.createElement('div');
|
|
|
+ icon1.className = 'icon1';
|
|
|
+ let icon2 = document.createElement('div');
|
|
|
+ icon2.className = 'icon2';
|
|
|
+ let icon3 = document.createElement('div');
|
|
|
+ icon3.className = 'icon3';
|
|
|
+ let icon4 = document.createElement('div');
|
|
|
+ icon4.className = 'icon4';
|
|
|
+ div.appendChild(icon1);
|
|
|
+ div.appendChild(icon2);
|
|
|
+ div.appendChild(icon3);
|
|
|
+ div.appendChild(icon4);
|
|
|
+ let table = document.createElement('div');
|
|
|
+ table.className = 'table-box';
|
|
|
+ let content = '';
|
|
|
+ content += '<div class="table">';
|
|
|
+ let newData = [];
|
|
|
+ if (res) {
|
|
|
+ newData = filterTd(res.rows[0], dataType);
|
|
|
+ } else {
|
|
|
+ newData = filterTd(data, dataType);
|
|
|
+ }
|
|
|
+ newData.forEach((item) => {
|
|
|
+ if (item.type === 'shortText') {
|
|
|
+ content += '<div class="tr">';
|
|
|
+ item.data.forEach((item2) => {
|
|
|
+ content += '<div class="point-item">';
|
|
|
+ content += '<div class="td1">' + item2.label + '</div><div class="td2">' + item2.value + '</div>';
|
|
|
content += '</div>';
|
|
|
});
|
|
|
content += '</div>';
|
|
|
- table.innerHTML = content;
|
|
|
- div.appendChild(table);
|
|
|
- let closeBtn = document.createElement('div');
|
|
|
- closeBtn.className = 'close';
|
|
|
- closeBtn.onclick = hideInfo;
|
|
|
- div.appendChild(closeBtn);
|
|
|
- showInfo(div, [data.longitude, data.latitude], true);
|
|
|
+ } else {
|
|
|
+ content += '<div class="point-item2">';
|
|
|
+ content += '<div class="td1">' + item.data[0].label + '</div><div class="td2">' + item.data[0].value + '</div>';
|
|
|
+ content += '</div>';
|
|
|
}
|
|
|
});
|
|
|
-};
|
|
|
+ content += '</div>';
|
|
|
+ table.innerHTML = content;
|
|
|
+ div.appendChild(table);
|
|
|
+ let closeBtn = document.createElement('div');
|
|
|
+ closeBtn.className = 'close';
|
|
|
+ closeBtn.onclick = hideInfo;
|
|
|
+ div.appendChild(closeBtn);
|
|
|
+ showInfo(div, [data.longitude, data.latitude], true);
|
|
|
+}
|
|
|
const filterTd = (obj, dataType) => {
|
|
|
let data = [];
|
|
|
let tempData = {};
|
|
|
let i = 0;
|
|
|
- for (let key in obj) {
|
|
|
- let keyLabel = pointDetailTemplate[dataType][key];
|
|
|
+ const pointDetailTemplateObj = pointDetailTemplate[dataType];
|
|
|
+ Object.keys(pointDetailTemplateObj).forEach((key) => {
|
|
|
+ let keyLabel = pointDetailTemplateObj[key];
|
|
|
if (!!keyLabel) {
|
|
|
if (i === 2) {
|
|
|
i = 0;
|
|
|
}
|
|
|
- const value = !!obj[key] ? obj[key] : '';
|
|
|
+ const value = !!obj && !!obj[key] ? obj[key] : '';
|
|
|
if (value && value.length > 8) {
|
|
|
if (i === 0) {
|
|
|
data.push({ type: 'longText', data: [{ label: keyLabel, value: value }] });
|
|
@@ -228,7 +260,11 @@ const filterTd = (obj, dataType) => {
|
|
|
tempData = { type: 'longText', data: [{ label: keyLabel, value: value }] };
|
|
|
}
|
|
|
} else {
|
|
|
- data[data.length - 1].data.push({ label: keyLabel, value: value });
|
|
|
+ if (i === 0) {
|
|
|
+ data.push({ type: 'shortText', data: [{ label: keyLabel, value: value }] });
|
|
|
+ } else {
|
|
|
+ data[data.length - 1].data.push({ label: keyLabel, value: value });
|
|
|
+ }
|
|
|
i++;
|
|
|
if (!!tempData && JSON.stringify(tempData) !== '{}') {
|
|
|
data.push(tempData);
|
|
@@ -237,18 +273,21 @@ const filterTd = (obj, dataType) => {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
if (!!tempData && JSON.stringify(tempData) !== '{}') {
|
|
|
data.push(tempData);
|
|
|
}
|
|
|
+ if (data[data.length - 1].data && data[data.length - 1].data.length === 1 && data[data.length - 1].type === 'shortText') {
|
|
|
+ data[data.length - 1].type = 'longText';
|
|
|
+ }
|
|
|
return data;
|
|
|
};
|
|
|
// 监听地图类型变化
|
|
|
watch(
|
|
|
- () => props.activeMap,
|
|
|
- () => {
|
|
|
- switchMap(props.activeMap);
|
|
|
- }
|
|
|
+ () => props.activeMap,
|
|
|
+ () => {
|
|
|
+ switchMap(props.activeMap);
|
|
|
+ }
|
|
|
);
|
|
|
|
|
|
watch(() => props.eventDetails, () => {
|
|
@@ -265,7 +304,17 @@ const getMapUtils = () => {
|
|
|
const getDrawTool = () => {
|
|
|
return mapUtils.getDrawTool();
|
|
|
};
|
|
|
-defineExpose({ getDrawTool, getMapUtils, addMarker, addSearchMarker, getMarkers, clearMarker, getMap, drawTool, handleHover });
|
|
|
+defineExpose({
|
|
|
+ getDrawTool,
|
|
|
+ getMapUtils,
|
|
|
+ addMarker,
|
|
|
+ addSearchMarker,
|
|
|
+ getMarkers,
|
|
|
+ clearMarker,
|
|
|
+ getMap,
|
|
|
+ drawTool,
|
|
|
+ handleHover
|
|
|
+});
|
|
|
const handleResize = () => {
|
|
|
map.resize();
|
|
|
};
|
|
@@ -280,12 +329,14 @@ onUnmounted(() => {
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
@import 'map.scss';
|
|
|
+
|
|
|
.map-container2 {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
position: relative;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
+
|
|
|
.map-container {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
@@ -294,6 +345,7 @@ onUnmounted(() => {
|
|
|
:deep(.amap-copyright) {
|
|
|
display: none !important;
|
|
|
}
|
|
|
+
|
|
|
:deep(.amap-marker-label) {
|
|
|
border: 1px solid #474747;
|
|
|
background-color: rgba(255, 255, 255, 0.65);
|