<!--
|
* @Author: shuishen 1109946754@qq.com
|
* @Date: 2024-10-25 15:07:51
|
* @LastEditors: shuishen 1109946754@qq.com
|
* @LastEditTime: 2025-04-28 11:34:40
|
* @FilePath: \drone-web-manage\src\components\map-container\mapContainer.vue
|
* @Description:
|
*
|
* Copyright (c) 2024 by shuishen, All Rights Reserved.
|
-->
|
<template>
|
<div class="map-container">
|
<div class="viewer-container ztzf-cesium" id="viewer-container">
|
<div class="content">
|
<slot name="content"></slot>
|
</div>
|
|
<PlanarRouteLineList :curRouteLineData="curRouteLineData" @routeLineListClick="routeLineListClick" />
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import PlanarRouteLineList from '@/components/PlanarRouteLineList/PlanarRouteLineList.vue'
|
|
import * as Cesium from 'cesium'
|
import { Cartesian3, Terrain, Viewer } from 'cesium'
|
import { PublicCesium } from '@/utils/cesium/publicCesium'
|
import ImageTrailMaterial from '@/utils/cesium/ImageTrailMaterial'
|
import { flyVisual } from '@/utils/cesium/mapUtil'
|
import * as turf from '@turf/turf'
|
|
import { nextTick, onBeforeUnmount, onMounted, onUnmounted } from 'vue'
|
import { read } from 'xlsx'
|
|
import startPng from '@/assets/map_images/Startingpointicon.png'
|
import endPng from '@/assets/map_images/EndPointicon.png'
|
import rwqfdImg from '@/assets/images/task/arrow-right-blue.png'
|
import newNumPoint from '@/assets/images/task/custom-point.png'
|
|
import { useRouteLine } from '@/hooks/useRouteLine/useRouteLine.js'
|
|
// 加载航线hook
|
const { curRouteLineData, routeLineListClick, initViewer, renderPreviewLine } = useRouteLine()
|
|
let publicCesiumInstance = null
|
let viewer = null
|
|
const { VITE_APP_BASE } = import.meta.env
|
// import * as Cesium from 'cesium'
|
// import 'cesium/Build/Cesium/Widgets/widgets.css'
|
const isViewerReady = ref(false)
|
const { rowDetails } = defineProps({
|
rowDetails: {
|
type: Object,
|
default: () => ({}),
|
}
|
})
|
|
async function initMap () {
|
if (viewer) return
|
publicCesiumInstance = new PublicCesium({ dom: 'viewer-container' })
|
viewer = publicCesiumInstance.getViewer()
|
|
initViewer(viewer)
|
isViewerReady.value = true
|
}
|
|
/**
|
* 初始化标注添加
|
* @param type 类型
|
* @param data 数据
|
*/
|
const initAddEntity = (type, data) => {
|
watch(() => isViewerReady.value,
|
(ready) => {
|
if (ready) {
|
viewer.entities.removeAll()
|
|
type === 'point' ? addPoint(data) : addPolyline(data)
|
}
|
},
|
{ deep: true, immediate: true } // 初始化时立即执行
|
)
|
}
|
|
/**
|
* 添加点标注
|
* @param data 数据 数据格式 [lng, lat]
|
*/
|
function addPoint (data) {
|
const [lng, lat] = data
|
|
if (!lng || !lat) return
|
|
viewer.entities.add({
|
position: Cartesian3.fromDegrees(lng, lat),
|
point: {
|
pixelSize: 10,
|
color: Cesium.Color.BLUE,
|
outlineColor: Cesium.Color.WHITE,
|
outlineWidth: 2
|
}
|
})
|
|
// 定位到点位
|
const points = [[lng, lat]] // 确保格式为二维数组
|
flyVisual(points, viewer, 4)
|
}
|
|
/**
|
* 添加点标注
|
* @param data 数据 数据格式 [[lng, lat], [lng, lat], [lng, lat]]
|
*/
|
async function addPolyline (data) {
|
await renderPreviewLine(data.url, data.type, data.cb)
|
}
|
|
onMounted(() => {
|
nextTick(() => {
|
initMap()
|
})
|
})
|
|
onBeforeUnmount(() => {
|
var cesiumContainer = document.getElementById('viewer-container')
|
if (cesiumContainer) {
|
cesiumContainer.remove() // 移除与地图相关的DOM元素
|
}
|
|
viewer.entities.removeAll()
|
publicCesiumInstance.viewerDestroy()
|
viewer = null
|
|
})
|
|
defineExpose({
|
initAddEntity
|
})
|
</script>
|
|
<script>
|
export default {
|
name: 'MapContainer'
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.map-container {
|
position: relative;
|
width: 100% !important;
|
height: 100% !important;
|
overflow: hidden;
|
}
|
|
.viewer-container {
|
position: absolute;
|
top: 0%;
|
left: 0%;
|
width: 100%;
|
height: 100%;
|
}
|
</style>
|