无人机管理后台前端(已迁走)
chenyao
2025-11-17 233e4fc4f35bd00a36ee34a7fbf5e47b41db26db
src/utils/cesium/publicCesium.js
@@ -94,13 +94,13 @@
         terrain = false,
         layerMode = 0,
         contour = true,
         // flyToContour = false,
         flyToContour = false,
         multiple = 1.4,
         dockOptions = {},
         boundaryColor = '#7FFFD4',
         boundaryChange,
         dockRangeType = 1,
         useDockHeight = false
      } = options
@@ -135,7 +135,7 @@
      this.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(utc, 0, new Cesium.JulianDate())
      // 边界,机巢
      this.boundary = useBoundary(this.viewer, { multiple, dockOptions, boundaryChange, boundaryColor, dockRangeType, useDockHeight })
      this.viewer?.imageryLayers.removeAll()
      this.viewer._cesiumWidget._creditContainer.style.display = 'none'
      handler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
@@ -143,8 +143,28 @@
      this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
      if (terrain) {
         // 正则:第一位非0,第二位任意数字,后10位都是0
         const re = /^[1-9]\d0{10}$/
         let result = null
         // 1️⃣先判断 areaCode
         if (re.test(store.state.user.userInfo.detail.areaCode)) {
            result = store.state.user.userInfo.detail.areaCode.slice(0, 6)
         } else {
            // 2️⃣如果不满足,从 ancestors 里找
            const matchedItems = store.state.user.userInfo.detail.ancestors
               .split(',')
               .filter(item => re.test(item)) // 过滤出符合条件的
            // 取第一个符合条件的前6位(可以改成 last one 看需求)
            if (matchedItems.length > 0) {
               result = matchedItems[0].slice(0, 6)
            }
         }
         try {
            Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}`, {
            Cesium.CesiumTerrainProvider.fromUrl(`${import.meta.env.VITE_APP_TERRAIN_URL}${result}`, {
               requestVertexNormals: true, // 启用地形法线增强立体感
               requestWaterMask: true, // 启用水体遮罩效果
            }).then(terrainProvider => {
@@ -158,8 +178,8 @@
      this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 4500000
      this.switchLayers(layerMode)
      this.switchFlatMode(flatMode)
      // this.switchContour(contour)
      // flyToContour && this.flyToContour(contour)
      this.switchContour(contour)
      flyToContour && this.flyToContour(contour)
   }
   getViewer () {
@@ -202,21 +222,22 @@
   }
   setShowDock (sns) {
      // this.boundary?.setShowDock(sns)
      this.boundary?.setShowDock(sns)
   }
   // 切换轮廓显示
   // async switchContour (open) {
   //    if (open) {
   //       await this.boundary?.openContour()
   //    } else {
   //       this.boundary?.closeContour()
   //    }
   // }
   async switchContour (open) {
      if (open) {
         await this.boundary?.openContour()
      } else {
         this.boundary?.closeContour()
      }
   }
   // // 飞向轮廓居中
   // flyToContour () {
   //    this.boundary?.flyToBoundary()
   // }
   flyToContour () {
      this.boundary?.flyToBoundary()
   }
   // 飞行 flyto
   flyTo (pointOption, time = 4, height = 3000, orientation = {}, complete = () => { }) {
@@ -751,7 +772,7 @@
         Cesium.Cartesian3.subtract(a, this.viewer?.camera.position, a),
         Cesium.Cartesian3.normalize(r, r),
         Cesium.Cartesian3.normalize(a, a)) : (r = c.direction,
         a = h.direction)
            a = h.direction)
      let d = Cesium.Cartesian3.dot(r, a)
         , p = 0
      return d < 1 && (p = Math.acos(d)),
@@ -780,7 +801,7 @@
            , r = Cesium.Math.acosClamped(-e)
         a > 0 && a > r && (a = r - Cesium.Math.EPSILON4),
            r = Cesium.Math.acosClamped(e),
         a < 0 && -a > r && (a = -r + Cesium.Math.EPSILON4)
            a < 0 && -a > r && (a = -r + Cesium.Math.EPSILON4)
      }
      return a
   }