Skip to content

usePrimitiveScope

Scope PrimitiveCollection mutations so created primitives are removed automatically when the component unmounts.

WARNING

This is a low-level helper used by usePrimitive. Prefer usePrimitive unless you need custom collection management.

Usage

ts
import { Primitive, PrimitiveCollection } from 'cesium';
import { usePrimitiveScope } from 'vesium';

const { add, remove } = usePrimitiveScope({
  collection: 'ground',
});

const primitive = add(new Primitive({
  geometryInstances: [],
}));

// Async creation is also supported.
add(Promise.resolve(new Primitive({
  geometryInstances: [],
})));

Notes

  • The target collection defaults to useViewer().value.scene.primitives.
  • Pass collection: 'ground' to use viewer.value.scene.groundPrimitives.
  • add accepts promises and adds the resolved primitive to the collection.

Type Definitions

typescript
import type { PrimitiveCollection } from 'cesium';
import type { MaybeRefOrGetter } from 'vue';
export interface UsePrimitiveScopeOptions {
    /**
     * The collection of Primitive to be added,
     * 'ground' alias `useViewer().value.scene.groundPrimitives`
     * @default useViewer().value.scene.primitives
     */
    collection?: MaybeRefOrGetter<PrimitiveCollection | 'ground' | undefined>;
}
/**
 * Make `add` and `remove` operations of `PrimitiveCollection` scoped,
 * automatically remove `Primitive` instance when component is unmounted.
 */
export declare function usePrimitiveScope(options?: UsePrimitiveScopeOptions): {
    scope: Readonly<import("vue").ShallowReactive<Set<any>>>;
    add: <R extends any>(instance: R, ...args: any[]) => R extends Promise<infer U> ? Promise<U> : any;
    remove: (instance: any, ...args: any[]) => any;
    removeWhere: (predicate: import("..").EffcetRemovePredicate<any>, ...args: any[]) => void;
    removeScope: (...args: any[]) => void;
};
//# sourceMappingURL=index.d.ts.map