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);
效果如圖:html
經過CZML也能夠添加幾何形狀,並且CZML還能夠描述動畫(如今先有個印象,動畫之後介紹)學習
先來看看官網上的說明,CZML是一種JSON格式的字符串,用於描述與時間有關的動畫場景,CZML包含點、線、地標、模型、和其餘的一些圖形元素,並指明瞭這些元素如何隨時間而變化。某種程度上說, Cesium 和 CZML的關係就像 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);
能夠看到單個的形狀和Entity的描述基本一致,只不過是使用JSON語法來描述,關於形狀描述能夠參考官方API,下一節列出形狀的相關信息網站
下表來自於官方網站,可是鏈接改成本地連接了ui
Point | ![]() |
entity.point - Reference Build/Documentation |
Boxes | ![]() |
entity.box - Code example - Reference Build/Documentation |
Circles and Ellipses | ![]() |
entity.ellipse - Code example - Reference Build/Documentation |
Corridor | ![]() |
entity.corridor - Code example - Reference Build/Documentation |
Cylinder and Cones | ![]() |
entity.cylinder - Code example - Reference Build/Documentation |
Polygons | ![]() |
entity.polygon - Code example - Reference Build/Documentation |
Polylines | ![]() |
entity.polyline - Code example - Reference Build/Documentation |
Polyline Volumes | ![]() |
entity.polylineVolume - Code example - Reference Build/Documentation |
Rectangles | ![]() |
entity.rectangle - Code example - Reference Build/Documentation |
Spheres and Ellipsoids | ![]() |
entity.ellipsoid - Code example - Reference Build/Documentation |
Walls | ![]() |
entity.wall - Code example - Reference Build/Documentation |
我的主頁 http://cesium.xin Cesium學習交流羣:593764057code