Skip to content

useDataSourceScope

Scope DataSourceCollection mutations so created data sources are removed automatically when the component unmounts.

WARNING

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

Usage

ts
import { CustomDataSource } from 'cesium';
import { useDataSourceScope } from 'vesium';

const { add, remove } = useDataSourceScope({
  destroyOnRemove: true,
});

const dataSource = add(new CustomDataSource('demo'));

// Async creation is also supported.
add(Promise.resolve(new CustomDataSource('async-demo')));

Notes

  • The target collection defaults to useViewer().value.dataSources.
  • destroyOnRemove is forwarded to dataSources.remove(dataSource, destroyOnRemove).
  • add accepts promises and adds the resolved data source to the collection.

Type Definitions

typescript
import type { CesiumDataSource } from '@vesium/shared';
import type { DataSourceCollection } from 'cesium';
import type { MaybeRefOrGetter } from 'vue';
export interface UseDataSourceScopeOptions {
    /**
     * The collection of DataSource to be added
     * @default useViewer().value.dataSources
     */
    collection?: MaybeRefOrGetter<DataSourceCollection | undefined>;
    /**
     * The second parameter passed to the `remove` function
     *
     * `dataSources.remove(dataSource,destroyOnRemove)`
     */
    destroyOnRemove?: boolean;
}
/**
 * Scope the SideEffects of `DataSourceCollection` operations and automatically remove them when unmounted
 */
export declare function useDataSourceScope(options?: UseDataSourceScopeOptions): import("..").UseCollectionScopeReturn<CesiumDataSource, any[], any[], any>;
//# sourceMappingURL=index.d.ts.map