From 89d51a7f59fe8d4bf08285be879a7a65045c5fe9 Mon Sep 17 00:00:00 2001 From: fukunee Date: Sat, 19 Sep 2026 17:10:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BE=BF=E7=AD=BE=E4=B8=8D=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=EF=BC=9A=E6=BB=9A=E8=BD=AE/=E5=8F=B3?= =?UTF-8?q?=E9=94=AE=E7=A9=BF=E9=80=8F=EF=BC=8C=E5=B7=A6=E9=94=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BAcanvas=E5=91=BD=E4=B8=AD=E9=80=89=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scene/CesiumGlobe.js | 33 +++++++++++++++++++++++++-------- src/styles.css | 2 -- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/scene/CesiumGlobe.js b/src/scene/CesiumGlobe.js index 1970982..77b8b94 100644 --- a/src/scene/CesiumGlobe.js +++ b/src/scene/CesiumGlobe.js @@ -355,11 +355,9 @@ export class CesiumGlobe { m.tipY = m.noteNormal.tipY; m.normalUrl = m.noteNormal.canvas.toDataURL(); m.selectedUrl = m.noteSelected.canvas.toDataURL(); + m.screenX = -1e9; + m.screenY = -1e9; el.style.backgroundImage = `url("${m.normalUrl}")`; - el.addEventListener('click', (e) => { - e.stopPropagation(); - this.onPick?.(m.index); - }); this._markerLayer.appendChild(el); } @@ -387,17 +385,36 @@ export class CesiumGlobe { el.style.display = 'block'; el.style.opacity = '1'; - el.style.left = `${win.x - m.tipX}px`; - el.style.top = `${win.y - m.tipY}px`; + m.screenX = win.x - m.tipX; + m.screenY = win.y - m.tipY; + el.style.left = `${m.screenX}px`; + el.style.top = `${m.screenY}px`; } } _setupPick() { const viewer = this.viewer; - // 移除 Viewer 默认的单击选中与双击“追踪实体”:否则双击后会锁定相机(定住) - // 标记便签已改为 DOM 覆盖层,点击由 DOM 元素自行处理 + // 移除 Viewer 默认的单击选中与双击“追踪实体” viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK); viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK); + + // 便签层 pointer-events:none 后,左键通过 canvas 命中测试选中便签 + viewer.screenSpaceEventHandler.setInputAction((movement) => { + const x = movement.position.x; + const y = movement.position.y; + for (const m of this.markers) { + if (!m.el || m.el.style.display === 'none') continue; + const w = m.noteNormal.width; + const h = m.noteNormal.height; + if ( + x >= m.screenX && x <= m.screenX + w && + y >= m.screenY && y <= m.screenY + h + ) { + this.onPick?.(m.index); + break; + } + } + }, Cesium.ScreenSpaceEventType.LEFT_CLICK); } // 右键原生 tilt:按下记录位置;松开不回正。中键:回正到“不倾斜不旋转”(天底 + 北朝上) diff --git a/src/styles.css b/src/styles.css index 80be4e5..cfa5001 100644 --- a/src/styles.css +++ b/src/styles.css @@ -44,10 +44,8 @@ html, body { } .marker-note { position: absolute; - pointer-events: auto; background-repeat: no-repeat; background-size: 100% 100%; - cursor: pointer; } /* 气氛遮罩 */