吉安感知网项目-前端
张含笑
2026-01-19 f925f12d5263c94644bddf6fd2ac3d23b77791cf
applications/drone-command/src/utils/cesium/publicCesium.js
@@ -2,6 +2,7 @@
import * as Cesium from 'cesium'
import { Cartesian3, Terrain, Viewer } from 'cesium'
import store from '@/store/index'
import jaGeojsonRaw from '@/assets/geojson/ja.geojson?raw'
import getBaseConfig from '@/buildConfig/config'
@@ -32,6 +33,36 @@
/**
 * 公共的Cesium (蓝色,2d)
 */
const DEFAULT_VIEW_RECTANGLE = (() => {
   try {
      const geojson = JSON.parse(jaGeojsonRaw)
      let west = Infinity
      let east = -Infinity
      let south = Infinity
      let north = -Infinity
      const walk = coords => {
         if (!Array.isArray(coords)) return
         if (typeof coords[0] === 'number' && typeof coords[1] === 'number') {
            const lng = coords[0]
            const lat = coords[1]
            if (!Number.isFinite(lng) || !Number.isFinite(lat)) return
            west = Math.min(west, lng)
            east = Math.max(east, lng)
            south = Math.min(south, lat)
            north = Math.max(north, lat)
            return
         }
         coords.forEach(walk)
      }
      geojson?.features?.forEach(feature => walk(feature?.geometry?.coordinates))
      if ([west, east, south, north].every(Number.isFinite)) {
         return Cesium.Rectangle.fromDegrees(west, south, east, north)
      }
   } catch (error) {}
   return Cesium.Rectangle.fromDegrees(66, 4, 135, 53.55)
})()
// 封装的不用管
let cn = {
@@ -106,7 +137,7 @@
      } = options
      Cesium.Camera.DEFAULT_VIEW_FACTOR = -0.45
      // 西南东北,默认显示中国
      Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(66, 4, 135, 53.55)
      Cesium.Camera.DEFAULT_VIEW_RECTANGLE = DEFAULT_VIEW_RECTANGLE
      const viewerOptions = {
         infoBox: false, // 禁用沙箱,解决控制台报错
         animation: false, // 左下角的动画仪表盘
@@ -881,4 +912,4 @@
         this.viewer?.imageryLayers.remove(imageryLayers)
      }
   }
}
}