Skip to content

Commit

Permalink
feat(source): wip cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Dec 4, 2019
1 parent 7d7b5e9 commit 3203959
Show file tree
Hide file tree
Showing 20 changed files with 6,485 additions and 10 deletions.
46 changes: 46 additions & 0 deletions examples/tutorial/data/demo/data_update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Scene, PointLayer } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
const scene = new Scene({
id: 'map',
map: new GaodeMap({
style: 'light',
pitch: 0,
center: [ 120.19382669582967, 30.258134 ],
zoom: 5
})
});

const radius = 0.1;

function pointOnCircle(angle) {
return {
type: 'FeatureCollection',
features: [{
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [ 120.19382669582967 + Math.cos(angle) * radius, 30.258134 + Math.sin(angle) * radius ]
}
}]
};
}
const layer = new PointLayer()
.source(pointOnCircle(0))
.shape('circle')
.size(15) // default 1
.color('#2F54EB')
.style({
stroke: 'rgb(255,255,255)',
strokeWidth: 2,
opacity: 1
});
scene.addLayer(layer);
function animateMarker(timestamp) {
layer.setData(pointOnCircle(timestamp / 1000));
requestAnimationFrame(animateMarker);
}
layer.on('inited', () => {
animateMarker(0);
});

7 changes: 5 additions & 2 deletions examples/tutorial/data/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
"demos": [
{
"filename": "line.js",
"title": "json数据"",
"screenshot": ""
"title": "json数据"
},
{
"filename": "data_update.js",
"title": "数据更新"
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
"site:clean": "gatsby clean",
"site:deploy": "yarn run site:build && gh-pages -d public",
"site:publish": "gh-pages -d public",
"lint:fix": "prettier --write docs/api/**/*.md packages/**/*.{spec,story}.ts{,x} stories/**/**/*.tsx",
"lint:examples": "eslint examples/**/**/*.js --fix",
"lint-fix": "prettier --write docs/api/**/*.md",
"lin-examples": "eslint examples/**/**/*.js --fix",
"prebuild": "run-p tsc lint",
"build": "yarn clean && lerna run build",
"postbuild": "yarn build:declarations",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/services/layer/ILayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface ILayer {
render(): ILayer;
destroy(): void;
source(data: any, option?: ISourceCFG): ILayer;
setData(data: any, option?: ISourceCFG): ILayer;
/**
* 向当前图层注册插件
* @param plugin 插件实例
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/services/source/ISourceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ export interface ITransform {
}

export interface ISourceCFG {
cluster?: boolean;
clusterOptions?: Partial<IClusterOptions>;
parser?: IParserCfg;
transforms?: ITransform[];
}
export interface IClusterOptions {
enable: false;
radius: number;
maxZoom: number;
minZoom: number;
field: string;
method: 'max' | 'sum' | 'min' | 'mean' | 'count' | CallBack;
}
export interface IDictionary<TValue> {
[key: string]: TValue;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/layers/src/core/BaseLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter

// 获取插件集
this.plugins = this.container.getAll<ILayerPlugin>(TYPES.ILayerPlugin);
console.log(this.plugins)
// 完成插件注册,传入场景和图层容器内的服务
for (const plugin of this.plugins) {
plugin.apply(this, {
Expand Down Expand Up @@ -338,6 +339,16 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
};
return this;
}

public setData(data: any, options?: ISourceCFG) {
this.sourceOption.data = data;
this.sourceOption.options = options;
console.time('init')
this.hooks.init.call();
console.timeEnd('init')
this.buildModels();
return this;
}
public style(options: object & Partial<ILayerConfig>): ILayer {
const { passes, ...rest } = options;

Expand Down Expand Up @@ -456,6 +467,12 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
// 解绑图层容器中的服务
// this.container.unbind(TYPES.IStyleAttributeService);
}
public clear() {

this.styleAttributeService.clearAllAttributes();
// 销毁所有 model
this.models.forEach((model) => model.destroy());
}

public isDirty() {
return !!(
Expand Down
2 changes: 2 additions & 0 deletions packages/layers/src/plugins/DataMappingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class DataMappingPlugin implements ILayerPlugin {
}: { styleAttributeService: IStyleAttributeService },
) {
layer.hooks.init.tap('DataMappingPlugin', () => {
console.time('DataMappingPlugin')
const attributes = styleAttributeService.getLayerStyleAttributes() || [];
const { dataArray } = layer.getSource().data;

Expand All @@ -37,6 +38,7 @@ export default class DataMappingPlugin implements ILayerPlugin {

// mapping with source data
layer.setEncodedData(this.mapping(attributes, dataArray));
console.timeEnd('DataMappingPlugin')
});

// remapping before render
Expand Down
2 changes: 2 additions & 0 deletions packages/layers/src/plugins/DataSourcePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { injectable } from 'inversify';
export default class DataSourcePlugin implements ILayerPlugin {
public apply(layer: ILayer) {
layer.hooks.init.tap('DataSourcePlugin', () => {
console.time('DataSourcePlugin')
const { data, options } = layer.sourceOption;
layer.setSource(new Source(data, options));
console.timeEnd('DataSourcePlugin')
});
}
}
2 changes: 2 additions & 0 deletions packages/layers/src/plugins/FeatureScalePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export default class FeatureScalePlugin implements ILayerPlugin {
}: { styleAttributeService: IStyleAttributeService },
) {
layer.hooks.init.tap('FeatureScalePlugin', () => {
console.time('FeatureScalePlugin')
this.scaleOptions = layer.getScaleOptions();
const attributes = styleAttributeService.getLayerStyleAttributes();
const { dataArray } = layer.getSource().data;
this.caculateScalesForAttributes(attributes || [], dataArray);
console.timeEnd('FeatureScalePlugin')
});

layer.hooks.beforeRender.tap('FeatureScalePlugin', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/layers/src/plugins/PixelPickingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class PixelPickingPlugin implements ILayerPlugin {
) {
// TODO: 由于 Shader 目前无法根据是否开启拾取进行内容修改,因此即使不开启也需要生成 a_PickingColor
layer.hooks.init.tap('PixelPickingPlugin', () => {
console.time('PixelPickingPlugin')
const { enablePicking } = layer.getLayerConfig();
styleAttributeService.registerStyleAttribute({
name: 'pickingColor',
Expand All @@ -55,6 +56,7 @@ export default class PixelPickingPlugin implements ILayerPlugin {
enablePicking ? encodePickingColor(featureIdx) : [0, 0, 0],
},
});
console.timeEnd('PixelPickingPlugin')
});
// 必须要与 PixelPickingPass 结合使用,因此必须开启 multiPassRenderer
// if (layer.multiPassRenderer) {
Expand Down
2 changes: 2 additions & 0 deletions packages/layers/src/plugins/RegisterStyleAttributePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export default class RegisterStyleAttributePlugin implements ILayerPlugin {
}: { styleAttributeService: IStyleAttributeService },
) {
layer.hooks.init.tap('RegisterStyleAttributePlugin', () => {
console.time('RegisterStyleAttributePlugin')
this.registerBuiltinAttributes(styleAttributeService);
console.timeEnd('RegisterStyleAttributePlugin')
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/layers/src/plugins/ShaderUniformPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
public apply(layer: ILayer) {
layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {
// 重新计算坐标系参数
console.time('ShaderUniformPlugin')
this.coordinateSystemService.refresh();

const { width, height } = this.rendererService.getViewportSize();
Expand Down Expand Up @@ -58,7 +59,7 @@ export default class ShaderUniformPlugin implements ILayerPlugin {
u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
}),
);

console.timeEnd('ShaderUniformPlugin')
// TODO:脏检查,决定是否需要渲染
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/layers/src/plugins/UpdateStyleAttributePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export default class UpdateStyleAttributePlugin implements ILayerPlugin {
styleAttributeService,
}: { styleAttributeService: IStyleAttributeService },
) {
layer.hooks.beforeRender.tap('UpdateStyleAttributePlugin', () => {
layer.hooks.init.tap('UpdateStyleAttributePlugin', () => {
console.time('UpdateStyleAttributePlugin')
const attributes = styleAttributeService.getLayerStyleAttributes() || [];
attributes
.filter((attribute) => attribute.needRegenerateVertices)
Expand All @@ -38,6 +39,7 @@ export default class UpdateStyleAttributePlugin implements ILayerPlugin {
`regenerate vertex attributes: ${attribute.name} finished`,
);
});
console.timeEnd('UpdateStyleAttributePlugin')
});
}
}
Loading

0 comments on commit 3203959

Please sign in to comment.