usePrimitiveScope
将 PrimitiveCollection 的增删操作范围化,并在组件卸载时自动移除创建的图元。
WARNING
这是一个底层辅助函数,主要供 usePrimitive 使用。除非你需要自定义集合管理逻辑,否则优先使用 usePrimitive。
Usage
ts
import { Primitive } from 'cesium';
import { usePrimitiveScope } from 'vesium';
const { add, remove } = usePrimitiveScope({
collection: 'ground',
});
const primitive = add(new Primitive({
geometryInstances: [],
}));
// 也支持异步创建
add(Promise.resolve(new Primitive({
geometryInstances: [],
})));说明
- 目标集合默认使用
useViewer().value.scene.primitives。 - 传入
collection: 'ground'时,会使用viewer.value.scene.groundPrimitives。 add支持 Promise,会在解析后自动加入集合。
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