editEntity
简化合并实体属性的操作,并且带有完整的类型提示。基于Object.assign
实现,后面的选项会覆盖前面的选项。他拥有完整的类型提示,和无智能提示的手动操作相比,editEntity
开发体验要好得多。
使用
这会将entity的材质改为红色,高度改为1:
js
const entity = viewer.entities.add({
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([-100, 30, -80, 70, -10, 40])
}
})
editEntity(
entity,
{
polygon: {
height: 1,
material: Cesium.Color.AQUA,
},
},
{
polygon: {
material: Cesium.Color.RED,
},
},
)
演练场
js
editEntity(A, B)
{ "id": "123-456-789", "name": "my-entity", "position": "here", "label": { "text": "hi", "font": "bold" }, "billboard": { "image": "a/b/c.jpg" } }
类型声明
Details
ts
/**
* Merge `Entity.ConstructorOptions` two depths deep.
*
* ## example
*
* ```js
* editEntity(
* { name: '1' },
* { name: '2' }
* )
* // { name: '2' }
*
* editEntity(
* {
* label: { text: 'foo', font: 'bar' }
* },
* {
* label: { font: 'bold' }
* }
* )
* // { label: { text: 'foo', font: 'bold' } } // two depths deep
* ```
*/
export declare function editEntity<
T extends Entity | Entity.ConstructorOptions,
>(entity: T, ...args: Entity.ConstructorOptions[]): T