Search code examples
javascripthtmlcssdjangocesiumjs

Overlay a toolbar over Cesium Viewer/Map


Hi I am trying to overlay a toolbar on the Cesium Viewer/Map but whenever I try to do the div class = toolbar like in the sandcastle example, the buttons or anything I add always shows up under the map. I want something like this: https://i.sstatic.net/1TUlx.jpg

Here's what I have so far:

Index.html

<html>
<head>
    <title>Demo</title>

</head>

<body>
     {% load staticfiles%}
     <script src= {% static "js/Cesium.js"  %} type="text/javascript"></script>
     <div id="cesiumContainer"></div>
     <div class="toolbar-left">
    <button onclick="alert('You clicked!');">Click me!</button>
    </div>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'test/hello.css' %}" />
     <script>
        var viewer = new Cesium.Viewer('cesiumContainer');
     </script>
</body> 
</html>

Solution

  • Fix was to explicitly add a style tag inside the html file to declare toolbar-left

            #cesiumContainer {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
                overflow: hidden;
            }
    
            .toolbar-left {
                display: block;
                position: absolute;
                top: 5px;
                left: 5px;
            }