智慧园区前端大屏
shuishen
2024-12-02 b67f46b4a768b4cd72d4e463c5dffefe977ddeb7
src/views/pd/components/dynamicPanel.vue
@@ -2,7 +2,7 @@
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-11-09 15:41:35
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-11-26 01:09:57
 * @LastEditTime: 2024-12-02 21:53:13
 * @FilePath: \bigScreen\src\views\pd\components\dynamicPanel.vue
 * @Description: 
 * 
@@ -46,8 +46,8 @@
        lng: 115.10343807,
        lat: 27.27256126
      },
      linePosition: '115.10341051,27.27251643,80;115.10357817,27.27278003,80',
      lineTime: 10000,
      linePosition: '115.10341051,27.27251643,64;115.10357817,27.27278003,64',
      lineTime: 5000,
      threeContent: '关闭绿源污水处理厂旁雨水排口,拦截污染水体。',
      threePointPosition: {
@@ -65,8 +65,8 @@
      fiveContent: '应急指挥部指导企业处理受污染废水, 监测公共应急池水质 ,确保达标后安全转运至绿源污水处理厂。',
      fivePointPosition: {
        lng: 115.10845441,
        lat: 27.27327366
        lng: 115.10843364,
        lat: 27.27320219
      },
      fivetime: 25000,
    },
@@ -83,10 +83,10 @@
      onetime: 0,
      lineCenter: {
        lng: 115.10343807,
        lat: 27.27256126
        lng: 115.10627858,
        lat: 27.29434439
      },
      linePosition: '115.10626847,27.29410411,80;115.10626769,27.29453267,80',
      linePosition: '115.10627726,27.29408853,64;115.10627703,27.29456132,64',
      lineTime: 5000,
      twoContent: '园区关闭北区雨水排口,拦截污染水体。',
@@ -96,10 +96,10 @@
      },
      twotime: 10000,
      threeContent: '园区启用北区公共应急池,将已拦截废水泵入应急池。',
      threeContent: '园区启用北区公共应急池(拟建),将已拦截废水泵入应急池。',
      threePointPosition: {
        lng: 115.10418532,
        lat: 27.29444603
        lng: 115.106600,
        lat: 27.296891
      },
      threetime: 15000,
@@ -122,107 +122,220 @@
      title: '典型案例3',
      content: '危险化学品运输事故: 北片区某企业的危化品运输车辆发生侧翻,大量盐酸流至路面,如不采取措施,将造成污染事故,影响到赣江下游水质。',
      showModel: true,
      oneCentent: '2024年09月16日14时,北片区某公司的危化品运输车辆发生侧翻,大量盐酸流至路面。',
      onePointPosition: {
        lng: 115.10248629,
        lat: 27.28112873
        lng: 115.10639786,
        lat: 27.28116943
      },
      onetime: 0,
      onetime: 8000,
      twoContent: '调度金龙水库清水,稀释污染团。',
      twoPointPosition: {
        lng: 115.10488545,
        lat: 27.27678110
      },
      twotime: 0,
      twotime: 13000,
      threeContent: '转输至江西粤鹏环保高新技术开发有限公司事故应急池、初期雨水池。',
      threePointPosition: {
        lng: 115.10545135,
        lat: 27.28043872
      },
      threetime: 0,
      threetime: 18000,
      fourContent: '转输至江西腾龙源环保科技有限公司事故应急池、初期雨水池。',
      fourPointPosition: {
        lng: 115.10332118,
        lat: 27.27831698
      },
      fourtime: 0,
      fourtime: 23000,
    },
  ]
})
const dynamicVectorLayer = new DC.VectorLayer('dynamicVectorLayer').addTo(window.$viewer)
const dynamicHtmlLayer = new DC.HtmlLayer('dynamicHtmlLayer').addTo(window.$viewer)
const dynamicLineVectorLayer = new DC.VectorLayer('dynamicLineVectorLayer').addTo(window.$viewer)
let dynamicVectorLayer = new DC.VectorLayer('dynamicVectorLayer').addTo(window.$viewer)
let dynamicHtmlLayer = new DC.HtmlLayer('dynamicHtmlLayer').addTo(window.$viewer)
let dynamicLineVectorLayer = new DC.VectorLayer('dynamicLineVectorLayer').addTo(window.$viewer)
const schemeStart = (item) => {
  emit('closePanel')
  clearAll()
let modelPosition = [
  {
    lng: 115.10601196,
    lat: 27.28378838
  },
  {
    lng: 115.10602432,
    lat: 27.28339800
  },
  {
    lng: 115.10600450,
    lat: 27.28319338,
  },
  {
    lng: 115.10605031,
    lat: 27.28294272,
  },
  {
    lng: 115.10610404,
    lat: 27.28267996
  },
  {
    lng: 115.10614202,
    lat: 27.28248175
  },
  {
    lng: 115.10620011,
    lat: 27.28221311
  },
  {
    lng: 115.10640155,
    lat: 27.28121605
  },
  window.$viewer.flyToPosition(new DC.Position(item.onePointPosition.lng, item.onePointPosition.lat, 400, 0, -90, 0), () => {
    let oneCenter = DC.Position.fromObject(item.onePointPosition)
    let oneCircle = new DC.Circle(oneCenter, 20)
    oneCircle.setStyle({
      material: new DC.CircleWaveMaterialProperty({
        color: DC.Color.RED.withAlpha(0.9),
        speed: 20,
        count: 5,
        gradient: 0.5
      })
]
let positions = modelPosition.map(i => [i.lng, i.lat, i.ele || 64].join(',')).join(';')
let tc = new DC.TrackController(window.$viewer)
let track = new DC.Track(positions, 5)
track.setModel(VITE_APP_BASE + 'gltf/car.gltf', {
  show: true,
  scale: 0.0025,
  // nodeTransformations: {
  //   rotation: window.$Cesium.Quaternion.fromHeadingPitchRoll(window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0)),
  // }
})
tc.addTrack(track)
const synth = window.speechSynthesis
const speak = (msg, continueFun = () => { }) => {
  let u = new SpeechSynthesisUtterance()
  let voices = synth.getVoices()
  u.text = msg
  u.rate = 2
  let findObj = voices.some(voice => voice.lang == 'zh-CN')
  if (!findObj) {
    u.lang = 'zh-TW'
  }
  u.onend = () => {
    continueFun()
  }
  synth.speak(u)
}
const publicFun = (item) => {
  let threeCenter = DC.Position.fromObject(item.threePointPosition)
  let threeCircle = new DC.Circle(threeCenter, 30)
  threeCircle.setStyle({
    material: new DC.CircleWaveMaterialProperty({
      color: DC.Color.fromRandom(),
      speed: 20,
      count: 5,
      gradient: 0.5
    })
    dynamicVectorLayer.addOverlay(oneCircle)
  })
  dynamicVectorLayer.addOverlay(threeCircle)
    let oneCentent = new DC.DivIcon(
      new DC.Position(item.onePointPosition.lng, item.onePointPosition.lat, 70),
      `<div class="dynamic-map-popup">
          <div class="content-wrap">
            <div class="content">
              <p>${item.oneCentent}</p>
              </div>
              </div>
              <div class="arrow"></div>
              </div>`
      // <p>特征污染物:${item.specificPollutant}</p>
    )
    dynamicHtmlLayer.addOverlay(oneCentent)
  let threeContent = new DC.DivIcon(
    new DC.Position(item.threePointPosition.lng, item.threePointPosition.lat, 70),
    `<div class="dynamic-map-popup">
                  <div class="content-wrap">
                    <div class="content">
                      <p>${item.threeContent}</p>
                    </div>
                  </div>
                  <div class="arrow"></div>
                </div>`
  )
  dynamicHtmlLayer.addOverlay(threeContent)
  window.$viewer.flyToPosition(new DC.Position(item.threePointPosition.lng, item.threePointPosition.lat, 400, 0, -90, 0), () => {
    speak(item.threeContent, () => {
      let FourCenter = DC.Position.fromObject(item.fourPointPosition)
      let fourCircle = new DC.Circle(FourCenter, 10)
      fourCircle.setStyle({
        material: new DC.CircleWaveMaterialProperty({
          color: DC.Color.fromRandom(),
          speed: 20,
          count: 5,
          gradient: 0.5
        })
      })
      dynamicVectorLayer.addOverlay(fourCircle)
      let fourContent = new DC.DivIcon(
        new DC.Position(item.fourPointPosition.lng, item.fourPointPosition.lat, 70),
        `<div class="dynamic-event-profile-map-popup">
                      <div class="content-wrap">
                        <div class="content">
                          <p>${item.fourContent}</p>
                        </div>
                      </div>
                      <div class="arrow"></div>
                    </div>`
      )
      dynamicHtmlLayer.addOverlay(fourContent)
      // 执行对应的事件函数
      window.$viewer.flyToPosition(new DC.Position(item.fourPointPosition.lng, item.fourPointPosition.lat, 400, 0, -90, 0), () => {
        speak(item.fourContent, () => {
          if (item.fivePointPosition) {
            let fiveCenter = DC.Position.fromObject(item.fivePointPosition)
            let fiveCircle = new DC.Circle(fiveCenter, 10)
            fiveCircle.setStyle({
              material: new DC.CircleWaveMaterialProperty({
                color: DC.Color.fromRandom(),
                speed: 20,
                count: 5,
                gradient: 0.5
              })
            })
            dynamicVectorLayer.addOverlay(fiveCircle)
            let fiveContent = new DC.DivIcon(
              new DC.Position(item.fivePointPosition.lng, item.fivePointPosition.lat, 70),
              `<div class="dynamic-event-profile-map-popup">
                              <div class="content-wrap">
                                <div class="content">
                                  <p>${item.fiveContent}</p>
                                </div>
                              </div>
                              <div class="arrow"></div>
                          </div>`
            )
            dynamicHtmlLayer.addOverlay(fiveContent)
            // 执行对应的事件函数
            window.$viewer.flyToPosition(new DC.Position(item.fivePointPosition.lng, item.fivePointPosition.lat, 400, 0, -90, 0), () => {
              speak(item.fiveContent)
            }, 3)
          }
        })
      }, 3)
    })
  }, 3)
}
  item.linePosition && (lineTime = setTimeout(() => {
    let polyline = new DC.Polyline(item.linePosition)
    polyline.setStyle({
      width: 20,
      material: new DC.PolylineImageTrailMaterialProperty({
        color: DC.Color.RED,
        speed: 20,
        image: VITE_APP_BASE + 'img/mapicon/right.png',
        repeat: { x: 5, y: 1 }
      }),
      clampToGround: false
const twoFun = (item, cb = () => { }) => {
  let twoCenter = DC.Position.fromObject(item.twoPointPosition)
  let twoCircle = new DC.Circle(twoCenter, 10)
  twoCircle.setStyle({
    material: new DC.CircleWaveMaterialProperty({
      color: DC.Color.fromRandom(),
      speed: 20,
      count: 5,
      gradient: 0.5
    })
  })
  dynamicVectorLayer.addOverlay(twoCircle)
    dynamicLineVectorLayer.addOverlay(polyline)
    window.$viewer.flyToPosition(new DC.Position(item.lineCenter.lng, item.lineCenter.lat, 400, 0, -90, 0), () => { }, 3)
  }, item.lineTime))
  timeTwo = setTimeout(() => {
    let twoCenter = DC.Position.fromObject(item.twoPointPosition)
    let twoCircle = new DC.Circle(twoCenter, 10)
    twoCircle.setStyle({
      material: new DC.CircleWaveMaterialProperty({
        color: DC.Color.fromRandom(),
        speed: 20,
        count: 5,
        gradient: 0.5
      })
    })
    dynamicVectorLayer.addOverlay(twoCircle)
    let twoContent = new DC.DivIcon(
      new DC.Position(item.twoPointPosition.lng, item.twoPointPosition.lat, 70),
      `<div class="dynamic-event-profile-map-popup">
  let twoContent = new DC.DivIcon(
    new DC.Position(item.twoPointPosition.lng, item.twoPointPosition.lat, 70),
    `<div class="dynamic-event-profile-map-popup">
          <div class="content-wrap">
            <div class="content">
              <p>${item.twoContent}</p>
@@ -230,108 +343,137 @@
              </div>
              <div class="arrow"></div>
              </div>`
      // <p>特征污染物:${item.specificPollutant}</p>
    )
    dynamicHtmlLayer.addOverlay(twoContent)
    // 执行对应的事件函数
    window.$viewer.flyToPosition(new DC.Position(item.twoPointPosition.lng, item.twoPointPosition.lat, 400, 0, -90, 0), () => { }, 3)
  }, item.twotime)
    // <p>特征污染物:${item.specificPollutant}</p>
  )
  dynamicHtmlLayer.addOverlay(twoContent)
  // 执行对应的事件函数
  window.$viewer.flyToPosition(new DC.Position(item.twoPointPosition.lng, item.twoPointPosition.lat, 400, 0, -90, 0), () => {
    speak(item.twoContent, () => {
      cb()
    })
  }, 3)
}
  timeThree = setTimeout(() => {
    let threeCenter = DC.Position.fromObject(item.threePointPosition)
    let threeCircle = new DC.Circle(threeCenter, 30)
    threeCircle.setStyle({
      material: new DC.CircleWaveMaterialProperty({
        color: DC.Color.fromRandom(),
        speed: 20,
        count: 5,
        gradient: 0.5
const createLinePath = (item, cb = () => { }) => {
  let polyline = new DC.Polyline(item.linePosition)
  polyline.setStyle({
    width: 20,
    material: new DC.PolylineImageTrailMaterialProperty({
      color: DC.Color.RED,
      speed: 20,
      image: VITE_APP_BASE + 'img/mapicon/right.png',
      repeat: { x: 5, y: 1 }
    }),
    clampToGround: false
  })
  dynamicLineVectorLayer.addOverlay(polyline)
  window.$viewer.flyToPosition(new DC.Position(item.lineCenter.lng, item.lineCenter.lat, 400, 0, -90, 0), () => {
    lineTime = setTimeout(() => {
      cb()
    }, item.lineTime)
  }, 3)
}
const schemeStart = (item) => {
  emit('closePanel')
  clearAll()
  if (item.showModel) {
    window.$viewer.flyToPosition("115.10587903,27.28374884,400,0,-90", () => {
      track.setModel(VITE_APP_BASE + 'gltf/car.gltf', {
        show: true,
        scale: 0.0025,
        // nodeTransformations: {
        //   rotation: window.$Cesium.Quaternion.fromHeadingPitchRoll(window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0)),
        // }
      })
      tc.play()
      tc.viewTrack(track, {
        mode: '2',
        pitch: -45,
        range: 400
      })
    })
    dynamicVectorLayer.addOverlay(threeCircle)
  }
    let threeContent = new DC.DivIcon(
      new DC.Position(item.threePointPosition.lng, item.threePointPosition.lat, 70),
      `<div class="dynamic-map-popup">
          <div class="content-wrap">
            <div class="content">
              <p>${item.threeContent}</p>
            </div>
          </div>
          <div class="arrow"></div>
        </div>`
    )
    dynamicHtmlLayer.addOverlay(threeContent)
    window.$viewer.flyToPosition(new DC.Position(item.threePointPosition.lng, item.threePointPosition.lat, 400, 0, -90, 0), () => { }, 3)
  }, item.threetime)
  item.fourPointPosition && (timeFour = setTimeout(() => {
    let FourCenter = DC.Position.fromObject(item.fourPointPosition)
    let fourCircle = new DC.Circle(FourCenter, 10)
    fourCircle.setStyle({
      material: new DC.CircleWaveMaterialProperty({
        color: DC.Color.fromRandom(),
        speed: 20,
        count: 5,
        gradient: 0.5
  timeOne = setTimeout(() => {
    function oneLoad () {
      let oneCenter = DC.Position.fromObject(item.onePointPosition)
      let oneCircle = new DC.Circle(oneCenter, 20)
      oneCircle.setStyle({
        material: new DC.CircleWaveMaterialProperty({
          color: DC.Color.RED.withAlpha(0.9),
          speed: 20,
          count: 5,
          gradient: 0.5
        })
      })
    })
    dynamicVectorLayer.addOverlay(fourCircle)
      dynamicVectorLayer.addOverlay(oneCircle)
    let fourContent = new DC.DivIcon(
      new DC.Position(item.fourPointPosition.lng, item.fourPointPosition.lat, 70),
      `<div class="dynamic-event-profile-map-popup">
      let oneCentent = new DC.DivIcon(
        new DC.Position(item.onePointPosition.lng, item.onePointPosition.lat, 70),
        `<div class="dynamic-map-popup">
          <div class="content-wrap">
            <div class="content">
              <p>${item.fourContent}</p>
              <p>${item.oneCentent}</p>
              </div>
              </div>
              <div class="arrow"></div>
              </div>`
    )
    dynamicHtmlLayer.addOverlay(fourContent)
    // 执行对应的事件函数
    window.$viewer.flyToPosition(new DC.Position(item.fourPointPosition.lng, item.fourPointPosition.lat, 400, 0, -90, 0), () => { }, 3)
  }, item.fourtime))
        // <p>特征污染物:${item.specificPollutant}</p>
      )
      dynamicHtmlLayer.addOverlay(oneCentent)
  item.fivePointPosition && (timeFive = setTimeout(() => {
    let fiveCenter = DC.Position.fromObject(item.fivePointPosition)
    let fiveCircle = new DC.Circle(fiveCenter, 10)
    fiveCircle.setStyle({
      material: new DC.CircleWaveMaterialProperty({
        color: DC.Color.fromRandom(),
        speed: 20,
        count: 5,
        gradient: 0.5
      speak(item.oneCentent, () => {
        if (item.key == 2) {
          createLinePath(item, () => {
            twoFun(item, () => {
              publicFun(item)
            })
          })
        } else if (item.key == 1) {
          twoFun(item, () => {
            createLinePath(item, () => {
              publicFun(item)
            })
          })
        } else {
          twoFun(item, () => {
            publicFun(item)
          })
        }
      })
    })
    dynamicVectorLayer.addOverlay(fiveCircle)
    let fiveContent = new DC.DivIcon(
      new DC.Position(item.fivePointPosition.lng, item.fivePointPosition.lat, 70),
      `<div class="dynamic-event-profile-map-popup">
          <div class="content-wrap">
            <div class="content">
              <p>${item.fiveContent}</p>
              </div>
              </div>
              <div class="arrow"></div>
              </div>`
    )
    dynamicHtmlLayer.addOverlay(fiveContent)
    // 执行对应的事件函数
    window.$viewer.flyToPosition(new DC.Position(item.fivePointPosition.lng, item.fivePointPosition.lat, 400, 0, -90, 0), () => { }, 3)
  }, item.fivetime))
    }
    if (item.showModel) {
      oneLoad()
    } else {
      window.$viewer.flyToPosition(new DC.Position(item.onePointPosition.lng, item.onePointPosition.lat, 400, 0, -90, 0), () => {
        oneLoad()
      }, 3)
    }
  }, item.onetime)
}
const clearAll = () => {
  window.speechSynthesis.cancel()
  lineTime && (clearTimeout(lineTime), lineTime = null)
  timeOne && (clearTimeout(timeOne), timeOne = null)
  timeTwo && (clearTimeout(timeTwo), timeTwo = null)
  timeThree && (clearTimeout(timeThree), timeThree = null)
  timeFour && (clearTimeout(timeFour), timeFour = null)
  timeFive && (clearTimeout(timeFive), timeFive = null)
  track.setModel(VITE_APP_BASE + 'gltf/car.gltf', {
    show: false,
    scale: 0.0025,
    // nodeTransformations: {
    //   rotation: window.$Cesium.Quaternion.fromHeadingPitchRoll(window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0), window.$Cesium.Math.toRadians(0)),
    // }
  })
  dynamicVectorLayer.clear()
  dynamicHtmlLayer.clear()
@@ -341,9 +483,16 @@
onUnmounted(() => {
  clearAll()
  dynamicVectorLayer && window.$viewer.removeLayer(dynamicVectorLayer)
  dynamicHtmlLayer && window.$viewer.removeLayer(dynamicHtmlLayer)
  dynamicLineVectorLayer && window.$viewer.removeLayer(dynamicLineVectorLayer)
  tc.clear()
  dynamicVectorLayer && window.$viewer && window.$viewer.removeLayer(dynamicVectorLayer)
  dynamicHtmlLayer && window.$viewer && window.$viewer.removeLayer(dynamicHtmlLayer)
  dynamicLineVectorLayer && window.$viewer && window.$viewer.removeLayer(dynamicLineVectorLayer)
  tc = null
  track = null
  dynamicVectorLayer = null
  dynamicHtmlLayer = null
  dynamicLineVectorLayer = null
})
</script>