Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5/Cesium - making divs float over cesium map

Tags:

html

cesium

I am using cesium : http://cesiumjs.org/ and I wanted to make some divs float over a cesium map, but I can't get it to work.

I tried the following container/tag method at jsfiddle.net/j08691/dChUR/5/ - substituing the image by a cesium map div - but it doesn't seem to work - the "tag" div isn't shown.

Any help?

like image 338
user967710 Avatar asked Jun 13 '14 13:06

user967710


1 Answers

You need to add position: absolute; and either top or bottom to your CSS, because the widget also uses absolute positioning. Adding this creates a new stacking context, which overrides z-index.

Here's a working example, hit "Run Code Snippet" at the bottom of this:

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>
like image 66
emackey Avatar answered Sep 18 '22 14:09

emackey