editEntity
editEntity
simplifies the merging of entity properties and provides complete type hints. It is implemented based on Object.assign
, where options specified later will override options specified earlier. It offers comprehensive type hints and a much better development experience compared to manual operations without intelligent prompts.
Usage
This will change the material of the entity to red, and the height of the entity to 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,
},
},
)
Playground
js
editEntity(A, B)
{ "id": "123-456-789", "name": "my-entity", "position": "here", "label": { "text": "hi", "font": "bold" }, "billboard": { "image": "a/b/c.jpg" } }
Type Declarations
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