便签不拦截事件:滚轮/右键穿透,左键改为canvas命中选中
This commit is contained in:
@@ -355,11 +355,9 @@ export class CesiumGlobe {
|
|||||||
m.tipY = m.noteNormal.tipY;
|
m.tipY = m.noteNormal.tipY;
|
||||||
m.normalUrl = m.noteNormal.canvas.toDataURL();
|
m.normalUrl = m.noteNormal.canvas.toDataURL();
|
||||||
m.selectedUrl = m.noteSelected.canvas.toDataURL();
|
m.selectedUrl = m.noteSelected.canvas.toDataURL();
|
||||||
|
m.screenX = -1e9;
|
||||||
|
m.screenY = -1e9;
|
||||||
el.style.backgroundImage = `url("${m.normalUrl}")`;
|
el.style.backgroundImage = `url("${m.normalUrl}")`;
|
||||||
el.addEventListener('click', (e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
this.onPick?.(m.index);
|
|
||||||
});
|
|
||||||
this._markerLayer.appendChild(el);
|
this._markerLayer.appendChild(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,17 +385,36 @@ export class CesiumGlobe {
|
|||||||
|
|
||||||
el.style.display = 'block';
|
el.style.display = 'block';
|
||||||
el.style.opacity = '1';
|
el.style.opacity = '1';
|
||||||
el.style.left = `${win.x - m.tipX}px`;
|
m.screenX = win.x - m.tipX;
|
||||||
el.style.top = `${win.y - m.tipY}px`;
|
m.screenY = win.y - m.tipY;
|
||||||
|
el.style.left = `${m.screenX}px`;
|
||||||
|
el.style.top = `${m.screenY}px`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_setupPick() {
|
_setupPick() {
|
||||||
const viewer = this.viewer;
|
const viewer = this.viewer;
|
||||||
// 移除 Viewer 默认的单击选中与双击“追踪实体”:否则双击后会锁定相机(定住)
|
// 移除 Viewer 默认的单击选中与双击“追踪实体”
|
||||||
// 标记便签已改为 DOM 覆盖层,点击由 DOM 元素自行处理
|
|
||||||
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
||||||
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_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:按下记录位置;松开不回正。中键:回正到“不倾斜不旋转”(天底 + 北朝上)
|
// 右键原生 tilt:按下记录位置;松开不回正。中键:回正到“不倾斜不旋转”(天底 + 北朝上)
|
||||||
|
|||||||
@@ -44,10 +44,8 @@ html, body {
|
|||||||
}
|
}
|
||||||
.marker-note {
|
.marker-note {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
pointer-events: auto;
|
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 气氛遮罩 */
|
/* 气氛遮罩 */
|
||||||
|
|||||||
Reference in New Issue
Block a user