Responsive DIVs in CesiumViewer [CesiumJS]

2019-07-07 01:11发布

问题:

I am working on customizing a Cesium map that has an overlay with a variety of information inside, the style of the overlay I'm implementing with bootsrap, unfortunately the divs that I put remain in a specific position and ignore the resizing of the page. Is there a way to make a DIV added to cesium viewer responsive?

What i do now is

    var position = Cesium.Cartesian3.fromDegrees(-76.59777, 39.03883);
    var scratch = new Cesium.Cartesian2();
    
    var canvasPosition = viewer.scene.cartesianToCanvasCoordinates(position, scratch);
    
    viewer.scene.preRender.addEventListener(function () {
        if (Cesium.defined(canvasPosition)) {
            
            htmlOverlayBoxInfo.style.left = '600px';
            htmlOverlayBoxInfo.style.top = '180px';
            
        }
    });
<div id="box-info" style="position: absolute" class="circles push-50 visibility">

            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn">
                <span class="circle circle-0"></span>
            </div>
            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn" data-timeout="100">
                <span class="circle circle-1"></span>
            </div>
            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn" data-timeout="200">
                <span class="circle circle-2"></span>
            </div>
            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn" data-timeout="300">
                <span class="circle circle-3"></span>
            </div>
            <div class="visibility-hidden " data-toggle="appear" data-class="animated fadeIn" data-timeout="400">
                <span class="circle circle-4"></span>
            </div>
            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn" data-timeout="500">
                <span class="circle circle-5"></span>
            </div>
            <div class="visibility-hidden" data-toggle="appear" data-class="animated fadeIn" data-timeout="600">
                <span class="circle circle-6"></span>
            </div>

            <span class="circle circles-main-content visibility-hidden" data-toggle="appear"
                  data-class="animated fadeIn" data-timeout="100">
                <h4>
                    New </h4>

                             </span>
        </div>

I am forced to put [style="position: absolute"] otherwise the div I need to overlay the map is not displayed at all. What am I doing wrong?

回答1:

I will solve the problem using Reactjs to do all the data presentation. Expanding this: https://www.npmjs.com/package/cesium-react