forked from drone/command-center-dashboard

chenyao
2025-04-12 80790ccc8b8ee6ac8db201f0f6c2d136fefd5a69
Merge branch 'master' of http://139.196.74.78:10010/r/drone/command-center-dashboard
1 files modified
95 ■■■■■ changed files
src/views/Home/useMapAggregation/useMapAggregation.js 95 ●●●●● patch | view | raw | blame | history
src/views/Home/useMapAggregation/useMapAggregation.js
@@ -16,6 +16,14 @@
/**
 * 机巢聚合功能
 */
let arrColor = ["rgb(15,176,255)", "rgb(18,76,154)", "#40C4E4", "#42B2BE", "rgb(51,176,204)", "#8CB7E5", "rgb(0,244,188)", "#139FF0"]
let index = 0
function getColor () {
  return arrColor[++index % arrColor.length]
}
export const useMapAggregation = type => {
  const { flyTo } = cesiumOperation()
@@ -266,6 +274,25 @@
        entities.forEach((entity, index) => {
          // 创建独立折线作为轮廓
          const positions = entity.polygon.hierarchy.getValue().positions
          const randomInt = Math.floor(Math.random() * 5) + 1
          let polygon = {}
          if (item.name == '县') {
            let material = new PolyGradientMaterial({
              color: Cesium.Color.fromCssColorString(arrColor[randomInt]),
              opacity: 0.7,
              alphaPower: 1.3
            })
            entity.polygon.extrudedHeight = (entity.properties.childrenNum._value || 1) * 500
            entity.polygon.material = material
            polygon = entity.polygon
            entity.polygon.outline = false // 显示边框
          }
          viewer.entities.add({
            id: `aggregation-outline-${index}`,
            polyline: {
@@ -276,6 +303,8 @@
                color: Cesium.Color.AQUA,
              }),
            },
            polygon
          })
        })
      })
@@ -296,7 +325,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}`,
@@ -336,17 +365,8 @@
      })
    })
    let arrColor = ["rgb(15,176,255)", "rgb(18,76,154)", "#40C4E4", "#42B2BE", "rgb(51,176,204)", "#8CB7E5", "rgb(0,244,188)", "#139FF0"]
    let index = 0
    function getColor () {
      return arrColor[++index % arrColor.length]
    }
    // 加载边界
    Cesium.GeoJsonDataSource.load(item.gJson).then(dataSource => {
      console.log(dataSource, item.gJson)
      viewer.dataSources.add(dataSource)
      item.BJDataSource = dataSource // 保存数据源以便后续删除
      // 获取数据源中的实体
@@ -402,36 +422,41 @@
    }
  }
  /**
   * 根据条件获取项
   * @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
    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')
    const curEntity = deviceAggregationFind || deviceFind || eventFind
    if (!curEntity) return
    currentEntity = curEntity
    const entityPosition = curEntity?.position?._value
    if (!entityPosition) return
    if (entityPosition) {
      positionC3 = entityPosition
    }
    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' })
    }
  }
@@ -457,7 +482,7 @@
  }
  // 移除弹框标签
  const removeLabel = () => {
    viewer.scene.postRender.removeEventListener(labelBoxRender)
    viewer?.scene.postRender.removeEventListener(labelBoxRender)
    removeDom()
  }