From 25a7c967bbd7bb3852c12fb14d02582694e3c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Fri, 15 Aug 2025 14:20:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=E6=B7=BB=E5=8A=A0fl?= =?UTF-8?q?yto=E5=AE=9A=E4=BD=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/TextBox/index.js | 95 ++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/src/Obj/Base/TextBox/index.js b/src/Obj/Base/TextBox/index.js index e78e9a9..b97613b 100644 --- a/src/Obj/Base/TextBox/index.js +++ b/src/Obj/Base/TextBox/index.js @@ -2,6 +2,7 @@ * 文本框 */ import Base from "../index"; +import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global' class TextBox extends Base { constructor(sdk, options = {}) { // this.sdk = { ...sdk } @@ -39,10 +40,12 @@ class TextBox extends Base { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates( viewer.scene, posi ); - let width = dom.clientWidth * 1 - let height = dom.clientHeight * 1 - dom.style.left = `${position.x - width / 2}px`; - dom.style.top = `${position.y - height}px`; + if (position) { + let width = dom.clientWidth * 1 + let height = dom.clientHeight * 1 + dom.style.left = `${position.x - width / 2}px`; + dom.style.top = `${position.y - height}px`; + } } viewer.scene.postRender.addEventListener(that.handler); that.textDom = dom @@ -68,10 +71,12 @@ class TextBox extends Base { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates( that.sdk.viewer.scene, posi ); - let width = that.textDom.clientWidth * 1 - let height = that.textDom.clientHeight * 1 - that.textDom.style.left = `${position.x - width / 2}px`; - that.textDom.style.top = `${position.y - height}px`; + if (position) { + let width = that.textDom.clientWidth * 1 + let height = that.textDom.clientHeight * 1 + that.textDom.style.left = `${position.x - width / 2}px`; + that.textDom.style.top = `${position.y - height}px`; + } } that.sdk.viewer.scene.postRender.addEventListener(that.handler); } @@ -92,6 +97,80 @@ class TextBox extends Base { set positions(v) { this.options.positions = v } + async flyTo(options = {}) { + setActiveViewer(0) + closeRotateAround(this.sdk) + closeViewFollow(this.sdk) + + if (this.options.customView && this.options.customView.relativePosition && this.options.customView.orientation) { + let orientation = { + heading: Cesium.Math.toRadians(this.options.customView.orientation.heading || 0.0), + pitch: Cesium.Math.toRadians(this.options.customView.orientation.pitch || -60.0), + roll: Cesium.Math.toRadians(this.options.customView.orientation.roll || 0.0) + } + + let lng = this.options.customView.relativePosition.lng + let lat = this.options.customView.relativePosition.lat + let alt = this.options.customView.relativePosition.alt + let destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt) + + let position = { lng: 0, lat: 0 } + if (this.options.position) { + position = { ...this.options.position } + } + else if (this.options.positions) { + position = { ...this.options.positions[0] } + } + else if (this.options.center) { + position = { ...this.options.center } + } + else if (this.options.start) { + position = { ...this.options.start } + } + else { + if (this.options.hasOwnProperty('lng')) { + position.lng = this.options.lng + } + if (this.options.hasOwnProperty('lat')) { + position.lat = this.options.lat + } + if (this.options.hasOwnProperty('alt')) { + position.alt = this.options.alt + } + } + // 如果没有高度值,则获取紧贴高度计算 + // if (!position.hasOwnProperty('alt')) { + // position.alt = await this.getClampToHeight(position) + // } + lng = this.options.customView.relativePosition.lng + position.lng + lat = this.options.customView.relativePosition.lat + position.lat + alt = this.options.customView.relativePosition.alt + position.alt + destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt) + this.sdk.viewer.camera.flyTo({ + destination: destination, + orientation: orientation + }) + } + else { + let positionArray = [] + let a = Cesium.Cartesian3.fromDegrees( + this.positions.lng, + this.positions.lat, + this.positions.alt + ) + positionArray.push(a.x, a.y, a.z) + + let BoundingSphere = Cesium.BoundingSphere.fromVertices(positionArray) + this.viewer.camera.flyToBoundingSphere(BoundingSphere, { + offset: { + heading: Cesium.Math.toRadians(0.0), + pitch: Cesium.Math.toRadians(-20.0), + roll: Cesium.Math.toRadians(0.0) + } + }) + + } + } async remove() { if (this.handler) {