import type { Source } from 'maplibre-gl'; import { ref, type Ref, unref } from 'vue'; export class SourceLib { private static readonly REFS = new Map>(); static genSourceOpts(type: string, props: object, sourceOpts: Array): T { return Object.keys(props) .filter(opt => (props as any)[ opt ] !== undefined && sourceOpts.indexOf(opt as any) !== -1) .reduce((obj, opt) => { (obj as any)[ opt ] = unref((props as any)[ opt ]); return obj; }, { type } as T); } static getSourceRef(mcid: number, source: any): Ref { const isString = typeof source === 'string', key = String(mcid) + (isString ? source : ''); let r = SourceLib.REFS.get(key); if (!r) { r = ref(isString ? null : undefined); SourceLib.REFS.set(key, r); } return r as Ref; } }