<template>
|
<div id="currentTaskMap"></div>
|
</template>
|
<script setup>
|
import * as Cesium from 'cesium'
|
import AmapMercatorTilingScheme from '@/utils/cesium/AmapMercatorTilingScheme'
|
import { Cartesian3, Terrain, Viewer } from 'cesium'
|
import endPointImg from '@/assets/images/EndPointicon.png'
|
import startPointImg from '@/assets/images/Startingpointicon.png'
|
import { addBlueFilter } from '@/utils/cesium/common'
|
import { analyzeKmzFile, removeTextKey, XMLToJSON } from '@/utils/cesium/kmz'
|
import rwqfdImg from '@/assets/images/signMachineNest/rwqfd.png'
|
import ImageTrailMaterial from '@/utils/cesium/ImageTrailMaterial'
|
import lineImg from '@/assets/images/arrow-right-blue.png'
|
import { flyVisual } from '@/utils/cesium/mapUtil'
|
import CreateFrustum from '@/utils/cesium/frustum/CreateFrustum'
|
|
const imageryProvider_ammapSL = new Cesium.UrlTemplateImageryProvider({
|
url: 'https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
|
layer: 'tdtVecBasicLayer',
|
style: 'default',
|
format: 'image/png',
|
tileMatrixSetID: 'GoogleMapsCompatible',
|
subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
|
maximumLevel: 18,
|
tilingScheme: new AmapMercatorTilingScheme(),
|
credit: 'amap_SL',
|
})
|
let viewer = null
|
const taskDetails = inject('taskDetails')
|
const deviceOsdInfo = inject('deviceOsdInfo')
|
|
const initMap = () => {
|
viewer = new Viewer('currentTaskMap', {
|
terrain: Terrain.fromWorldTerrain(),
|
infoBox: false, // 禁用沙箱,解决控制台报错
|
animation: false, // 左下角的动画仪表盘
|
baseLayerPicker: false, // 右上角的图层选择按钮
|
geocoder: false, // 搜索框
|
homeButton: false, // home按钮
|
sceneModePicker: false, // 模式切换按钮
|
timeline: false, // 底部的时间轴
|
navigationHelpButton: false, // 右上角的帮助按钮,
|
selectionIndicator: false, // 是否显示选择指示器
|
baseLayer: false,
|
fullscreenButton: false,
|
})
|
const gdLayer = viewer.imageryLayers.addImageryProvider(imageryProvider_ammapSL)
|
const options = {
|
bInvertColor: true,
|
bFilterColor: true,
|
filterColor: '#4e70a6',
|
}
|
// 添加蓝色滤镜
|
addBlueFilter(options, viewer, gdLayer)
|
viewer.scene.morphTo2D(0)
|
//设置默认点
|
viewer.camera.setView({
|
destination: Cartesian3.fromDegrees(115.763819, 28.787374, 5000),
|
})
|
}
|
|
const drawWayline = lineObj => {
|
const positions = lineObj.Placemark.map(item => {
|
const [lon, lat] = item.Point.coordinates.split(',')
|
return Cartesian3.fromDegrees(Number(lon), Number(lat))
|
})
|
// 起点
|
viewer.entities.add({
|
position: positions[0],
|
billboard: {
|
image: new Cesium.ConstantProperty(rwqfdImg),
|
width: 70,
|
height: 70,
|
},
|
})
|
// 终点
|
viewer.entities.add({
|
position: positions[positions.length - 1],
|
billboard: {
|
image: new Cesium.ConstantProperty(endPointImg),
|
width: 30,
|
height: 30,
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 底部对齐
|
},
|
})
|
// 路径线
|
viewer.entities.add({
|
polyline: {
|
width: 4,
|
positions: positions,
|
material: new ImageTrailMaterial({
|
color: { alpha: 1, blue: 1, green: 1, red: 1 },
|
speed: 20,
|
image: lineImg,
|
repeat: { x: Math.floor(40), y: 1 },
|
}),
|
clampToGround: false,
|
},
|
})
|
}
|
|
// 解析kmz文件
|
const parsingFiles = async url => {
|
const res = await analyzeKmzFile(`${url}?_t=${new Date().getTime()}`)
|
const waylinesXML = await res.fileInfoObj['wpmz/waylines.wpml']
|
const waylinesXMLJSON = XMLToJSON(waylinesXML)?.['Document']
|
const waylinesXMLObj = removeTextKey(waylinesXMLJSON.Folder)
|
if (!waylinesXMLObj.Placemark.length) return
|
const allPoint = waylinesXMLObj.Placemark.map(item => item.Point.coordinates.split(','))
|
flyVisual(allPoint, viewer)
|
drawWayline(waylinesXMLObj)
|
}
|
|
const removeMap = () => {
|
viewer.entities.removeAll()
|
viewer.destroy()
|
}
|
|
let viewInfoFrustum
|
// 设置视椎
|
const setCreateFrustum = () => {
|
const deviceInfo = deviceOsdInfo.value?.data?.host
|
if (!deviceInfo) return
|
viewInfoFrustum?.clear()
|
if ([14, 0].includes(deviceInfo.mode_code)) return
|
const attitude_head = 180 + deviceInfo.attitude_head
|
const gimbal_pitch = 90 - Number(deviceInfo?.payloads[0]?.gimbal_pitch) || 0
|
viewInfoFrustum = new CreateFrustum(viewer, {
|
position: {
|
longitude: deviceInfo.longitude,
|
latitude: deviceInfo.latitude,
|
altitude: deviceInfo.height,
|
},
|
width: 30,
|
height: 30,
|
fov: 20.0,
|
near: 3.0,
|
far: 250.0,
|
roll: gimbal_pitch,
|
pitch: 0,
|
heading: attitude_head,
|
})
|
}
|
|
watch(deviceOsdInfo, setCreateFrustum)
|
watch(taskDetails, () => {
|
if (taskDetails.value.way_lines.length) {
|
parsingFiles(taskDetails.value.way_lines[0].url)
|
}
|
})
|
onBeforeUnmount(() => {
|
removeMap()
|
})
|
|
onMounted(() => {
|
nextTick(() => {
|
initMap()
|
})
|
})
|
</script>
|
<style scoped lang="scss">
|
#currentTaskMap {
|
|
:deep() {
|
.cesium-viewer {
|
width: 100%;
|
height: 100%;
|
overflow: hidden;
|
|
.cesium-viewer-cesiumWidgetContainer {
|
width: 100%;
|
height: 100%;
|
|
.cesium-widget {
|
width: 100%;
|
height: 100%;
|
|
canvas {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
}
|
}
|
|
.cesium-viewer-bottom {
|
display: none;
|
}
|
}
|
}
|
</style>
|