Skip to content

Commit

Permalink
feat: layer 支持数据过滤属性
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Oct 7, 2023
1 parent 760d8a1 commit b3d516e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export interface BubbleLayerOptions extends CompositeLayerOptions {
* 文本标注
*/
label?: LabelOptions;
/**
* 数据过滤
*/
filter?: PointLayerOptions['filter'];
/**
* 交互反馈
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { clone, isEqual, isUndefined, omit } from '@antv/util';
import { CompositeLayer } from '../../core/composite-layer';
import { LineLayer } from '../../core-layers/line-layer';
import { PolygonLayer } from '../../core-layers/polygon-layer';
import { TextLayer } from '../../core-layers/text-layer';
import { getDefaultState } from './adaptor';
import { ChoroplethLayerOptions, ChoroplethLayerSourceOptions } from './types';
import { CompositeLayer } from '../../core/composite-layer';
import { ICoreLayer, ISource, MouseEvent } from '../../types';
import { EMPTY_GEOJSON_SOURCE } from '../common/constants';
import { DEFAULT_OPTIONS, DEFAULT_STATE } from './constants';
import { isGestureMultiSelect } from '../common/multi-select';
import { getDefaultState } from './adaptor';
import { DEFAULT_OPTIONS, DEFAULT_STATE } from './constants';
import { getLabelLayerOptions, isLabelPosition, parserLabeSourceData } from './helper';
import { ChoroplethLayerOptions, ChoroplethLayerSourceOptions } from './types';

export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
/**
Expand Down Expand Up @@ -188,6 +188,7 @@ export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
lineOpacity,
lineDash,
lineType,
filter,
} = this.options;

const strokeStyle = {
Expand All @@ -204,6 +205,7 @@ export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
size: lineWidth,
color: strokeColor,
style: strokeStyle,
filter,
};

return options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IParserCfg } from '@antv/l7';
import { PolygonLayerOptions } from '../../core-layers/polygon-layer/types';
import { CompositeLayerOptions } from '../../core/composite-layer';
import { ISourceCFG, ISource } from '../../types';
import { ISource, ISourceCFG } from '../../types';
import { LabelOptions } from '../common/types';

/**
Expand Down Expand Up @@ -81,6 +81,10 @@ export interface ChoroplethLayerOptions extends CompositeLayerOptions {
*/
position?: LabelPosition;
};
/**
* 数据过滤
*/
filter?: PolygonLayerOptions['filter'];
/**
* 交互反馈
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { isUndefined } from '@antv/util';
import { CompositeLayerOptions } from '../../core/composite-layer';
import { FilterAttr } from '../../types';
import { LabelOptions } from './types';

interface WrapLayerOptions extends CompositeLayerOptions {
label?: LabelOptions;
/**
* 数据过滤
*/
filter?: FilterAttr;
}

/**
* 获取标注图层配置项
*/
export const getLabelLayerOptions = <T extends WrapLayerOptions>(options: T) => {
const { visible, minZoom, maxZoom, zIndex = 0, label } = options;
const { visible, minZoom, maxZoom, zIndex = 0, label, filter } = options;
const labelVisible = visible && Boolean(label) && (isUndefined(label?.visible) || label?.visible);
const labelLayerOptions = {
zIndex: zIndex + 0.1,
minZoom,
maxZoom,
filter,
...label,
visible: labelVisible,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ISourceCFG, ISource } from '../../types';
import { PointLayerStyleOptions } from '../../core-layers/point-layer/types';
import { PointLayerOptions } from '../../core-layers/point-layer/types';
import { PointLayerOptions, PointLayerStyleOptions } from '../../core-layers/point-layer/types';
import { TextLayerStyleOptions } from '../../core-layers/text-layer/types';
import { CompositeLayerOptions } from '../../core/composite-layer';
import { ISource, ISourceCFG } from '../../types';
import { LabelOptions } from '../common/types';

/**
Expand Down Expand Up @@ -60,6 +59,10 @@ export interface IconLayerOptions extends CompositeLayerOptions {
* 文本标注
*/
label?: LabelOptions;
/**
* 数据过滤
*/
filter?: PointLayerOptions['filter'];
/**
* 交互反馈
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/composite-layers/src/core/composite-layer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isUndefined, uniqueId } from '@antv/util';
import EventEmitter from '@antv/event-emitter';
import { ILegend, Source } from '@antv/l7';
import { isUndefined, uniqueId } from '@antv/util';
import { CompositeLayerType, ICompositeLayer, ICoreLayer, ISource, LayerBlend, Scene, SourceOptions } from '../types';
import { deepMergeLayerOptions, isSourceChanged } from '../utils';
import { Scene, SourceOptions, ICompositeLayer, CompositeLayerType, LayerBlend, ICoreLayer, ISource } from '../types';
import { CompositeLayerEvent, LayerGroupEvent, OriginLayerEventList } from './constants';
import { LayerGroup } from './layer-group';

Expand Down
7 changes: 6 additions & 1 deletion packages/composite-layers/src/core/core-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MappingAttribute } from '../adaptor/attribute';
import {
AnimateAttr,
ColorAttr,
FilterAttr,
ICoreLayer,
ILayer,
ILegend,
Expand Down Expand Up @@ -54,6 +55,10 @@ export interface CoreLayerOptions extends Partial<LayerBaseConfig> {
* 纹理贴图
*/
texture?: TextureAttr;
/**
* 数据过滤
*/
filter?: FilterAttr;
/**
* 图层样式
*/
Expand Down Expand Up @@ -183,7 +188,7 @@ export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter
* 映射图层属性
*/
protected adaptorLayerAttr(isDiff = true): void {
const attrKeys = ['shape', 'color', 'size', 'scale', 'texture', 'style', 'animate', 'state'];
const attrKeys = ['shape', 'color', 'size', 'scale', 'texture', 'filter', 'style', 'animate', 'state'];
const currentAttrs = this.adaptorAttrOptions(this.options);
const lastAttrs = this.adaptorAttrOptions(this.lastOptions);

Expand Down

0 comments on commit b3d516e

Please sign in to comment.