cesium编程入门(五)绘制形状

通过Entity添加形状

先来看一个添加立方体的例子

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

通过CZML添加

通过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,下一节列出形状的相关信息

形状相关描述

下表来自于官方网站,但是连接改为本地链接了

   
PointpointGeometry.pngentity.point - Reference Build/Documentation
BoxesboxGeometry.pngentity.box - Code example - Reference Build/Documentation
Circles and EllipsesellipseGeometry.pngentity.ellipse - Code example - Reference Build/Documentation
CorridorcorridorGeometry.pngentity.corridor - Code example - Reference Build/Documentation
Cylinder and ConescylinderGeometry.pngentity.cylinder - Code example - Reference Build/Documentation
PolygonspolygonGeometry.pngentity.polygon - Code example - Reference Build/Documentation
PolylinespolylineGeometry.pngentity.polyline - Code example - Reference Build/Documentation
Polyline VolumespolylineVolumeGeometry.pngentity.polylineVolume - Code example - Reference Build/Documentation
RectanglesextentGeometry.pngentity.rectangle - Code example - Reference Build/Documentation
Spheres and EllipsoidsellipsoidGeometry.pngentity.ellipsoid - Code example - Reference Build/Documentation
WallswallGeometry.pngentity.wall - Code example - Reference Build/Documentation

个人主页 http://cesium.xin Cesium学习交流群:593764057

转载于:https://my.oschina.net/u/592443/blog/1604249

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值