Feat source (#765)

* feat: layer 初始化支持传入source 对象

* fix: l7 导出source

* fix: lint error

Co-authored-by: 象数 <zhengxue.lzx@antgroup.com>
This commit is contained in:
@thinkinggis 2021-10-11 14:15:27 +08:00 committed by GitHub
parent 02df900784
commit e37ae61516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import Source from '@antv/l7-source';
export * from '@antv/l7-core'; export * from '@antv/l7-core';
export * from '@antv/l7-scene'; export * from '@antv/l7-scene';
export * from '@antv/l7-maps'; export * from '@antv/l7-maps';
@ -5,3 +6,4 @@ export * from '@antv/l7-layers';
export * from '@antv/l7-component'; export * from '@antv/l7-component';
export * from '@antv/l7-utils'; export * from '@antv/l7-utils';
export * from './version'; export * from './version';
export { Source };

View File

@ -30,6 +30,7 @@ import {
IScale, IScale,
IScaleOptions, IScaleOptions,
IShaderModuleService, IShaderModuleService,
ISource,
ISourceCFG, ISourceCFG,
IStyleAttributeInitializationOptions, IStyleAttributeInitializationOptions,
IStyleAttributeService, IStyleAttributeService,
@ -451,6 +452,11 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
} }
public source(data: any, options?: ISourceCFG): ILayer { public source(data: any, options?: ISourceCFG): ILayer {
if (data?.data) {
// 判断是否为source
this.setSource(data);
return this;
}
this.sourceOption = { this.sourceOption = {
data, data,
options, options,

View File

@ -6,6 +6,7 @@ import {
IParseDataItem, IParseDataItem,
IParserCfg, IParserCfg,
IParserData, IParserData,
ISource,
ISourceCFG, ISourceCFG,
ITransform, ITransform,
lazyInject, 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; public data: IParserData;
// 数据范围 // 数据范围
@ -66,7 +67,7 @@ export default class Source extends EventEmitter {
private clusterIndex: Supercluster; private clusterIndex: Supercluster;
constructor(data: any, cfg?: ISourceCFG) { constructor(data: any | ISource, cfg?: ISourceCFG) {
super(); super();
// this.rawData = cloneDeep(data); // this.rawData = cloneDeep(data);
this.originData = data; this.originData = data;

View File

@ -1,6 +1,7 @@
// @ts-ignore // @ts-ignore
import { import {
Layers, Layers,
Source,
LineLayer, LineLayer,
PointLayer, PointLayer,
PolygonLayer, PolygonLayer,
@ -43,8 +44,10 @@ export default class World extends React.Component {
autoFit: true, autoFit: true,
}); });
const dataSource = new Source(data);
layer layer
.source(data) .source(dataSource)
.color('name', [ .color('name', [
'#2E8AE6', '#2E8AE6',
'#69D1AB', '#69D1AB',
@ -65,7 +68,7 @@ export default class World extends React.Component {
}); });
linelayer linelayer
.source(data) .source(dataSource)
.color('#fff') .color('#fff')
.size(1) .size(1)
.shape('line') .shape('line')