From a51171f691ec516929fbb29356ad9074d0439b6e Mon Sep 17 00:00:00 2001
From: GuLiMmo <2820890765@qq.com>
Date: Thu, 07 Mar 2024 17:32:45 +0800
Subject: [PATCH] update: 右键新增航线、事件编辑、kmz文件编辑
---
src/pages/page-web/projects/components/route-edit/index.vue | 212 +++++++++++++++++++---------------------------------
1 files changed, 78 insertions(+), 134 deletions(-)
diff --git a/src/pages/page-web/projects/components/route-edit/index.vue b/src/pages/page-web/projects/components/route-edit/index.vue
index c568d50..ea4e04e 100644
--- a/src/pages/page-web/projects/components/route-edit/index.vue
+++ b/src/pages/page-web/projects/components/route-edit/index.vue
@@ -7,17 +7,14 @@
</template>
返回
</a-button>
- <div class="save-button">
+ <div class="save-button" @click="saveWaylineFile">
<SaveOutlined />
</div>
<setting v-model:loadCompleted="loadCompleted">
<template #show>
<a-button type="text" class="setting-btn">
<div class="router-setting">
- <img
- class="wayline-icon"
- :src="getResource('wayline.png')"
- alt="icon" />
+ <img class="wayline-icon" :src="getResource('wayline.png')" alt="icon" />
<span class="text">航线设置</span>
<CaretDownOutlined />
</div>
@@ -26,10 +23,7 @@
</setting>
</div>
<div class="wayline-info">
- <div
- class="info-box"
- v-for="(item, index) in waylineDetails"
- :key="index">
+ <div class="info-box" v-for="(item, index) in waylineDetails" :key="index">
<div class="title">{{ item.title }}</div>
<div class="info">{{ item.value }}</div>
</div>
@@ -45,10 +39,7 @@
<div class="right">{{ index + 1 }}</div>
</div>
<div class="graph-right">
- <div
- v-for="(event, index) in item.eventList"
- :key="index"
- class="s-event-icon">
+ <div v-for="(event, index) in item.eventList" :key="index" class="s-event-icon">
<a-tooltip placement="top">
<template #title>
{{ event.name }}
@@ -66,24 +57,23 @@
import _ from 'lodash'
import * as Cesium from 'cesium'
import setting from './components/setting.vue'
-import useKmzTsa from '/@/utils/cesium/use-kmz-tsa'
+import useKmzTsa, { kmlStr } from '/@/utils/cesium/use-kmz-tsa'
import { ref, reactive, defineEmits, defineProps, watch, onMounted } from 'vue'
import { ArrowLeftOutlined, CaretDownOutlined, SaveOutlined } from '@ant-design/icons-vue'
import { cesiumOperation } from '/@/hooks/use-cesium-tsa'
import { useMyStore } from '/@/store'
import ImageTrailMaterial from '/@/utils/cesium/ImageTrailMaterial'
-import useMapDraw from '/@/utils/cesium/use-map-draw'
+import useMapDraw, { kmlEntities as globalEntities } from '/@/utils/cesium/use-map-draw'
+import { getKmlParams } from '/@/utils/cesium/kmz'
+import { getHaeHeight } from '/@/utils/cesium/mapUtils'
const store = useMyStore()
const { appContext }: any = getCurrentInstance()
const global = appContext.config.globalProperties
-const {
- removeAllPoint,
- getEntityById,
- addPolyline,
- addRightClick,
- removeRightClickEvent,
-} = cesiumOperation()
+const kmzUtils = useKmzTsa()
+
+const { removeAllPoint, getEntityById, addPolyline, removeAllDataSource, addRightClick, removeRightClickEvent } =
+ cesiumOperation()
interface waylineDetails {
title: string
@@ -116,15 +106,12 @@
const tragetPointArr = ref<tragetPoint[]>([])
-let kmlDataSource:
- | { entities: { values: { _children: any }[] }; show: boolean }
- | null
- | any = null
+let kmlDataSource: { entities: { values: { _children: any }[] }; show: boolean } | null | any = null
let mouseRightClickEvent: any = null
// 绘制地图上的东西
-let mapDraw = null
+let mapDraw: any = null
// 航线详情
const waylineDetails = ref<waylineDetails[]>([])
// 样式
@@ -141,31 +128,29 @@
if (kmlDataSource) {
global.$viewer.dataSources.remove(kmlDataSource)
}
- global.$viewer.dataSources
- .add(Cesium.KmlDataSource.load(filePath.value, options))
- .then((res: any) => {
- kmlDataSource = res
- mapDraw = useMapDraw(kmlDataSource, [], filePath.value, global)
- const {
- drawWayline,
- waylineDetails: details,
- waylinePointsEvent,
- kmlEntities: entities,
- clearWaylineData
- } = mapDraw
- clearWaylineData()
- drawWayline()
- useKmzTsa().init(filePath.value).then(kmlRes => {
- loadCompleted.value = true
- })
- waylineDetails.value = details
- tragetPointArr.value = waylinePointsEvent.value
- kmlEntities.value = entities.value
- if (!mouseRightClickEvent) {
- // 添加右键事件
- addMapPointEvent()
- }
+ global.$viewer.dataSources.add(Cesium.KmlDataSource.load(filePath.value, options)).then((res: any) => {
+ kmlDataSource = res
+ mapDraw = useMapDraw(kmlDataSource, [], filePath.value, global)
+ const {
+ drawWayline,
+ waylineDetails: details,
+ waylinePointsEvent,
+ kmlEntities: entities,
+ clearWaylineData,
+ } = mapDraw
+ clearWaylineData()
+ drawWayline()
+ kmzUtils.init(filePath.value).then((kmlRes) => {
+ loadCompleted.value = true
})
+ waylineDetails.value = details
+ tragetPointArr.value = waylinePointsEvent.value
+ kmlEntities.value = entities.value
+ if (!mouseRightClickEvent) {
+ // 添加右键事件
+ addMapPointEvent()
+ }
+ })
}
// const createPointOrPolyline = () => {}
@@ -219,12 +204,7 @@
const nextPoint = points[index + 1]?.position
if (prevPoint) {
// 获取中心点
- const centerPoint = Cesium.Cartesian3.lerp(
- currentPoint,
- prevPoint,
- 0.5,
- new Cesium.Cartesian3(),
- )
+ const centerPoint = Cesium.Cartesian3.lerp(currentPoint, prevPoint, 0.5, new Cesium.Cartesian3())
// 获取两个点之间的距离
let distance = Cesium.Cartesian3.distance(currentPoint, prevPoint)
distance = Math.round(distance)
@@ -232,12 +212,7 @@
}
if (nextPoint) {
// 获取中心点
- const centerPoint = Cesium.Cartesian3.lerp(
- currentPoint,
- nextPoint,
- 0.5,
- new Cesium.Cartesian3(),
- )
+ const centerPoint = Cesium.Cartesian3.lerp(currentPoint, nextPoint, 0.5, new Cesium.Cartesian3())
// 获取两个点之间的距离
let distance = Cesium.Cartesian3.distance(currentPoint, nextPoint)
distance = Math.round(distance)
@@ -274,13 +249,8 @@
title: `在${Number(selectPointIndex.value) + 1}号航点前插入`,
},
]
- const defaultEvents = [
- { class: 'finally-point', title: '在最后航点新增航点' },
- ]
- const events =
- selectPointIndex.value !== null
- ? [...defaultEvents, ...pointEvents]
- : defaultEvents
+ const defaultEvents = [{ class: 'finally-point', title: '在最后航点新增航点' }]
+ const events = selectPointIndex.value !== null ? [...defaultEvents, ...pointEvents] : defaultEvents
popupDom = createPointPopupDom(events)
global.$viewer.container.appendChild(popupDom)
popupDom.style.transform = `translate3d(${x}px, ${y}px, 0)`
@@ -330,84 +300,53 @@
`
return pointPopup
}
+
// 给DOM添加点击事件
const addMenuEvent = (dom: HTMLElement, position: Cesium.Cartesian2) => {
dom.addEventListener('click', (e: any) => {
removeCesiumChildDom(popupDom)
const className = e.target.className
- const c3Position = global.$viewer.scene.globe.pick(
- global.$viewer.camera.getPickRay(position),
- global.$viewer.scene,
- )
+ const c3Position = global.$viewer.scene.globe.pick(global.$viewer.camera.getPickRay(position), global.$viewer.scene)
const c2Postion = ellipsoid.cartesianToCartographic(c3Position)
const longitude = Cesium.Math.toDegrees(c2Postion.longitude)
const latitude = Cesium.Math.toDegrees(c2Postion.latitude)
- const height = 70
- const createPointPosition = Cesium.Cartesian3.fromDegrees(
- longitude,
- latitude,
+ // 获取全局高度
+ const globalHeight: any = getKmlParams(kmlStr.value, true, {
+ name: 'globalHeight',
+ findRegx: '([\\s\\S]*?)',
+ })
+ const height = Number(globalHeight[1])
+ const createPointPosition = Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
+ const entity: Cesium.Entity = global.$viewer.entities.add({
+ position: createPointPosition,
+ })
+ // 加入kml文件中
+ const setting = {
+ Point: {
+ coordinates: `${longitude},${latitude}`,
+ },
+ index: tragetPointArr.value.length,
height,
- )
- let entity: Cesium.Entity | any = null
+ ellipsoidHeight: height,
+ }
if (className === 'finally-point') {
- entity = global.$viewer.entities.add({
- position: createPointPosition,
- label: {
- text: 'ASL:70m',
- font: '13px monospace',
- showBackground: true,
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
- disableDepthTestDistance: Number.POSITIVE_INFINITY,
- pixelOffset: new Cesium.Cartesian2(0, -40),
- },
- billboard: {
- image: createBillboard(tragetPointArr.value.length + 1, '#61d396'),
- pixelOffset: new Cesium.Cartesian2(0, -20),
- },
- point: {
- pixelSize: 20,
- color: Cesium.Color.GHOSTWHITE,
- outlineColor: Cesium.Color.BLACK,
- },
- })
- const prePostion =
- tragetPointArr.value[tragetPointArr.value.length - 1].position
- const polylinePositions = [prePostion, createPointPosition]
- addPolyline({
- polyline: {
- positions: polylinePositions,
- width: 7,
- material: new ImageTrailMaterial({
- backgroundColor: Cesium.Color.fromBytes(96, 210, 149),
- image: getResource('arrow-right.png'),
- imageW: 7,
- duration: 0,
- animation: false,
- }),
- clampToGround: false, // 关闭贴地效果,保留高度
- },
- })
- addPolyline({
- polyline: {
- positions: Cesium.Cartesian3.fromDegreesArrayHeights([
- longitude,
- latitude,
- height,
- longitude,
- latitude,
- 0,
- ]),
- width: 1,
- material: new Cesium.PolylineDashMaterialProperty({
- color: Cesium.Color.WHITE,
- }),
- },
- })
+ removeAllDataSource()
+ removeAllPoint()
+ kmzUtils.writePoint(setting)
+ globalEntities.value.push(entity)
+ mapDraw.drawWayline(globalEntities.value, kmlStr.value)
tragetPointArr.value.push({
position: createPointPosition,
eventList: [],
})
+ }
+ if (className === 'add-prev-point') {
+ // console.log(1)
+ }
+ if (className === 'add-next-point') {
+ // const index = selectPointIndex.value
+ // globalEntities.value.splice(index, 0, entity)
+ // console.log()
}
// clearCesiumMap()
// createMapMarker(undefined, [...kmlEntities.value, entity])
@@ -437,6 +376,11 @@
}
}
+// 保存文件
+const saveWaylineFile = () => {
+ kmzUtils.save()
+}
+
onMounted(() => {
// 清空画布
clearCesiumMap()
--
Gitblit v1.9.3