From bb9b31d8abc6578fa451cc545658115d0da4ff50 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Sat, 12 Apr 2025 13:36:09 +0800
Subject: [PATCH] feat: 更换返回按钮
---
src/views/Home/useMapAggregation/useMapAggregation.js | 66 ++++++++++++++------------------
1 files changed, 29 insertions(+), 37 deletions(-)
diff --git a/src/views/Home/useMapAggregation/useMapAggregation.js b/src/views/Home/useMapAggregation/useMapAggregation.js
index fe993cf..8678176 100644
--- a/src/views/Home/useMapAggregation/useMapAggregation.js
+++ b/src/views/Home/useMapAggregation/useMapAggregation.js
@@ -48,7 +48,6 @@
let viewer = null
let active = null
let handler = null
- let positionC3 = null
let currentEntity = null
const store = useStore()
@@ -293,7 +292,7 @@
entity.polygon.outline = false // 显示边框
}
- let curEntity = viewer.entities.add({
+ viewer.entities.add({
id: `aggregation-outline-${index}`,
polyline: {
positions: positions,
@@ -305,11 +304,6 @@
},
polygon
- })
-
- item.name == '县' && viewer.flyTo(curEntity, {
- offset: new Cesium.HeadingPitchRange(0, Cesium.Math.toRadians(-60), 0),
- duration: 0.5,
})
})
})
@@ -330,7 +324,7 @@
// 遍历特征并添加实体
featuresList.forEach((feature, index) => {
if (!feature.position) return
- const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 12000)
+ const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1], 0)
viewer.entities.add({
position: position,
id: `aggregation-name-${index}`,
@@ -415,11 +409,12 @@
// 弹框位置刷新
const labelBoxRender = () => {
+ if (!currentEntity) return
let dom = document.querySelector('#mapPopUpBox')
if (!dom) {
dom = getLabelDom(currentEntity.properties.customData._value.data)
}
- const screenPosition = viewer.scene.cartesianToCanvasCoordinates(positionC3)
+ const screenPosition = viewer.scene.cartesianToCanvasCoordinates(currentEntity?.position?._value)
if (screenPosition) {
dom.style.left = `${screenPosition.x}px`
dom.style.top = `${screenPosition.y}px`
@@ -427,36 +422,34 @@
}
}
+ /**
+ * 根据条件获取项
+ * @param {Array} arr 数据源
+ * @param {Function} condition 条件
+ * @returns
+ */
+ const findTypeItem = (arr, condition) => {
+ return arr.find(item => condition(item))
+ }
+
// 左键单机事件
const singleMachineEvent = async click => {
- const pickedObject = viewer.scene.pick(click.position)
- if (!(Cesium.defined(pickedObject) && pickedObject.id)) return
- const entity = pickedObject.id
- currentEntity = entity
- const entityPosition = entity?.position?._value
- if (!entityPosition) return
- if (entityPosition) {
- positionC3 = entityPosition
- }
+ let clickTargets = viewer.scene.drillPick(click.position).map(item => item.id)
+ if (!clickTargets.length) return
+
+ let deviceAggregationFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'deviceAggregation')
+ let deviceFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'device')
+ let eventFind = findTypeItem(clickTargets, (item) => item?.properties?.customData?._value?.data?.type === 'event')
+ currentEntity = deviceAggregationFind || deviceFind || eventFind
+ if (!currentEntity) return
+ if (!currentEntity?.position?._value) return
+ // 一定要移除
removeLabel()
- const customData = entity?.properties?.customData?._value?.data
- if (!customData) return
- console.log('customData', customData)
- switch (customData.type) {
- case 'deviceAggregation':
- viewer.scene.postRender.addEventListener(labelBoxRender)
- break
- // todo 待对接
- case 'device':
- store.commit('setSingleUavHome', { id: '123' })
- break
- case 'eventAggregation':
- break
- case 'event':
- viewer.scene.postRender.addEventListener(labelBoxRender)
- break
- default:
- break
+ if (deviceAggregationFind || eventFind) {
+ viewer.scene.postRender.addEventListener(labelBoxRender)
+ }
+ if (deviceFind) {
+ store.commit('setSingleUavHome', { id: '123' })
}
}
@@ -498,7 +491,6 @@
viewer = null
active = null
handler = null
- positionC3 = null
currentEntity = null
}
const init = () => {
--
Gitblit v1.9.3