Merge pull request #228 from antvis/fix/qbi-color-size-update

Fix/qbi color size update
This commit is contained in:
@thinkinggis 2020-02-27 11:26:30 +08:00 committed by GitHub
commit ff9f568a2b
8 changed files with 16 additions and 9 deletions

View File

@ -13,7 +13,7 @@ export default React.memo(function Chart(props: ILayerProps) {
color.field color.field
? layer.color(color.field as StyleAttrField, color.values) ? layer.color(color.field as StyleAttrField, color.values)
: layer.color(color.values as StyleAttrField); : layer.color(color.values as StyleAttrField);
}, [color.field, color.scale, JSON.stringify(color.values)]); }, [color.field, color.scale, JSON.stringify(color.values), JSON.stringify(color.options)]);
return null; return null;
}); });

View File

@ -13,6 +13,6 @@ export default React.memo(function Chart(props: ILayerProps) {
if (filter.field) { if (filter.field) {
layer.filter(filter.field as string, filter.values as StyleAttrField); layer.filter(filter.field as string, filter.values as StyleAttrField);
} }
}, [filter.field, filter.values, JSON.stringify(filter.values)]); }, [filter.field, filter.values, JSON.stringify(filter.values), JSON.stringify(filter.options)]);
return null; return null;
}); });

View File

@ -60,10 +60,6 @@ export default function BaseLayer(type: string, props: ILayerProps) {
// 重绘layer // 重绘layer
if (layer) { if (layer) {
mapScene.render(); mapScene.render();
// 如果autoFit为true执行自适应操作
if (options?.autoFit) {
layer.fitBounds();
}
} }
}); });

View File

@ -13,6 +13,6 @@ export default React.memo(function Chart(props: ILayerProps) {
shape.field shape.field
? layer.shape(shape.field, shape.values) ? layer.shape(shape.field, shape.values)
: layer.shape(shape.values as StyleAttrField); : layer.shape(shape.values as StyleAttrField);
}, [shape.field, JSON.stringify(shape.values)]); }, [shape.field, JSON.stringify(shape.values), JSON.stringify(shape.options)]);
return null; return null;
}); });

View File

@ -13,6 +13,6 @@ export default React.memo(function Chart(props: ILayerProps) {
size.field size.field
? layer.size(size.field, size.values) ? layer.size(size.field, size.values)
: layer.size(size.values as StyleAttrField); : layer.size(size.values as StyleAttrField);
}, [size.field, JSON.stringify(size.values), size.scale]); }, [size.field, size.scale, JSON.stringify(size.values), JSON.stringify(size.options)]);
return null; return null;
}); });

View File

@ -17,6 +17,11 @@ export default React.memo(function Chart(props: ISourceProps) {
} else { } else {
layer.setData(data, sourceOption); layer.setData(data, sourceOption);
} }
// 临时解决:若开启,每次更新之后自适应缩放;
// TODO是否可以统一到Layer的option里目前问题是Layer的autoFit一直为true无法触发更新
if (sourceOption.autoFit) {
layer.fitBounds();
}
}, [data, JSON.stringify(sourceOption)]); }, [data, JSON.stringify(sourceOption)]);
return null; return null;
}); });

View File

@ -22,6 +22,9 @@ export interface IAttributeOptions {
values: string[] | number[] | string | number | CallBack; values: string[] | number[] | string | number | CallBack;
scale?: string; scale?: string;
blend: keyof typeof BlendType; blend: keyof typeof BlendType;
options?: {
[key: string]: any;
};
} }
export interface IScaleAttributeOptions { export interface IScaleAttributeOptions {
@ -49,6 +52,8 @@ export interface IStyleOptions {
export interface ISourceOptions extends ISourceCFG { export interface ISourceOptions extends ISourceCFG {
data: any; data: any;
// 每次更新数据之后是否自适应缩放
autoFit: boolean;
} }
export interface IActiveOptions { export interface IActiveOptions {

View File

@ -1,7 +1,8 @@
import { ILayer } from '@antv/l7'; import { ILayer } from '@antv/l7';
import { createContext, useContext } from 'react'; import { createContext, useContext } from 'react';
export const LayerContext = createContext({}); // tslint:disable-next-line: no-object-literal-type-assertion
export const LayerContext = createContext<ILayer | undefined>({} as ILayer);
export function useLayerValue(): ILayer { export function useLayerValue(): ILayer {
return (useContext(LayerContext) as unknown) as ILayer; return (useContext(LayerContext) as unknown) as ILayer;
} }