cesium-动态数据格式CZML介绍
CZML定义
CZML是Cesium团队制定的一种用来描述动态场景的JSON架构语言,可以用来描述点、线、多边形、体、模型及其他图元,同时定义它们是怎样随时间变化的。CZML采用数据驱动的方式完成场景加载渲染,开发者在CZML中定义场景数据类型、交互信息、时间节点等内容,不需要额外的代码便可构建出丰富的场景。
Cesium与CZML的关系就如同Google Earth和KML的关系。CZML和KML都是用来描述场景的数据格式,KML是由XML语言定义的,而CZML是特定格式的JSON。开发者可以通过其他语言生成CZML文件,然后由Cesium调用,也可以前端接收到数据后,直接生成CZML对象并调用。
- CZML是基于JSON定义的语言。
- CZML大多数属性都可随时间变化。假如有一辆车,分别定义了两个不同时间的位置。通过CZML定义的差值算法,客户端可以准确地显示车在两个时间点内运动的过程。
- CZML的结构可向客户端高效增量流式传输。在显示场景之前,不需要在客户端上加载整个场景数据,可随时间变化增量传输到场景中。
- CZML是高度优化的语言,旨在解析时更紧凑,人工读写更容易。
- CZML是一个开放的格式,支持在其基础上进一步扩展功能和特性。
CZML数据结构
CZML是JSON的一个子集,也就是说一个有效的CZML文档同时也是一个有效的JSON文档。CZML文档包含一个JSON数组,数组中每个对象都是一个CZML数据包(packet),其中第一个packet是CZML的固定格式,只有设定这个固定的packet,Cesium才会识别这是CZML,否则当作普通数组处理。
具体代码如下所示:
{
"id": "document",
"name": "CZML Path",
"version": "1.0",
"clock": {
"interval": "2012-08-04T10:00:00Z/2012-08-04T15:00:00Z",
"currentTime": "2012-08-04T10:00:00Z",
"multiplier": 10
}
}
- id:固定值
- name:可自定义设置值
- version:CZML版本,CZL目前只有1.0版本,固定值
- clock:设置CZML的时间信息,可选项
完整的CZML至少包合两个packet,第一个用于标识CZML,第二个packet对应一个场景中的对象,例如一架飞机。
[
{ //packet one
"id": "document",
"name": "CZML Path",
"version": "1.0",
"clock": {
"interval": "2012-08-04T10:00:00Z/2012-08-04T15:00:00Z",
"currentTime": "2012-08-04T10:00:00Z",
"multiplier": 10
}
},
{ //packet two
"id": "GroundControlStation",
"position": {
"cartographicDegrees": [
-75.5,
40.0,
0.0
]
},
"point": {
"color": {
"rgba": [
0,
0,
255,
255
]
}
}
}
]
每个packet都有一个id属性,标示当前描述的对象。id 在同一个CZML中及与它载人同一个范围(scope)内的其他CZML文件中必须是唯一的。假如没有指定id。那么客户端将随机自动生成唯一的id。但是这样在随后的包中就无法引用它了,例如无法再往该对象中添加数据。
除了id,一个包通常还包含0到多个(正常情况下是1到多个)定义对象图形特征的属性。正如上面的例子,定义了一个“GroundControlStation"对象,它拥有 一个固定坐标为(-75.0,40.0)的WGS-84坐标,高度为0,随后蓝色的点将会绘制在其坐标位置处。
CZML还有很多标准的属性,包括用来添加点、布告板、模型、线及其他图形到场景的属性。
CZML内容
CZML能表示的内容类型非常丰富,既包括基础图形绘制,也支持三维模型、墙、路径、标签、公告板等对象,而且为每个对象设置了丰富的属性。
属性名称 | 重要子属性 |
---|---|
point(点) | show,color,pixSize,outlineColor,outlineWidth,scaleByDistance,and translucencyByDistance |
polyline(折线) | show,position,material,width,granularity,and followSurface |
rectangle(长方形) | show,position,height,extrudedHeight,granularity,rotation,stRotation,fill,outline,outlineColor,outlineColor,outlineWidth,closeBottom,and closeTop |
polygon(多边形) | show,postion,height,extrudedHeight,material,outline,outlineColor,outlineWidth,granularity,fill,perPositionHeight,and stRotation |
ellipse(椭圆) | show,semiMajorAxis,semiMoinorAxis,rotation,material,height,extrudedHeight,granuarity,stRotation,fill,numberOfVerticalLines,outline,outlineColor,and outlineWidth |
box(盒子) | show,dimensions,fill, material, outline,outlineColor,and outlineWidth |
corridor(走廊) | show,positions,width,height,cornerType,extruded- Height,fill,material,outline,granularity,outlineColor,and outlineWidth |
cylinder(圆筒) | show,length,topRadius,bottomRadius,fill,material,numberOfVerticalLines,slices,outlines,outlineColor,and outlineWidth |
polylineVolume(折线体积) | show,position,shape,cornerType fill material,outline,granularity,outlineColor,and outlineWidth |
ellipsoid(椭球体) | show,radii,fill,material, outline,outlineColor,outlineWidth,stackPartitions slicePartitions and subdivisions |
wall(墙) | show,positions,material,minimumHeights,maximumHeights,granularity,fill, outline,outlineColor and outlineWidth |
model(模型) | show,gltf,scale,runAnimations,incrementallyLoadTextures,minimumPixelSize,maximumScale,and nodeTransformations |
path(小路) | show,material,width,resolution,leadTime and trailTime |
label(标签) | show,textm style,font,scale,fillColor,outlineColor,outlineWidth,eyeOffset,translucencyByDistance,pixeloffset,horizontalOrigin,verticalOrigion,and pixelOffsetScaleByDistance |
billboard(广告牌) | show,image,color,eyeOffset,horizontalOrigion,verticalOrigin,pixelOffset,scale,rotation,width,height,scaleByDistance,imageSubRegion,sizeInMeters,and alignedAxis |