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; } /* 气氛遮罩 */