From 41b8a8d0ecea96ace27b5afb9ce63b4193420c49 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Thu, 14 Aug 2025 08:47:21 +0800
Subject: [PATCH] Merge branch 'refs/heads/历史任务详情' into feature/v5.0/5.0.3

---
 src/utils/cesium/publicCesium.js |  496 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 405 insertions(+), 91 deletions(-)

diff --git a/src/utils/cesium/publicCesium.js b/src/utils/cesium/publicCesium.js
index 7c198e9..59b1acf 100644
--- a/src/utils/cesium/publicCesium.js
+++ b/src/utils/cesium/publicCesium.js
@@ -1,21 +1,25 @@
-import EventBus from './eventBus'
-
+import EventBus from '@/utils/eventBus'
+import * as Cesium from 'cesium'
 import { Cartesian3, Terrain, Viewer } from 'cesium'
+import store from '@/store/index'
 
 import getBaseConfig from '@/buildConfig/config'
 
 const {
+	imageryProvider_ammap,
+	imageryProvider_ammapBz,
+	imageryProvider_ammapSL,
 	imageryProvider_stand,
 	imageryProvider_standZh,
-
+	imageryProvider_tdt_cia_w,
 	imageryProvider_tdt_img_w,
-	imageryProvider_tdt_cia_w
+
+	blueImageryProviderVec,
+	blueImageryProviderCva,
 } = getBaseConfig()
 
-const env = import.meta.env.VITE_APP_ENV || 'default'
-
-import { addBlueFilter } from './common'
-import * as Cesium from 'cesium'
+import { addBlueFilter } from '@/utils/cesium/common'
+import { useBoundary } from '@/utils/cesium/useBoundary'
 
 let smallMpaCenterDistance = null
 let curCameraHpr = null
@@ -55,17 +59,51 @@
 	return Cesium.Cartesian3.fromDegrees(i, a, t ? 0 : o)
 }
 
+/**
+ * 创建ztzf-cesium
+ * @param {Object} options - 配置选项对象
+ * @param {string} options.dom - Cesium 容器的 DOM 元素
+ * @param {boolean} [options.flatMode=true] - 是否启用 2D 模式,默认为 true
+ * @param {boolean} [options.terrain=false] - 是否启用地形,默认为 false
+ * @param {number} [options.layerMode=17] - 图层模式,默认值为 17(蓝色底图)
+ * @param {boolean} [options.contour=true] - 是否显示轮廓线,默认为 true
+ * @param {boolean} [options.flyToContour=false] - 是否飞行到轮廓,默认为 false
+ * @param {number} [options.multiple=1.4] - 范围倍数
+ * @param {number} [options.dockOptions={}] - 机巢显示
+ * @param {array} [options.boundaryChange] - 边界改变事件
+ * @param {array} [options.boundaryColor] - 边界颜色
+ * @param {array} [options.dockRangeType] - 机巢范围类型 1显示覆盖圆;2显示覆盖圈
+ * @param {array} [options.useDockHeight] - 是否使用机巢高度,默认为false
+ */
 export class PublicCesium {
 
 	constructor(options) {
-		this.handlerEvents = { handler: null }
+		this.handlerLeftEvents = { handler: null }
+		this.handlerRightEvents = { handler: null }
+		this.handlerMouseMoveEvents = { handler: null }
 		this.viewer = null
+		this.globalBaseMapLayers = []
+		this.boundary = null
 		this.init(options)
 	}
 
 	init (options) {
-		const that = this
-		const { dom, flatMode = true, terrain = false, mapFilter = true, layers } = options
+		const {
+			dom,
+			flatMode = true,
+			terrain = false,
+			layerMode = 0,
+			contour = true,
+			// flyToContour = false,
+			multiple = 1.4,
+
+			dockOptions = {},
+
+
+
+			dockRangeType = 1,
+			useDockHeight = false
+		} = options
 		Cesium.Camera.DEFAULT_VIEW_FACTOR = -0.45
 		// 西南东北,默认显示中国
 		Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(66, 4, 135, 53.55)
@@ -83,16 +121,26 @@
 			fullscreenButton: false,
 		}
 
-		this.viewer = new Viewer(options.dom, viewerOptions)
+		this.viewer = new Viewer(dom, viewerOptions)
+		this.viewerDom = dom
 
-		this.viewer.imageryLayers.removeAll()
+		this.viewer.scene.globe.enableLighting = true
+		this.viewer.shadows = false
+		this.viewer.shadowMap.darkness = 0.5
+
+		let time = new Date()
+		time.setHours(12, 0, 0, 0)
+		let utc = Cesium.JulianDate.fromDate(new Date(time))
+
+		this.viewer.clockViewModel.currentTime = Cesium.JulianDate.addHours(utc, 0, new Cesium.JulianDate())
+
+		// 边界,机巢
+
+		this.viewer?.imageryLayers.removeAll()
 		this.viewer._cesiumWidget._creditContainer.style.display = 'none'
+		handler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
-		handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
-
-		if (flatMode) {
-			this.viewer.scene.screenSpaceCameraController.enableTilt = false
-		}
+		this.viewer?.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK) // 禁用双击
 
 		if (terrain) {
 			try {
@@ -107,101 +155,299 @@
 			}
 		}
 
-		if (layers) {
-			layers.forEach(item => {
-				this.viewer.imageryLayers.addImageryProvider(item)
-			})
-		} else {
-			if (env === 'jiangwu') {
-				this.tcLayer = this.viewer.imageryLayers.addImageryProvider(imageryProvider_tdt_img_w)
-				this.zjLayer = this.viewer.imageryLayers.addImageryProvider(imageryProvider_tdt_cia_w)
-			} else {
-				this.tcLayer = this.viewer.imageryLayers.addImageryProvider(imageryProvider_stand)
-				this.zjLayer = this.viewer.imageryLayers.addImageryProvider(imageryProvider_standZh)
-			}
-		}
-
-		// if (mapFilter) {
-		// 	;[this.tcLayer, this.zjLayer].forEach(item => {
-		// 		item.brightness = 0.6 // 亮度(默认值)
-		// 		item.contrast = 1.8 // 对比度(负值降低对比度)
-		// 		item.hue = 1 // 色相(弧度值,3.0可能导致紫色)
-		// 		item.saturation = 0 // 增加饱和度强化蓝色
-		// 		item.gamma = 0.3 // 伽马校正(小于1.0使颜色更鲜艳)
-		// 	})
-
-		// 	const filterOptions = { bInvertColor: true, bFilterColor: true, filterColor: '#4e70a6' }
-		// 	// 添加蓝色滤镜
-		// 	addBlueFilter(filterOptions, this.viewer)
-		// }
-
 		this.viewer.scene.screenSpaceCameraController.maximumZoomDistance = 4500000
+		this.switchLayers(layerMode)
+		this.switchFlatMode(flatMode)
+		// this.switchContour(contour)
+		// flyToContour && this.flyToContour(contour)
 	}
+
 	getViewer () {
 		return this.viewer
 	}
 
-	viewerDestroy () {
+	// 销毁viewer
+	viewerDestroy (removeDom = true) {
 		smallMpaCenterDistance = null
 
-		this.viewer && this.viewer.destroy()
-		this.viewer = null
+		if (this.viewer) {
+			this.viewer?.entities.removeAll()
+			this.viewer?.imageryLayers.removeAll()
+			this.viewer?.dataSources.removeAll()
+
+
+			// try {
+			// 	this.viewer?.scene?.primitives?.removeAll()
+			// 	this.viewer?.entities?.removeAll()
+			// } catch (e) {
+			// 	console.warn('清理资源时出错:', e)
+
+			// 	console.log(this.viewer, 1111111111111)
+			// }
+
+			// 获取webgl上下文
+			let gl = this.viewer?.scene.context._originalGLContext
+			gl.canvas.width = 1
+			gl.canvas.height = 1
+			gl.getExtension("WEBGL_lose_context").loseContext()
+			gl = null
+			this.viewer?.destroy() // 销毁Viewer实例
+			this.viewer = null
+			var cesiumContainer = document.getElementById(this.viewerDom)
+			if (cesiumContainer && removeDom) {
+				cesiumContainer.remove() // 移除与地图相关的DOM元素
+				this.viewerDom = null
+			}
+		}
 	}
-	addRightClickEvent (sid, cb) {
-		if (this.rightClickHandler) this.removeRightClickEvent()
 
-		this.rightClickHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
+	setShowDock (sns) {
+		// this.boundary?.setShowDock(sns)
+	}
 
-		this.rightClickHandler.setInputAction(click => {
+	// 切换轮廓显示
+	// async switchContour (open) {
+	// 	if (open) {
+	// 		await this.boundary?.openContour()
+	// 	} else {
+	// 		this.boundary?.closeContour()
+	// 	}
+	// }
+	// // 飞向轮廓居中
+	// flyToContour () {
+	// 	this.boundary?.flyToBoundary()
+	// }
+
+	// 飞行 flyto
+	flyTo (pointOption, time = 4, height = 3000, orientation = {}, complete = () => { }) {
+		if (!pointOption.longitude && !pointOption.latitude) return
+		const destination = Cesium.Cartesian3.fromDegrees(pointOption.longitude, pointOption.latitude, height)
+		const duration = time
+		this.viewer?.camera.flyTo({
+			destination,
+			duration,
+			orientation,
+			complete,
+		})
+	}
+
+	switchLayers (mode, roadLine = false) {
+		let mapLayers = []
+		this.globalBaseMapLayers?.forEach(item => {
+			if (item.mapLayer) item.mapLayer.show = false
+		})
+		// store.state.common.mapSetting.mode = mode
+		// 标准地图(天地图矢量)加载
+		if (mode === 0) {
+			mapLayers.push(
+				...[
+					{ key: 'imageryProvider_standZh', layer: imageryProvider_standZh },
+					{ key: 'imageryProvider_stand', layer: imageryProvider_stand },
+				]
+			)
+		}
+		// 高德地图矢量图层加载
+		if (mode === 2) {
+			mapLayers.push({
+				key: 'imageryProvider_ammapSL',
+				layer: imageryProvider_ammapSL,
+			})
+		}
+		// 高德影像地图数据图层
+		if (mode === 3) {
+			mapLayers.push(
+				...[
+					{ key: 'imageryProvider_ammap', layer: imageryProvider_ammap },
+					{ key: 'imageryProvider_ammapBz', layer: imageryProvider_ammapBz },
+				]
+			)
+		}
+
+		// 天地图影像➕注记
+		if (mode === 4) {
+			mapLayers.push(
+				...[
+					{ key: 'imageryProvider_standZh', layer: imageryProvider_standZh },
+					// { key: 'imageryProvider_tdt_cia_w', layer: imageryProvider_tdt_cia_w },
+					{ key: 'imageryProvider_tdt_img_w', layer: imageryProvider_tdt_img_w },
+				]
+			)
+		}
+
+		// 蓝色底图
+		if (mode === 17) {
+			mapLayers.push(
+				...[
+					{ key: 'blueImageryProviderCva', layer: blueImageryProviderCva },
+					{ key: 'blueImageryProviderVec', layer: blueImageryProviderVec },
+				]
+			)
+		}
+
+		// 路线图加载
+		if (roadLine === true && mode === 1) {
+			mapLayers.push({ key: 'annotation', layer: imageryProvider_tdt_cia_w })
+		}
+
+		mapLayers.forEach(item => {
+			let find = this.globalBaseMapLayers.find(item1 => item1.key === item.key)
+			if (!find) {
+				find = {
+					key: item.key,
+					mapLayer: this.viewer?.imageryLayers.addImageryProvider(item.layer),
+				}
+				this.globalBaseMapLayers.push(find)
+			}
+			find.mapLayer.show = true
+			this.setCurrentLayerFilter(find, mode)
+			this.viewer?.imageryLayers.lowerToBottom(find.mapLayer)
+		})
+	}
+
+	// 设置或重置滤镜
+
+	setCurrentLayerFilter (data, mode) {
+		if (mode === 17) {
+			data.mapLayer.brightness = 0.6 // 亮度(默认值)
+			data.mapLayer.contrast = 1.8 // 对比度(负值降低对比度)
+			data.mapLayer.hue = 1 // 色相(弧度值,3.0可能导致紫色)
+			data.mapLayer.saturation = 0 // 增加饱和度强化蓝色
+			data.mapLayer.gamma = 0.3 // 伽马校正(小于1.0使颜色更鲜艳)
+
+			if (data.key === 'blueImageryProviderVec')
+				addBlueFilter(
+					{
+						bInvertColor: true,
+						bFilterColor: true,
+						filterColor: '#4e70a6',
+					},
+					this.viewer,
+					true
+				)
+		} else {
+			data.mapLayer.brightness = 1 // 亮度(默认值)
+			data.mapLayer.contrast = 1 // 对比度(负值降低对比度)
+			data.mapLayer.hue = 0 // 色相(弧度值,3.0可能导致紫色)
+			data.mapLayer.saturation = 1 // 增加饱和度强化蓝色
+			data.mapLayer.gamma = 1 // 伽马校正(小于1.0使颜色更鲜艳)
+
+			addBlueFilter(
+				{
+					bInvertColor: true,
+					bFilterColor: true,
+					filterColor: '#4e70a6',
+				},
+				this.viewer,
+				false
+			)
+		}
+	}
+
+	// 切换为二三维模式 type:  true 2D  false 3D
+	switchFlatMode (type) {
+		if (type) {
+			this.viewer?.scene.morphTo2D(0)
+		} else {
+			this.viewer?.scene.morphTo3D(0)
+		}
+	}
+
+	// 右键点击事件
+	addRightClickEvent (sid, cb, eventKey = 'rightHandler') {
+		if (this.handlerRightEvents.rightHandler) this.removeRightClickEvent()
+		if (this.handlerRightEvents[eventKey]) this.removeRightClickEvent(eventKey)
+
+		this.handlerRightEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
+
+		this.handlerRightEvents[eventKey].setInputAction(click => {
 			const pick = this.viewer?.scene.pick(click.position)
 			cb(click, pick, this.viewer)
 		}, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
 	}
 
 	// 移除鼠标右键事件
-	removeRightClickEvent () {
-		if (!this.rightClickHandler) return
-		this.rightClickHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
+	removeRightClickEvent (eventKey = 'rightHandler') {
+		if (!this.handlerRightEvents[eventKey]) return
+		this.handlerRightEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK)
 
-		this.rightClickHandler = null
+		this.handlerRightEvents[eventKey] = null
+	}
+
+	addLeftDrillPickEvent (cb, eventKey = 'handler') {
+		if (this.handlerLeftEvents.handler) this.removeLeftDrillPickEvent()
+		if (this.handlerLeftEvents[eventKey]) this.removeLeftDrillPickEvent(eventKey)
+
+		this.handlerLeftEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
+		this.handlerLeftEvents[eventKey].setInputAction(click => {
+			const picks = this.viewer?.scene.drillPick(click.position)
+
+			cb(picks)
+		}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
+	}
+
+	removeLeftDrillPickEvent (eventKey = 'handler') {
+		if (this.handlerLeftEvents[eventKey] == null) return
+		this.handlerLeftEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
+
+		this.handlerLeftEvents[eventKey] = null
 	}
 
 	// 鼠标点击事件
 	addLeftClickEvent (sid, cb, eventKey = 'handler') {
-		if (this.handlerEvents.handler) this.removeLeftClickEvent()
-		if (this.handlerEvents[eventKey]) this.removeLeftClickEvent(eventKey)
+		if (this.handlerLeftEvents.handler) this.removeLeftClickEvent()
+		if (this.handlerLeftEvents[eventKey]) this.removeLeftClickEvent(eventKey)
 
-		this.handlerEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
-		this.handlerEvents[eventKey].setInputAction(click => {
+		this.handlerLeftEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
+		this.handlerLeftEvents[eventKey].setInputAction(click => {
 			const pick = this.viewer?.scene.pick(click.position)
 
 			if (pick && pick.primitive && pick.primitive?.customParams?.type === '3DTileset') {
-				return cb(click, pick, this.viewer, this.handlerEvents[eventKey])
+				return cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
 			}
 
 			if (pick && pick.id && (pick.id._id === sid || pick.id._id.includes(sid))) {
-				cb(click, pick, this.viewer, this.handlerEvents[eventKey])
+				cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
 			}
 
 			if (sid === null) {
-				cb(click, pick, this.viewer, this.handlerEvents[eventKey])
+				cb(click, pick, this.viewer, this.handlerLeftEvents[eventKey])
 			}
 		}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
 	}
 
 	// 移除鼠标点击事件
 	removeLeftClickEvent (eventKey = 'handler') {
-		if (this.handlerEvents[eventKey] == null) return
-		this.handlerEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
+		if (this.handlerLeftEvents[eventKey] == null) return
+		this.handlerLeftEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK)
 
-		this.handlerEvents[eventKey] = null
+		this.handlerLeftEvents[eventKey] = null
+	}
+
+	// 鼠标移动事件
+	addMouseHandler (sid, cb, eventKey = 'mouseHandler') {
+		const that = this
+		if (this.handlerMouseMoveEvents.mouseHandler) this.removeMouseHandler()
+		if (this.handlerMouseMoveEvents[eventKey]) this.removeMouseHandler(eventKey)
+
+
+		this.handlerMouseMoveEvents[eventKey] = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
+
+		this.handlerMouseMoveEvents[eventKey].setInputAction(function (movement) {
+			cb(movement, that.viewer)
+		}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
+	}
+
+	// 移除鼠标移动事件
+	removeMouseHandler (eventKey = 'mouseHandler') {
+		if (this.handlerMouseMoveEvents[eventKey] == null) return
+		this.handlerMouseMoveEvents[eventKey].removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE)
+
+		this.handlerMouseMoveEvents[eventKey] = null
 	}
 
 	pointInitEvent (left_down, mouse_move, left_up) {
-		if (!this.pointEditHandler) {
-			this.pointEditHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
-		}
-
+		if (this.pointEditHandler) this.pointUnInitEvent()
+		this.pointEditHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 		const events = {
 			left_down,
 			mouse_move,
@@ -354,6 +600,56 @@
 		}
 	}
 
+	getMouseInfoAll (position) {
+		let scene = this.viewer?.scene
+		let target = scene.pick(position)
+		let cartesian = undefined
+		let surfaceCartesian = undefined
+		let wgs84Position = undefined
+		let wgs84SurfacePosition = undefined
+		if (scene.pickPositionSupported) {
+			cartesian = scene.pickPosition(position)
+		}
+		if (cartesian) {
+			let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian)
+			if (c) {
+				wgs84Position = {
+					lng: Cesium.Math.toDegrees(c.longitude),
+					lat: Cesium.Math.toDegrees(c.latitude),
+					alt: c.height,
+				}
+			}
+		}
+		if (
+			scene.mode === Cesium.SceneMode.SCENE3D &&
+			!(this.viewer?.terrainProvider instanceof Cesium.EllipsoidTerrainProvider)
+		) {
+			let ray = scene.camera.getPickRay(position)
+			surfaceCartesian = scene.globe.pick(ray, scene)
+		} else {
+			surfaceCartesian = scene.camera.pickEllipsoid(position, Cesium.Ellipsoid.WGS84)
+		}
+		if (surfaceCartesian) {
+			let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(surfaceCartesian)
+			if (c) {
+				wgs84SurfacePosition = {
+					lng: Cesium.Math.toDegrees(c.longitude),
+					lat: Cesium.Math.toDegrees(c.latitude),
+					alt: c.height,
+				}
+			}
+		}
+
+		return {
+			target: target,
+			windowPosition: position,
+			position: cartesian,
+			wgs84Position: wgs84Position,
+			surfacePosition: surfaceCartesian,
+			wgs84SurfacePosition: wgs84SurfacePosition,
+		}
+	}
+
 	// 左键按下事件
 	pro_left_down (e) {
 		proMoveFlag = !0
@@ -369,15 +665,15 @@
 		if (proMoveFlag) {
 			this.look3D(e.startPosition, e.endPosition)
 
-			const position = this.viewer.camera.positionCartographic
+			const position = this.viewer?.camera.positionCartographic
 			const lng = Cesium.Math.toDegrees(position.longitude).toFixed(4)
 			const lat = Cesium.Math.toDegrees(position.latitude).toFixed(4)
 			const alt = (position.height / 1000).toFixed(2) // 转换为千米
 
 			// 获取方向
-			const heading = Cesium.Math.toDegrees(this.viewer.camera.heading).toFixed(2)
-			const pitch = Cesium.Math.toDegrees(this.viewer.camera.pitch).toFixed(2)
-			const roll = Cesium.Math.toDegrees(this.viewer.camera.roll).toFixed(2)
+			const heading = Cesium.Math.toDegrees(this.viewer?.camera.heading).toFixed(2)
+			const pitch = Cesium.Math.toDegrees(this.viewer?.camera.pitch).toFixed(2)
+			const roll = Cesium.Math.toDegrees(this.viewer?.camera.roll).toFixed(2)
 
 			curCameraHpr = {
 				heading,
@@ -401,9 +697,9 @@
 		this.bindProLeftUp = this.pro_left_up.bind(this)
 		this.bindProLeftMove = this.pro_mouse_move.bind(this)
 
-		proHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
+		proHandler = new Cesium.ScreenSpaceEventHandler(this.viewer?.scene.canvas)
 
-		proController = this.viewer.scene.screenSpaceCameraController
+		proController = this.viewer?.scene.screenSpaceCameraController
 
 		proController.enableRotate = !1
 		proController.enableTilt = !1
@@ -429,8 +725,8 @@
 	}
 
 	look3D (e, t, i = !1) {
-		let r = this.viewer.camera
-			, a = this.viewer.scene.globe.ellipsoid
+		let r = this.viewer?.camera
+			, a = this.viewer?.scene.globe.ellipsoid
 			, s = i ? -1 : 2
 			, o = a.geodeticSurfaceNormal(r.position)
 		r.look(o, this.getLookAngle(e, t, "x") * s),
@@ -443,19 +739,19 @@
 			, o = t[i]
 			, n = new Cesium.Cartesian2("x" === i ? s : 0, "y" === i ? s : 0)
 			, l = new Cesium.Cartesian2("x" === i ? o : 0, "y" === i ? o : 0)
-			, c = this.viewer.camera.getPickRay(n)
-			, h = this.viewer.camera.getPickRay(l)
+			, c = this.viewer?.camera.getPickRay(n)
+			, h = this.viewer?.camera.getPickRay(l)
 		if (!c || !h)
 			return 0
-		this.viewer.camera.frustum instanceof Cesium.OrthographicFrustum ? (r = c.origin,
+		this.viewer?.camera.frustum instanceof Cesium.OrthographicFrustum ? (r = c.origin,
 			a = h.origin,
-			Cesium.Cartesian3.add(this.viewer.camera.direction, r, r),
-			Cesium.Cartesian3.add(this.viewer.camera.direction, a, a),
-			Cesium.Cartesian3.subtract(r, this.viewer.camera.position, r),
-			Cesium.Cartesian3.subtract(a, this.viewer.camera.position, a),
+			Cesium.Cartesian3.add(this.viewer?.camera.direction, r, r),
+			Cesium.Cartesian3.add(this.viewer?.camera.direction, a, a),
+			Cesium.Cartesian3.subtract(r, this.viewer?.camera.position, r),
+			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)),
@@ -463,7 +759,7 @@
 	}
 
 	lookVertical (e, t) {
-		let i = this.viewer.camera
+		let i = this.viewer?.camera
 			, r = this.judgeParallelAndRecalculateAngle(-e, i.direction, t)
 		r && i.look(i.right, r)
 	}
@@ -484,15 +780,33 @@
 				, 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
 	}
 
+	getEntityById (id) {
+		const pointEntity = this.viewer?.entities.getById(id)
+		return pointEntity
+	}
+
+	removeById (id) {
+		this.viewer?.entities.removeById(id)
+		const pointEntity = this.viewer?.entities.getById(id)
+		if (pointEntity && pointEntity !== undefined) {
+			this.viewer?.entities.remove(pointEntity)
+		}
+	}
+
+	removeAllPoint () {
+		if (this.viewer) {
+			this.viewer?.entities?.removeAll()
+			// viewer?.scene?.primitives?.removeAll();
+		}
+	}
+
 	// 添加entity
 	addCustomImageryProviderDataSource (imageryLayers) {
-		console.log(imageryLayers, this.viewer, '---1-')
-
 		return this.viewer?.imageryLayers.addImageryProvider(imageryLayers)
 	}
 

--
Gitblit v1.9.3