@rsmap/vue3ol
Version:
使用 vue3 风格封装后的 Openlayer 地图组件库。
18 lines (16 loc) • 1.1 kB
TypeScript
import { Ref, ShallowRef } from 'vue';
import { Cluster, Source } from 'ol/source';
import { Layer } from 'ol/layer';
import { IfAny } from '@vue/shared';
/**
* Create a Source and watch for source, prop and layer changes
* @param SourceClass The Class of the source which should be created
* @param layer A `ref` carrying the parent components layer the layer should be applied to
* @param props A `ref` of the properties which should be passed to the SourceClass
* @param eventsToHandle The event names list for events that should be passed from the source through the component
*/
export default function useSource<T extends Source>(SourceClass: new (...args: any[]) => T, layer: Ref<Layer> | Ref<Cluster> | null | undefined, props: Ref<ConstructorParameters<typeof SourceClass>[0]>, eventsToHandle?: string[]): {
source: Ref<any> extends T ? T extends T & Ref<any> ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
updateSource: () => Ref<any> extends T ? T extends T & Ref<any> ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
removeSource: () => void;
};