Skip to content

BaseSource

BaseSource 是一个基础组件,用于定义数据源。

API

sourceProps

属性名说明类型默认值
minzoom源最小缩放级别number0
maxzoom源最大缩放级别number22
attribution源名称string-
volatile是否本地缓存booleanfalse

baseSourceProps

属性名说明类型默认值
id源的IDstring-
options源的配置项object必填

sourceEmits

事件名说明回调参数
load源加载完成后触发Function

Inject

hooks/symbol.ts
typescript
export const sourceKey: InjectionKey<ShallowRef<Source | undefined>> = Symbol('Source')
hooks/useSource.ts
ts
export function useSource<T extends Source>() {
  const source = inject(sourceKey)
  if (!source) {
    throw new Error('No Source provided')
  }
  return unref(source) as T
}

类型定义

SourceLoadEvent

sources/BaseSource/BaseSource.ts
typescript
export interface SourceLoadEvent {
  source: any
  map: Map
}

SourcexcludeProps

sources/BaseSource/BaseSource.ts
typescript
export type SourcexcludeProps<T> = Omit<T, 'type'>

基于 MIT 许可发布