MeasurementSnapping

new IonSdkMeasurements.MeasurementSnapping(options)

Snapping settings for the measurement tools. Changes apply immediately to every tool sharing this instance.
Name Type Description
options MeasurementSnapping.ConstructorOptions optional Initialization options.
Example:
const bridge = await Cesium.IonSnapService.fromAssetId(bridgeAssetId);
const building = await Cesium.IonSnapService.fromAssetId(buildingAssetId);
viewer.extend(viewerMeasureMixin, {
  snapping: {
    service: (feature) =>
      feature.primitive === bridgeTileset ? bridge : building,
  },
});
viewer.measure.viewModel.snapping.client = false;

Members

client : Boolean

Snap picks to nearby edges via Scene#snap.
Default Value: true

readonly disableModifier : KeyboardEventModifier

Modifier key that suppresses snapping while held.

readonly errorEvent : Event

Raised with the error when a snapping service request fails; the point keeps its client position. If there are no listeners, the error is logged to the console.

getElementId : MeasurementSnapping.ElementIdCallback

Returns the elementId passed to SnapService#snap for a picked feature.
Example:
// For a tileset that isn't from the BIM/CAD tiler, read its own numeric id
// property; otherwise use the default (`element`).
const snapping = viewer.measure.viewModel.snapping;
const getBimCadElementId = snapping.getElementId;
snapping.getElementId = (feature) =>
  feature.primitive === otherTileset
    ? `${feature.getProperty("id")}`
    : getBimCadElementId(feature);

service : SnapService|MeasurementSnapping.ServiceCallback|undefined

The SnapService used to refine placed points, or a function returning one for a picked feature.

Type Definitions

IonSdkMeasurements.MeasurementSnapping.ConstructorOptions

Initialization options for the MeasurementSnapping constructor.
Properties:
Name Type Attributes Default Description
client Boolean <optional>
true Snap picks to nearby edges via Scene#snap. On by default; set to false to opt out. Surfaces use the exact cursor pick; a surface snap is only used when nothing else is under the cursor.
service SnapService | MeasurementSnapping.ServiceCallback <optional>
Opt-in server-side refinement: a SnapService, e.g. an IonSnapService, or a function returning the service for a picked feature. Each point is refined asynchronously after it's placed (on click), starting from its client-snapped position; labels show "≈" until the result arrives. Off unless provided.
getElementId MeasurementSnapping.ElementIdCallback <optional>
Returns the elementId passed to SnapService#snap for a picked feature. Defaults to the feature's numeric element property (set by BIM/CAD tilesets), formatted as a decimal string for IonSnapService.
disableModifier KeyboardEventModifier <optional>
KeyboardEventModifier.ALT Modifier key that suppresses snapping while held. Only read by MeasurementMouseHandler. Avoid SHIFT, which some tools already use (e.g. direction clamping in HorizontalMeasurement).

IonSdkMeasurements.MeasurementSnapping.ElementIdCallback(feature) → String|undefined

Returns the SnapService element id for a picked feature. Called for each placed point that a service refines.
Name Type Description
feature Object The picked feature, e.g. a Cesium3DTileFeature.
Returns:
The element id, or undefined to skip refinement.

IonSdkMeasurements.MeasurementSnapping.ServiceCallback(feature) → SnapService|undefined

Returns the snapping service for a picked feature.
Name Type Description
feature Object The picked feature, e.g. a Cesium3DTileFeature.
Returns:
The service, or undefined to skip refinement.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.