diff --git a/packages/l7/src/index.ts b/packages/l7/src/index.ts index 242d1c912c..dafcc0cee3 100644 --- a/packages/l7/src/index.ts +++ b/packages/l7/src/index.ts @@ -1,3 +1,4 @@ +import Source from '@antv/l7-source'; export * from '@antv/l7-core'; export * from '@antv/l7-scene'; export * from '@antv/l7-maps'; @@ -5,3 +6,4 @@ export * from '@antv/l7-layers'; export * from '@antv/l7-component'; export * from '@antv/l7-utils'; export * from './version'; +export { Source }; diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index 29e467f321..e190a60c5d 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -30,6 +30,7 @@ import { IScale, IScaleOptions, IShaderModuleService, + ISource, ISourceCFG, IStyleAttributeInitializationOptions, IStyleAttributeService, @@ -451,6 +452,11 @@ export default class BaseLayer extends EventEmitter } public source(data: any, options?: ISourceCFG): ILayer { + if (data?.data) { + // 判断是否为source + this.setSource(data); + return this; + } this.sourceOption = { data, options, diff --git a/packages/source/src/source.ts b/packages/source/src/source.ts index c0c04cc45b..cd83ddc4ef 100644 --- a/packages/source/src/source.ts +++ b/packages/source/src/source.ts @@ -6,6 +6,7 @@ import { IParseDataItem, IParserCfg, IParserData, + ISource, ISourceCFG, ITransform, lazyInject, @@ -35,7 +36,7 @@ function mergeCustomizer(objValue: any, srcValue: any) { } } -export default class Source extends EventEmitter { +export default class Source extends EventEmitter implements ISource { public data: IParserData; // 数据范围 @@ -66,7 +67,7 @@ export default class Source extends EventEmitter { private clusterIndex: Supercluster; - constructor(data: any, cfg?: ISourceCFG) { + constructor(data: any | ISource, cfg?: ISourceCFG) { super(); // this.rawData = cloneDeep(data); this.originData = data; diff --git a/stories/Layers/components/polygon_line.tsx b/stories/Layers/components/polygon_line.tsx index cc65d0d42c..8f5d5bd634 100644 --- a/stories/Layers/components/polygon_line.tsx +++ b/stories/Layers/components/polygon_line.tsx @@ -1,6 +1,7 @@ // @ts-ignore import { Layers, + Source, LineLayer, PointLayer, PolygonLayer, @@ -43,8 +44,10 @@ export default class World extends React.Component { autoFit: true, }); + const dataSource = new Source(data); + layer - .source(data) + .source(dataSource) .color('name', [ '#2E8AE6', '#69D1AB', @@ -65,7 +68,7 @@ export default class World extends React.Component { }); linelayer - .source(data) + .source(dataSource) .color('#fff') .size(1) .shape('line')