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