便签不拦截事件:滚轮/右键穿透,左键改为canvas命中选中

This commit is contained in:
2026-09-19 17:10:07 +08:00
parent 9df646c91c
commit 89d51a7f59
2 changed files with 25 additions and 10 deletions
+25 -8
View File
@@ -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:按下记录位置;松开不回正。中键:回正到“不倾斜不旋转”(天底 + 北朝上)
-2
View File
@@ -44,10 +44,8 @@ html, body {
}
.marker-note {
position: absolute;
pointer-events: auto;
background-repeat: no-repeat;
background-size: 100% 100%;
cursor: pointer;
}
/* 气氛遮罩 */