| | |
| | | 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' |
| | | |
| | |
| | | /** |
| | | * 公共的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 = { |
| | |
| | | } = 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, // 左下角的动画仪表盘 |
| | |
| | | this.viewer?.imageryLayers.remove(imageryLayers) |
| | | } |
| | | } |
| | | } |
| | | } |