clampToHeight

fun clampToHeight(cartesian: Cartesian3, objectsToExclude: ReadonlyArray<Any>? = definedExternally, width: Double? = definedExternally, result: Cartesian3? = definedExternally): Cartesian3(source)

Clamps the given cartesian position to the scene geometry along the geodetic surface normal. Returns the clamped position or undefined if there was no scene geometry to clamp to. May be used to clamp objects to the globe, 3D Tiles, or primitives in the scene.

This function only clamps to globe tiles and 3D Tiles that are rendered in the current view. Clamps to all other primitives regardless of their visibility.

// Clamp an entity to the underlying scene geometry
const position = entity.position.getValue(JulianDate.now());
entity.position = viewer.scene.clampToHeight(position);

Return

The modified result parameter or a new Cartesian3 instance if one was not provided. This may be undefined if there was no scene geometry to clamp to.

Parameters

cartesian

The cartesian position.

objectsToExclude

A list of primitives, entities, or 3D Tiles features to not clamp to.

width

Width of the intersection volume in meters. Default value - 0.1

result

An optional object to return the clamped position.

See also