Appearance
概述
实体(Entity)表示高层封装的可视对象 ,是 Cesium 提供的一个简单、数据驱动、高层 API,用于在场景中方便地创建和管理各种图形对象。
创建点线面
javascript
// 创建点
viewer.entities.add({
id: "point1",
position: Cesium.Cartesian3.fromDegrees(121.47, 31.23, 100),
point: {
pixelSize: 12,
color: Cesium.Color.YELLOW,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 2,
}
})
// 创建线
viewer.entities.add({
id: "line1",
polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights([
120.0, 30.0, 100000,
121.0, 31.0, 100000,
122.0, 30.5, 100000
]),
width: 4,
material: Cesium.Color.RED,
clampToGround: false,
}
})
// 创建面
viewer.entities.add({
id: "polygon1",
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
120.0, 30.0,
121.0, 30.0,
121.0, 31.0,
120.0, 31.0
]),
material: Cesium.Color.fromCssColorString("#ffff00").withAlpha(0.4),
}
})跟踪实体
通过 viewer.zoomTo / viewer.flyTo 实现跟踪实体效果。
javascript
viewer.zoomTo(viewer.entities).then(() => {
viewer.camera.zoomOut(10000)
})