我正在使用 cesium:http ://cesiumjs.org/ 我想让一些 div 漂浮在 cesium 地图上,但我无法让它工作。
我在 jsfiddle.net/j08691/dChUR/5/ 尝试了以下容器/标签方法 - 用铯映射 div 替换图像 - 但它似乎不起作用 - “标签” div 没有显示。
有什么帮助吗?
您需要在 CSS 中添加position: absolute;
和之一top
,bottom
因为该小部件也使用绝对定位。添加它会创建一个新的堆叠上下文,它会覆盖z-index
.
这是一个工作示例,点击底部的“运行代码片段”:
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0;
var viewer = new Cesium.Viewer('cesiumContainer', {
timeline: false,
animation: false,
navigationHelpButton: false
});
var skyAtmosphere = viewer.scene.skyAtmosphere;
var skyCheckbox = document.getElementById('skyCheckbox');
skyCheckbox.addEventListener('change', function() {
viewer.scene.skyAtmosphere = skyCheckbox.checked ? skyAtmosphere : undefined;
}, false);
html, body, #cesiumContainer {
width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
font-family: sans-serif; color: #edffff;
}
#controlPanel {
position: absolute;
top: 5px;
left: 5px;
background: rgba(42, 42, 42, 0.8);
padding: 5px 8px;
border-radius: 5px;
}
label {
cursor: pointer;
}
label:hover span {
text-decoration: underline;
}
<link href="http://cesiumjs.org/releases/1.15/Build/Cesium/Widgets/widgets.css"
rel="stylesheet"/>
<script src="http://cesiumjs.org/releases/1.15/Build/Cesium/Cesium.js">
</script>
<div id="cesiumContainer"></div>
<div id="controlPanel">
This is a floating control panel<br/>
with a translucent background color.
<p>
<label>
<input id="skyCheckbox" type="checkbox" checked />
<span>Enable atmospheric effect</span>
</label><br/>
<button class="cesium-button">Button 1</button>
<button class="cesium-button">Button 2</button>
</p>
</div>
要添加到emackey的答案,除了添加position: absolute
到我的 css 之外,我还必须添加一个top:150px
or bottom:150px
。基本上任何将指定相对于父容器的位置的东西。
即使使用绝对位置,它也很可能被 cesium 小部件向下推,因为它占据了 100% 的高度。