定义简介
Entity是Cesium中的一个重要概念,它代表了在三维场景中的实体对象。这些实体可以是地球上的点、线、面,也可以是飞机、汽车、船舶等动态物体。
属性
Entity具有丰富的属性,包括位置、方向、速度、外观等。通过设置这些属性,开发者可以精确地控制实体在三维场景中的表现形式。
关联实体
基础属性 | 描述 |
---|---|
id | 唯一标识 |
name | 可读标识 |
show | 是否显示实体 |
description | 实体的html描述 |
position | 实体位置 |
orientation | 实体方向 |
viewFrom | 查看此实体对象的建议初始偏移量 |
parent | 与此实体关联的父实体 |
description设置一个html弹窗
description
属性被设置为包含HTML标记的字符串。这允许您以富文本的形式呈现描述,包括段落、链接等。
var viewer = new Cesium.Viewer('cesiumContainer');
var entity = viewer.entities.add({
name: 'Example Entity',
position: Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
description: '<p>This is a sample description for the entity.</p>'
});
// 点击实体时显示描述
viewer.selectedEntity = entity;
当Cesium Viewer中点击实体时,它将显示实体的描述信息
其表现效果和 new Cesium.SelectionIndicator 指示器部件相同
position位置信息
position位置又称为当前实体的坐标位置,常用的坐标位置有:(球坐标系和笛卡尔坐标系)
具体详情见文章:SuperMap iClient3D for WebGL ——坐标系(世界坐标、WGS84坐标系、平面直角坐标系)
orientation当前模型的方向
一般存在方向的都是一些模型(飞机、汽车等),在方向上我们最常用的是
new Cesium.HeadingPitchRoll ( heading , pitch , roll )
heading:航向
pitch:螺距
roll:滚动
官方介绍:
航向是从当地北部来的旋转正角向东增加的方向。俯仰是从本地东西向平面的旋转。正俯仰角在飞机上方。负俯仰角在平面下方。横摇是绕局部东轴应用的第一次旋转。
const position = Cesium.Cartesian3.fromDegrees(104.1, 30.6,500);
const heading = 0;
const pitch = 0;
const roll = 0;
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
const orientation = Cesium.Transforms.headingPitchRollQuaternion(
position,
hpr
);
const addModeEntity = window.viewer.entities.add({
name: '测试1',
id:"cs1",
position: position,
orientation: orientation,
model: {
uri: '/static/SampleData/gltf/客机模型/客机模型.gltf',
scale:0.1,
minimumPixelSize:0.1,
maximumScale: 20,
shadows:true,
color:Cesium.Color.RED,
colorBlendMode:Cesium.ColorBlendMode.MIX// Cesium.ColorBlendMode.REPLACE//
},
});
window.viewer.trackedEntity = addModeEntity;
window.viewer.flyTo(window.viewer.entities.getById("cs1"))
相关Entity的方法实例
添加属性
viewer.entities.add()
删除指定id的实体
viewer.entities.removeById(1)
这个id就是实体entity的id
删除全部实体
viewer.entities.removeAll()
实体中材质(material)
Material在Cesium中负责定义实体的外观特性,如颜色、透明度、纹理等。
- ColorMaterial(颜色材质): 允许开发者定义实体的颜色,从而为实体添加生动的色彩。
entity.material = new Cesium.ColorMaterialProperty(Cesium.Color.RED);
- ImageMaterial(图片材质): 允许将图片应用到实体上,以展示详细的纹理。
entity.material = new Cesium.ImageMaterialProperty({
image: 'path/to/texture.png',
});
- CheckerboardMaterial(棋盘格材质): 创建一个有趣的棋盘格效果,使实体更具视觉吸引力。
entity.material = new Cesium.CheckerboardMaterialProperty({
evenColor: Cesium.Color.WHITE,
oddColor: Cesium.Color.BLACK,
repeat: new Cesium.Cartesian2(8, 8),
});