跳至内容

useEntityScope

将“EntityCollection”操作的副作用范围化,并在卸载时自动删除

Usage

ts
TODO;

Type Definitions

typescript
import type { Entity, EntityCollection } from 'cesium';
import type { MaybeRefOrGetter, ShallowReactive } from 'vue';
import type { EffcetRemovePredicate } from '../useCollectionScope';
export interface UseEntityScopeOptions {
    /**
     * The collection of Entity to be added
     * @default useViewer().value.entities
     */
    collection?: MaybeRefOrGetter<EntityCollection>;
}
export interface UseEntityScopeRetrun {
    /**
     * A `Set` for storing SideEffect instance,
     * which is encapsulated using `ShallowReactive` to provide Vue's reactive functionality
     */
    scope: Readonly<ShallowReactive<Set<Entity>>>;
    /**
     * Add SideEffect instance
     */
    add: <T extends Entity>(entity: T) => T;
    /**
     * Remove specified SideEffect instance
     */
    remove: (entity: Entity, destroy?: boolean) => boolean;
    /**
     * Remove all SideEffect instance that meets the specified criteria
     */
    removeWhere: (predicate: EffcetRemovePredicate<Entity>, destroy?: boolean) => void;
    /**
     * Remove all SideEffect instance within current scope
     */
    removeScope: (destroy?: boolean) => void;
}
/**
 * Make `add` and `remove` operations of `EntityCollection` scoped,
 * automatically remove `Entity` instance when component is unmounted.
 */
export declare function useEntityScope(options?: UseEntityScopeOptions): UseEntityScopeRetrun;