From 5b71877ae3c9434eacba53ddd5e358392fa85d3d Mon Sep 17 00:00:00 2001 From: fukunee Date: Sat, 19 Sep 2026 17:12:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=BF=E7=AD=BE=E9=94=9A=E7=82=B9=E8=B4=B4?= =?UTF-8?q?=E5=88=B0=E5=9C=B0=E5=BD=A2=E8=A1=A8=E9=9D=A2=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=94=BE=E5=A4=A7=E6=97=8B=E8=BD=AC=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=BC=82=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scene/CesiumGlobe.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/scene/CesiumGlobe.js b/src/scene/CesiumGlobe.js index 77b8b94..4dc03ad 100644 --- a/src/scene/CesiumGlobe.js +++ b/src/scene/CesiumGlobe.js @@ -299,6 +299,7 @@ export class CesiumGlobe { viewer.clock.shouldAnimate = false; this._buildMarkers(); + this._clampMarkersToTerrain(); this._setupPick(); this._setupRightRestore(); this._loadBoundaries(); @@ -327,6 +328,8 @@ export class CesiumGlobe { const noteNormal = makeStickyNote(entry.name, 16, false); const noteSelected = makeStickyNote(entry.name, 16, true); this.markers.push({ + lng: entry.lng, + lat: entry.lat, position, r2: Cesium.Cartesian3.magnitudeSquared(position), noteNormal, @@ -337,6 +340,29 @@ export class CesiumGlobe { this._initMarkerLayer(); } + // 把便签锚点贴到地形表面(否则在椭球面高度 0 上,放大旋转时会飘) + async _clampMarkersToTerrain() { + const scene = this.viewer.scene; + if (!scene || !scene.globe) return; + const cartos = this.markers.map((m) => + Cesium.Cartographic.fromDegrees(m.lng, m.lat), + ); + try { + await scene.sampleHeightMostDetailed(cartos); + } catch (err) { + console.warn('[CesiumGlobe] 地形高度采样失败,便签保持椭球面高度:', err); + return; + } + for (let i = 0; i < this.markers.length; i++) { + const h = cartos[i] && cartos[i].height; + if (h != null && isFinite(h)) { + const m = this.markers[i]; + m.position = Cesium.Cartesian3.fromDegrees(m.lng, m.lat, h); + m.r2 = Cesium.Cartesian3.magnitudeSquared(m.position); + } + } + } + // 便签用 DOM 覆盖层渲染:始终在城市/国家名上层,且缩放到最近也不会漂移 _initMarkerLayer() { const container = document.getElementById('cesium-container');