3

このコードの何が問題なのか誰か教えてください。

    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);

指定された座標にボックスを表示しますが、ポリラインを描画しようとすると、次のエラーが発生します: Uncaught TypeError: Cannot read property 'push' of undefined ( https://cesiumjs.org/Cesium/Sourceの 300 行目) /DataSources/Entity.js )

このようなものが欲しい https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases

前もって感謝します。

4

1 に答える 1

2

エンティティ 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);
于 2015-05-18T13:17:17.117 に答える