From 4247327bfa9835873a0a19d29731a13d67c8924b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Sat, 23 Aug 2025 00:07:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=A1=86=E4=BD=8D=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/TextBox/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Obj/Base/TextBox/index.js b/src/Obj/Base/TextBox/index.js index 0179243..8a974d9 100644 --- a/src/Obj/Base/TextBox/index.js +++ b/src/Obj/Base/TextBox/index.js @@ -54,7 +54,6 @@ class TextBox extends Base { // 配置CSS样式和内容结构 viewer.cesiumWidget.container.appendChild(dom); let posi = Cesium.Cartesian3.fromDegrees(that.options.position.lng.toFixed(4), that.options.position.lat.toFixed(4), that.options.position.alt.toFixed(4)) - that.handler = function () { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates( viewer.scene, posi @@ -80,12 +79,15 @@ class TextBox extends Base { var cartographic = Cesium.Cartographic.fromCartesian(cartesian); var longitude = Cesium.Math.toDegrees(cartographic.longitude); var latitude = Cesium.Math.toDegrees(cartographic.latitude); + + let height = await that.getClampToHeight({ lng: longitude, lat: latitude }) that.position = { lng: longitude, lat: latitude, - alt: cartographic.height + // alt: cartographic.height + alt: height } - let posi = Cesium.Cartesian3.fromDegrees(longitude.toFixed(4), latitude.toFixed(4), cartographic.height.toFixed(4)) + let posi = Cesium.Cartesian3.fromDegrees(longitude.toFixed(4), latitude.toFixed(4), height.toFixed(4)) that.handler = function () { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates( From 5ceaa3b649719b79e7ccac1fafb62193c85942f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Sat, 23 Aug 2025 01:17:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/TextBox/index.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Obj/Base/TextBox/index.js b/src/Obj/Base/TextBox/index.js index 8a974d9..5c6f3da 100644 --- a/src/Obj/Base/TextBox/index.js +++ b/src/Obj/Base/TextBox/index.js @@ -53,7 +53,7 @@ class TextBox extends Base { // 配置CSS样式和内容结构 viewer.cesiumWidget.container.appendChild(dom); - let posi = Cesium.Cartesian3.fromDegrees(that.options.position.lng.toFixed(4), that.options.position.lat.toFixed(4), that.options.position.alt.toFixed(4)) + let posi = Cesium.Cartesian3.fromDegrees(that.options.position.lng, that.options.position.lat, that.options.position.alt) that.handler = function () { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates( viewer.scene, posi @@ -71,8 +71,16 @@ class TextBox extends Base { } async setHandeler(data) { let that = this - const ray = this.sdk.viewer.camera.getPickRay(new Cesium.Cartesian2(data.x, data.y)); - var cartesian = this.sdk.viewer.scene.globe.pick(ray, this.sdk.viewer.scene); + + let cartesian = this.sdk.viewer.scene.pickPosition(new Cesium.Cartesian2(data.x, data.y)); //屏幕坐标转为笛卡尔空间坐标 + // if (!cartesian) return; + + // let c = Cesium.Cartographic.fromCartesian(position); + if (!cartesian) { + const ray = this.sdk.viewer.camera.getPickRay(new Cesium.Cartesian2(data.x, data.y)); + cartesian = this.sdk.viewer.scene.globe.pick(ray, this.sdk.viewer.scene); + } + if (Cesium.defined(cartesian)) { that.sdk.viewer.scene.postRender.removeEventListener(that.handler); @@ -84,10 +92,10 @@ class TextBox extends Base { that.position = { lng: longitude, lat: latitude, - // alt: cartographic.height - alt: height + alt: cartographic.height + // alt: height } - let posi = Cesium.Cartesian3.fromDegrees(longitude.toFixed(4), latitude.toFixed(4), height.toFixed(4)) + let posi = Cesium.Cartesian3.fromDegrees(longitude, latitude, cartographic.height) that.handler = function () { const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(