diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index 8f46684654..3134472e24 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -434,10 +434,10 @@ export default class BaseLayer extends EventEmitter public setData(data: any, options?: ISourceCFG) { if (this.inited) { - this.layerSource.setData(data); + this.layerSource.setData(data, options); } else { this.on('inited', () => { - this.layerSource.setData(data); + this.layerSource.setData(data, options); }); } diff --git a/packages/source/src/source.ts b/packages/source/src/source.ts index 4a27000d68..ba40800f55 100644 --- a/packages/source/src/source.ts +++ b/packages/source/src/source.ts @@ -58,22 +58,7 @@ export default class Source extends EventEmitter { super(); // this.rawData = cloneDeep(data); this.originData = data; - if (cfg) { - if (cfg.parser) { - this.parser = cfg.parser; - } - if (cfg.transforms) { - this.transforms = cfg.transforms; - } - this.cluster = cfg.cluster || false; - if (cfg.clusterOptions) { - this.cluster = true; - this.clusterOptions = { - ...this.clusterOptions, - ...cfg.clusterOptions, - }; - } - } + this.initCfg(cfg); this.hooks.init.tap('parser', () => { this.excuteParser(); @@ -87,9 +72,10 @@ export default class Source extends EventEmitter { this.init(); } - public setData(data: any) { + public setData(data: any, options?: ISourceCFG) { this.rawData = data; this.originData = data; + this.initCfg(options); this.init(); this.emit('update'); } @@ -161,6 +147,24 @@ export default class Source extends EventEmitter { return feature?._id; } + private initCfg(cfg?: ISourceCFG) { + if (cfg) { + if (cfg.parser) { + this.parser = cfg.parser; + } + if (cfg.transforms) { + this.transforms = cfg.transforms; + } + this.cluster = cfg.cluster || false; + if (cfg.clusterOptions) { + this.cluster = true; + this.clusterOptions = { + ...this.clusterOptions, + ...cfg.clusterOptions, + }; + } + } + } private excuteParser(): void { const parser = this.parser; const type: string = parser.type || 'geojson'; diff --git a/stories/District/Layer/world.tsx b/stories/District/Layer/world.tsx index dc9a7f8af6..7f6c4be666 100644 --- a/stories/District/Layer/world.tsx +++ b/stories/District/Layer/world.tsx @@ -26,10 +26,10 @@ export default class Country extends React.Component { scene.on('loaded', () => { const Layer = new WorldLayer(scene, { data: [], - bubble: { - enable: false, + joinBy: ['SOC', 'SOC'], + fill: { color: { - field: 'NAME_CHN', + field: 'value', values: [ '#feedde', '#fdd0a2', @@ -47,12 +47,32 @@ export default class Country extends React.Component { field: 'NAME_CHN', }, popup: { - enable: false, + enable: true, Html: (props: any) => { - return `${props.NAME_CHN}`; + return `${props.NAME_CHN + ':' + props.value}`; }, }, }); + Layer.on('loaded', () => { + console.log('完成'); + Layer.updateData( + [ + { + SOC: 'CHN', + value: 3000, + }, + { + SOC: 'CAN', + value: 5000, + }, + { + SOC: 'RUS', + value: 4000, + }, + ], + ['SOC', 'SOC'], + ); + }); }); this.scene = scene; }