javascript - CesiumJS - 使用带有广告牌的弹出窗口?
问题描述
我最近一直在做一个 CesiumJS 项目,并且我已经成功地在我的地球上实现了广告牌。当用户单击其中一个广告牌时,我想将它们带到特定网站。这显示在代码中:
const viewer = new Cesium.Viewer('cesiumContainer');
var example = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
billboard: {
image: "../images/example.png",
},
});
example.linkForPick = 'https://www.example.com/';
viewer.screenSpaceEventHandler.setInputAction(function(mouse) {
var pickedObject = viewer.scene.pick(mouse.position);
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id.linkForPick)) {
window.open(pickedObject.id.linkForPick, "_self");
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
但是,我想要发生的是,当用户单击广告牌时,会在弹出窗口中显示一个带有该链接网站的模式弹出窗口。我有 javascript 代码在 html 页面上实现它:
Javascript:
document.getElementById("link").onclick = function(e) {
e.preventDefault();
document.getElementById("popupdarkbg").style.display = "block";
document.getElementById("popup").style.display = "block";
document.getElementById('popupiframe').src = "http://example.com";
document.getElementById('popupdarkbg').onclick = function() {
document.getElementById("popup").style.display = "none";
document.getElementById("popupdarkbg").style.display = "none";
};
return false;
}
window.onkeydown = function(e) {
if (e.keyCode == 27) {
document.getElementById("popup").style.display = "none";
document.getElementById("popupdarkbg").style.display = "none";
e.preventDefault();
return;
}
}
HTML:
<div id="main">
<a href="" id="link">Click me</a><br>
</div>
<div id="popup"><iframe id="popupiframe"></iframe></div>
<div id="popupdarkbg"></div>
CSS:
#popup { display: none; position: fixed; top: 12%; left: 15%; width: 70%; height: 70%; background-color: white; z-index: 10; }
#popup iframe { width: 100%; height: 100%; border: 0; }
#popupdarkbg { position: fixed; z-index: 5; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; background-color: rgba(0,0,0,.75); display: none; }
但是,我很难理解如何使这两个代码块一起工作。因此,当用户单击广告牌时,模式弹出窗口应显示与该广告牌关联的网站。
有谁可以帮助我了解如何进行这项工作?
提前致谢,
Ĵ
解决方案
推荐阅读
- python - 我试图了解计算 RGB 图像每个通道的平均值的过程
- cmake - 如何在使用 Qt Creator 和 CMake 构建 aws-sdk-cpp 后执行“make install”步骤
- java - Jackson mixin 在序列化和反序列化时被忽略
- ios - 如何启用/禁用导航栏按钮 [XCode] (swift)
- javascript - EJS 不显示页面
- power-bi-report-server - 如何在 POWERBI 中使用 Web Anonymous Method 应用计划刷新?
- python - 使用函数从 webscrape 创建数据框
- google-apps-script - 您如何允许共享 Google 表格的用户运行其在库中的功能?
- jupyter-notebook - 将 Jupyter 笔记本转换为原生 Python 中的 html 输出
- flutter - 在颤振中开发 PWA 时无法检查错误日志