Cesiumjs – How to draw a polyline from one height to the next.

phpmind-cesiumjs-draw-poly-lines

Cesium.Math.setRandomNumberSeed(1234);

    var viewer = new Cesium.Viewer('cesiumContainer');
    var entities = viewer.entities;
    var boxes = entities.add(new Cesium.Entity());
    var polylines = entities.add(new Cesium.Entity());

    //Create the entities and assign each entity's parent to the group to which it belongs.
    var prevHeight = 0.0;
    for (var i = 0; i < 5; ++i) {
        var height = 100000.0 + (200000.0 * i);
        entities.add({
            parent : boxes,
            position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
            box : {
                dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
                material : Cesium.Color.fromRandom({alpha : 1.0})
            }
        });
        entities.add({
            parent : polylines,
            position : Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height),
            polyline : {
                positions: [
                    Cesium.Cartesian3.fromDegrees(-86.0, 55.0, prevHeight),
                    Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height)
                ],
                width : new Cesium.ConstantProperty(2),
                material : Cesium.Color.fromRandom({alpha : 1.0}),
                followSurface : new Cesium.ConstantProperty(false)
            }
        });
        
        prevHeight = height;
    }
    viewer.zoomTo(viewer.entities);
Share

Leave a Reply

Your email address will not be published. Required fields are marked *