我希望在不同的位置產生一定數量的shape1
和shape2
副本,這些副本只能在運行時才知道,並且能夠編程修改其他屬性。克隆和修改CZML包
提及,克隆和修改CZML包的首選方法是什麼?在加載時CzmlDataSource
var czml = [{
"id" : "document",
"name" : "CZML Geometries: Cones and Cylinders",
"version" : "1.0"
}, {
"id" : "shape1",
"name" : "Green cylinder with black outline",
"position" : {
"cartographicDegrees" : [-100.0, 40.0, 200000.0]
},
"cylinder" : {
"length" : 400000.0,
"topRadius" : 200000.0,
"bottomRadius" : 200000.0,
"material" : {
"solidColor" : {
"color" : {
"rgba" : [0, 255, 0, 128]
}
}
},
"outline" : true,
"outlineColor" : {
"rgba" : [0, 0, 0, 255]
}
}
}, {
"id" : "shape2",
"name" : "Red cone",
"position" : {
"cartographicDegrees" : [-105.0, 40.0, 200000.0]
},
"cylinder" : {
"length" : 400000.0,
"topRadius" : 0.0,
"bottomRadius" : 200000.0,
"material" : {
"solidColor" : {
"color" : {
"rgba" : [255, 0, 0, 255]
}
}
}
}
}];
var dataSource = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSource);
謝謝;澄清了很多。 「你不能直接克隆一個實體,但你可以從一個通用的選項對象中添加新的實體({options ...})到一個EntityCollection中,這個對象可以多次保存和重複使用。 「 如何提取從CZML數據包創建的「實體」對象的屬性(要保存到通用選項對象以供重用)? 請忍受我的沉悶;我來自C和C++的領域,並不熟悉JS的習語。 – Slaiyer
@Slaiyer這不是一個典型的代碼路徑,並且Cesium不直接支持它。一種選擇可能是完全跳過CZML,而是讓服務器提供實體創建模板對象。另一個選擇是使用[CzmlDataSource.process](http://cesiumjs.org/Cesium/Build/Documentation/CzmlDataSource.html#process)以循環方式重新提取ID已更改的czml數據包。 – emackey