2015-05-18 23 views
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); 

它顯示盒在給定的座標,但是當我試圖繪製折線它給這個錯誤: 遺漏的類型錯誤:無法讀取未定義(上線https://cesiumjs.org/Cesium/Source/DataSources/Entity.js 300)的特性「推」

我想是提前這 https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases

感謝。

回答

1

你混合實體API(與名稱和描述可追蹤實體更高級別的API)與原始圖形API(下面的層,這只是顯示圖形元)。

編輯:看起來像斯科特雷諾茲也回答了你在mailing list你,你發佈了後續問題。在這裏,我借用了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); 
+0

非常感謝你@emackey。有用。但我想直立顯示折線。正如[這](https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases) – Mushu

+0

更新我的答案。 – emackey