Skip to content

KBE3D / KBCore / Cesium / ModelFeature

类: ModelFeature

A feature of a Model. <p> Provides access to a feature's properties stored in the model's feature table. </p> <p> Modifications to a <code>ModelFeature</code> object have the lifetime of the model. </p> <p> Do not construct this directly. Access it through picking using Scene#pick. </p>

示例

ts
// On mouse over, display all the properties for a feature in the console log.
handler.setInputAction(function(movement) {
    const feature = scene.pick(movement.endPosition);
    if (feature instanceof Cesium.ModelFeature) {
        console.log(feature);
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

参数

Object with the following properties:

参数

The model the feature belongs to.

参数

The unique integral identifier for this feature.

属性

show

show: boolean

Gets or sets if the feature will be shown. This is set for all features when a style's show is evaluated.


color

color: Color

Gets or sets the highlight color multiplied with the feature's color. When this is white, the feature's color is not changed. This is set for all features when a style's color is evaluated.


featureId

readonly featureId: number

Get the feature ID associated with this feature. For 3D Tiles 1.0, the batch ID is returned. For EXT_mesh_features, this is the feature ID from the selected feature ID set.

方法

hasProperty()

hasProperty(name: string): boolean

Returns whether the feature contains this property.

参数

name

string

The case-sensitive name of the property.

返回

boolean

Whether the feature contains this property.


getProperty()

getProperty(name: string): any

Returns a copy of the value of the feature's property with the given name.

参数

name

string

The case-sensitive name of the property.

返回

any

The value of the property or undefined if the feature does not have this property.

示例

ts
// Display all the properties for a feature in the console log.
const propertyIds = feature.getPropertyIds();
const length = propertyIds.length;
for (let i = 0; i < length; ++i) {
    const propertyId = propertyIds[i];
    console.log(propertyId + ': ' + feature.getProperty(propertyId));
}

getPropertyInherited()

getPropertyInherited(name: string): any

Returns a copy of the feature's property with the given name, examining all the metadata from the EXT_structural_metadata and legacy EXT_feature_metadata glTF extensions. Metadata is checked against name from most specific to most general and the first match is returned. Metadata is checked in this order: <ol> <li>structural metadata property by semantic</li> <li>structural metadata property by property ID</li> </ol> <p> See the EXT_structural_metadata Extension

as well as the previous EXT_feature_metadata Extension for glTF. </p>

参数

name

string

The semantic or property ID of the feature. Semantics are checked before property IDs in each granularity of metadata.

返回

any

The value of the property or undefined if the feature does not have this property.


getPropertyIds()

getPropertyIds(results?: string[]): string[]

Returns an array of property IDs for the feature.

参数

results?

string[]

An array into which to store the results.

返回

string[]

The IDs of the feature's properties.


setProperty()

setProperty(name: string, value: any): boolean

Sets the value of the feature's property with the given name.

参数

name

string

The case-sensitive name of the property.

value

any

The value of the property that will be copied.

返回

boolean

true if the property was set, false otherwise.

Examples

ts
const height = feature.getProperty('Height'); // e.g., the height of a building
ts
const name = 'clicked';
if (feature.getProperty(name)) {
    console.log('already clicked');
} else {
    feature.setProperty(name, true);
    console.log('first click');
}

构造函数

构造函数

new ModelFeature(options: { model: Model; featureId: number; }): ModelFeature

参数

options
model

Model

featureId

number

返回

ModelFeature

KBE3D @3.0.0 Copyright © 2024-present KBE3D