通過(guò)Entity添加形狀
先來(lái)看一個(gè)添加立方體的例子
var viewer = new Cesium.Viewer('cesiumContainer');
var redBox = **viewer.entities.add**({
name : 'Red box with black outline',
position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
box : {
dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK
}
});
viewer.zoomTo(viewer.entities);
效果如圖:

Jietu20180108-214130.jpg
通過(guò)CZML添加
通過(guò)CZML也可以添加幾何形狀,而且CZML還可以描述動(dòng)畫(huà)(現(xiàn)在先有個(gè)印象,動(dòng)畫(huà)以后介紹)
先來(lái)看看官網(wǎng)上的說(shuō)明,CZML是一種JSON格式的字符串,用于描述與時(shí)間有關(guān)的動(dòng)畫(huà)場(chǎng)景,CZML包含點(diǎn)、線、地標(biāo)、模型、和其他的一些圖形元素,并指明了這些元素如何隨時(shí)間而變化。某種程度上說(shuō), Cesium 和 CZML的關(guān)系就像 Google Earth 和 KML。
var czml = [{
"id" : "document",
"name" : "box",
"version" : "1.0"
},{
"id" : "shape2",
"name" : "Red box with black outline",
"position" : {
"cartographicDegrees" : [-107.0, 40.0, 300000.0]
},
"box" : {
"dimensions" : {
"cartesian": [400000.0, 300000.0, 500000.0]
},
"material" : {
"solidColor" : {
"color" : {
"rgba" : [255, 0, 0, 128]
}
}
},
"outline" : true,
"outlineColor" : {
"rgba" : [0, 0, 0, 255]
}
}
}];
var viewer = new Cesium.Viewer('cesiumContainer');
var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);
viewer.zoomTo(dataSourcePromise);
可以看到單個(gè)的形狀和Entity的描述基本一致,只不過(guò)是使用JSON語(yǔ)法來(lái)描述,關(guān)于形狀描述可以參考官方API,下一節(jié)列出形狀的相關(guān)信息
形狀相關(guān)描述
下表來(lái)自于官方網(wǎng)站,但是連接改為本地鏈接了
| ? | ? | ? |
|---|---|---|
| Point | ![]() pointGeometry.png
|
entity.point - Reference Build/Documentation |
| Boxes | ![]() boxGeometry.png
|
entity.box - Code example - Reference Build/Documentation |
| Circles and Ellipses | ![]() ellipseGeometry.png
|
entity.ellipse - Code example - Reference Build/Documentation |
| Corridor | ![]() corridorGeometry.png
|
entity.corridor - Code example - Reference Build/Documentation |
| Cylinder and Cones | ![]() cylinderGeometry.png
|
entity.cylinder - Code example - Reference Build/Documentation |
| Polygons | ![]() polygonGeometry.png
|
entity.polygon - Code example - Reference Build/Documentation |
| Polylines | ![]() polylineGeometry.png
|
entity.polyline - Code example - Reference Build/Documentation |
| Polyline Volumes | ![]() polylineVolumeGeometry.png
|
entity.polylineVolume - Code example - Reference Build/Documentation |
| Rectangles | ![]() extentGeometry.png
|
entity.rectangle - Code example - Reference Build/Documentation |
| Spheres and Ellipsoids | ![]() ellipsoidGeometry.png
|
entity.ellipsoid - Code example - Reference Build/Documentation |
| Walls | ![]() wallGeometry.png
|
entity.wall - Code example - Reference Build/Documentation |
個(gè)人主頁(yè) http://cesium.xin
Cesium學(xué)習(xí)交流群:593764057(滿),476893082










