在铯中显示一条折线(有一定高度)



谁能告诉我这段代码有什么问题?

    Cesium.Math.setRandomNumberSeed(1234);
    var viewer = new Cesium.Viewer('cesiumContainer');
    var entities = viewer.entities;
    var boxes = entities.add(new Cesium.Entity());
    var polylines = new Cesium.PolylineCollection();
    //Create the entities and assign each entity's parent to the group to which it belongs.
    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 : {
                width : new Cesium.ConstantProperty(2),
                material : Cesium.Color.fromRandom({alpha : 1.0}),
                followSurface : new Cesium.ConstantProperty(false)
            }
        });
    }
    viewer.zoomTo(viewer.entities);

它显示框在给定的坐标,但当我试图画一个多线段,它给出了这个错误:未捕获的类型错误:无法读取未定义的属性'push'(在https://cesiumjs.org/Cesium/Source/DataSources/Entity.js的第300行)

我想要这样的东西https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&标签=展示

你将实体API(带有带有名称和描述的可跟踪实体的高级API)与原始图形API(下面的层,只显示图形原语)混合在一起。

编辑:看起来Scott Reynolds也在邮件列表中为你回答了这个问题,你发布了一个后续问题。这里我借用了Scott的"竖线"代码,删除了"父"关系,因为它们似乎没有在这里使用,并为所有实体添加了可点击的信息框描述。

Cesium.Math.setRandomNumberSeed(1234);
var viewer = new Cesium.Viewer('cesiumContainer');
var entities = viewer.entities;
var prevHeight = 0.0;
for (var i = 0; i < 5; ++i) {
    var height = 100000.0 + (200000.0 * i);
    entities.add({
        name : 'Box ' + i,
        description : 'This box is at height: ' + height.toLocaleString() + ' m',
        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({
        name : 'Line ' + i,
        description : 'This line is from height ' + prevHeight.toLocaleString() +
            ' m to height ' + height.toLocaleString() + ' m',
        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);

最新更新