3D-City Model
    Preparing search index...

    Viewshed – Encapsulates viewshed/visibility analysis as a dynamic shadow map using Cesium post-processing.

    Handles shadow map/camera creation, shader uniform management, FOV/frustum math, and in-scene interactive placement. Supports dynamic reconfiguration for colors, blending, size, field-of-view, depth bias, etc. Ties to two draggable PointEntity markers—"camera" and "target"—and auto-recomputes when they move.

    Application/viewer instance.

    Fragment shader code (GLSL).

    Overlay color for visible area.

    Overlay color for occluded area.

    Blend value for overlays.

    Shadow map size (resolution).

    Max draw distance.

    Bias for shadow computation.

    Camera field of view (degrees).

    Camera aspect ratio.

    Camera height above surface.

    Initial frustum definition.

    onSet(callback) - Register a callback for when the viewshed is positioned.

    cancel() - Cancel and destroy if not finalized/placed.

    destroy() - Remove shadow maps, scene primitives, and mark destroyed.

    _createShadowMap() - Build/refresh shadow map state for internal use.

    _addPostProcess() - Attach post-process/shader to the Cesium scene.

    _initUpdateListener() - Poll for shadow map readiness and manage shader activation.

    _updateShadowMap() - Updates the light camera and map according to view geometry.

    update(frameState) - Cesium update hook (pushed shadow map to frame state).

    const vs = new Viewshed(app, fsCode, { alpha: 0.7, maxDistance: 2500 });
    vs.onSet(() => { console.log("Viewshed ready!"); });
    // Interactively move vs.camera and vs.target in the scene.

    Hierarchy

    • Primitive
      • Viewshed
    Index

    Constructors

    • Parameters

      • app: any
      • viewshedFS: any
      • __namedParameters: {
            alpha?: number;
            aspectRatio?: number;
            depthBias?: number;
            fov?: number;
            frustum?: {
                bottom: number;
                far: number;
                left: number;
                near: number;
                right: number;
                top: number;
            };
            heightOffset?: number;
            lightColor?: Color;
            maxDistance?: number;
            shadowColor?: Color;
            size?: number;
        }
      • ...args: any = {}

      Returns Viewshed

    Properties

    _fovX: number
    _fovY: number
    _maxDistance: any
    _size: any
    allowPicking: boolean

    When true, each geometry instance will only be pickable with Scene#pick. When false, GPU memory is saved. *

    alpha: number

    Blend value for region coloring.

    app: any
    appearance: Appearance

    The Appearance used to shade this primitive. Each geometry instance is shaded with the same appearance. Some appearances, like PerInstanceColorAppearance allow giving each instance unique properties.

    aspectRatio: number

    Camera aspect ratio.

    asynchronous: boolean

    Determines if the geometry instances will be created and batched on a web worker.

    camera: PointEntity

    Movable entity marking the viewshed origin.

    compressVertices: boolean

    When true, geometry vertices are compressed, which will save memory.

    cull: boolean

    When true, the renderer frustum culls and horizon culls the primitive's commands based on their bounding volume. Set this to false for a small performance gain if you are manually culling the primitive.

    debugShowBoundingVolume: boolean

    This property is for debugging only; it is not for production use nor is it optimized.

    Draws the bounding sphere for each draw command in the primitive.

    depthBias: number

    Bias value for shadow map precision.

    depthFailAppearance: Appearance

    The Appearance used to shade this primitive when it fails the depth test. Each geometry instance is shaded with the same appearance. Some appearances, like PerInstanceColorAppearance allow giving each instance unique properties.

    When using an appearance that requires a color attribute, like PerInstanceColorAppearance, add a depthFailColor per-instance attribute instead.

    Requires the EXT_frag_depth WebGL extension to render properly. If the extension is not supported, there may be artifacts.

    destroyed: boolean

    True once resources are released.

    finished: boolean

    Set true once a camera/target have been positioned.

    fov: number

    Camera field of view in degrees.

    frustum: {
        bottom: number;
        far: number;
        left: number;
        near: number;
        right: number;
        top: number;
    }
    geometryInstances: GeometryInstance | GeometryInstance[]

    The geometry instances rendered with this primitive. This may be undefined if options.releaseGeometryInstances is true when the primitive is constructed.

    Changing this property after the primitive is rendered has no effect.

    interleave: boolean

    Determines if geometry vertex attributes are interleaved, which can slightly improve rendering performance.

    lightColor: Color

    RGBA color for visible region in the viewshed.

    modelMatrix: Matrix4

    The 4x4 transformation matrix that transforms the primitive (all geometry instances) from model to world coordinates. When this is the identity matrix, the primitive is drawn in world coordinates, i.e., Earth's WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by Transforms.eastNorthUpToFixedFrame.

    This property is only supported in 3D mode.

    const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0);
    p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
    onSetCallback: () => void
    postProcess: any
    preUpdateListener: any
    ready: boolean

    Determines if the primitive is complete and ready to render. If this property is true, the primitive will be rendered the next time that Primitive#update is called.

    // Wait for a primitive to become ready before accessing attributes
    const removeListener = scene.postRender.addEventListener(() => {
    if (!frustumPrimitive.ready) {
    return;
    }

    const attributes = primitive.getGeometryInstanceAttributes('an id');
    attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);

    removeListener();
    });
    releaseGeometryInstances: boolean

    When true, the primitive does not keep a reference to the input geometryInstances to save memory.

    shadowColor: Color

    RGBA color for non-visible region in the viewshed.

    shadowMap: undefined | ShadowMap
    shadows: ShadowMode

    Determines whether this primitive casts or receives shadows from light sources.

    show: boolean

    Determines if the primitive will be shown. This affects all geometry instances in the primitive.

    target: PointEntity

    Movable entity marking the viewshed focal point.

    vertexCacheOptimize: boolean

    When true, geometry vertices are optimized for the pre and post-vertex-shader caches.

    viewshedFS: any

    Accessors

    Methods

    • Internal: Attaches/shares the post-process viewshed shader and recipe to the scene.

      Returns void

    • Internal utility: Create/refresh Cesium shadow map for this viewshed, using interactive camera/target. Uses PerspectiveFrustum for the field-of-view and placement.

      Returns void

    • Internal: Initializes event listener to enable post-processing only after the shadow map texture becomes available.

      Returns void

    • Internal helper: Updates shadow map/camera/focus geometry as required (for movement/scale changes).

      Returns void

    • Cancels and destroys the viewshed tool if not yet finalized.

      Returns boolean

      True if cancelled (destroyed), false otherwise.

    • Cleans up and releases all resources: drops shadow maps, event listeners, camera/target markers, and scene entries.

      Returns void

    • Returns the modifiable per-instance attributes for a GeometryInstance.

      Parameters

      • id: any

        The id of the GeometryInstance.

      Returns any

      The typed array in the attribute's format or undefined if the is no instance with id.

      const attributes = primitive.getGeometryInstanceAttributes('an id');
      attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
      attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);
      attributes.distanceDisplayCondition = Cesium.DistanceDisplayConditionGeometryInstanceAttribute.toValue(100.0, 10000.0);
      attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(Cartesian3.IDENTITY);
    • Returns true if this object was destroyed; otherwise, false.

      If this object was destroyed, it should not be used; calling any function other than isDestroyed will result in a DeveloperError exception.

      Returns boolean

      true if this object was destroyed; otherwise, false.

    • Register a callback to be invoked when both camera and target points are set/placed.

      Parameters

      • callback: Function

      Returns void

    • Cesium per-frame update hook. Updates the shadow map state.

      Parameters

      • frameState: FrameState

      Returns void