Skip to content

Commit

Permalink
feat: 新增复合图层获取图例方法 (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Oct 20, 2022
1 parent 3df35ef commit 93e21d0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/composite-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"@antv/util": "^2.0.14"
},
"devDependencies": {
"@antv/l7": "^2.9.14"
"@antv/l7": "^2.9.37"
},
"peerDependencies": {
"@antv/l7": "^2.9.14"
"@antv/l7": "^2.9.37"
},
"publishConfig": {
"access": "public",
Expand Down
9 changes: 8 additions & 1 deletion packages/composite-layers/src/core/composite-layer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { uniqueId } from '@antv/util';
import EventEmitter from '@antv/event-emitter';
import { Source } from '@antv/l7';
import { ILegend, Source } from '@antv/l7';
import { deepMergeLayerOptions, isSourceChanged } from '../utils';
import { Scene, SourceOptions, ICompositeLayer, CompositeLayerType, LayerBlend, ICoreLayer, ISource } from '../types';
import { CompositeLayerEvent, OriginLayerEventList } from './constants';
Expand Down Expand Up @@ -298,6 +298,13 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
this.layer.fitBounds(fitBoundsOptions);
}

/**
* 获取图例
*/
public getLegend(name: string): ILegend {
return this.layer.getLegend(name);
}

/**
* 获取图例数据
*/
Expand Down
8 changes: 8 additions & 0 deletions packages/composite-layers/src/core/core-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
StateAttribute,
TextureAttr,
ISource,
ILegend,
} from '../types';
import { CoreLayerEvent, OriginLayerEventList } from './constants';
import { MappingAttribute } from '../adaptor/attribute';
Expand Down Expand Up @@ -367,6 +368,13 @@ export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter
this.layer.fitBounds(fitBoundsOptions);
}

/**
* 获取图例
*/
public getLegend(name: string): ILegend {
return this.layer.getLegend(name);
}

/**
* 获取图例数据
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/composite-layers/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ITransform,
ILegendSegmentItem,
ILegendClassificaItem,
ILegend,
} from '@antv/l7';
import { BlendType } from '@antv/l7';

Expand All @@ -22,6 +23,7 @@ export type {
ITransform,
ILegendSegmentItem,
ILegendClassificaItem,
ILegend,
Scene,
};

Expand Down
4 changes: 3 additions & 1 deletion packages/composite-layers/src/types/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SourceOptions } from './attr';
import { ILayer, LayerBlend, Scene, ISource } from './common';
import { ILayer, LayerBlend, Scene, ISource, ILegend } from './common';

export interface ILayerGroup {
name: string;
Expand Down Expand Up @@ -59,6 +59,7 @@ export interface ICoreLayer {
boxSelect(bounds: [number, number, number, number], callback: (...args: any[]) => void): void;

fitBounds(fitBoundsOptions?: unknown): void;
getLegend(name: string): ILegend;
getLegendItems(type: string): Record<string, any>[];

destroy(): void;
Expand Down Expand Up @@ -97,6 +98,7 @@ export interface ICompositeLayer {
setBlend(blend: LayerBlend): void;

fitBounds(fitBoundsOptions?: unknown): void;
getLegend(name: string): ILegend;
getLegendItems(type: string): Record<string, any>[];
getColorLegendItems(): Record<string, any>[];

Expand Down
4 changes: 2 additions & 2 deletions packages/l7plot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"url": "https://github.com/antvis/L7Plot/issues"
},
"devDependencies": {
"@antv/l7": "^2.9.14",
"@antv/l7": "^2.9.37",
"@types/geojson": "^7946.0.8",
"@types/lodash-es": "^4.17.4",
"@types/topojson-client": "^3.1.0"
Expand All @@ -53,7 +53,7 @@
"topojson-client": "^3.1.0"
},
"peerDependencies": {
"@antv/l7": "^2.9.14"
"@antv/l7": "^2.9.37"
},
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ layer.off(eventName: string, callback: (...args) => void);

#### 生命周期事件

| 事件名 | 类型 | 描述 |
| ---------- | ------------ | ------------------------- |
| inited | 生命周期事件 | 图层初始化完成事件 |
| add | 生命周期事件 | 图层添加到场景 scene 事件 |
| remove | 生命周期事件 | 图层移除时事件 |
| dataUpdate | 生命周期事件 | 图层数据源更新事件 |
| 事件名 | 类型 | 描述 |
| ------------ | ------------ | ------------------------------ |
| inited | 生命周期事件 | 图层初始化完成事件 |
| add | 生命周期事件 | 图层添加到场景 scene 事件 |
| remove | 生命周期事件 | 图层移除时事件 |
| dataUpdate | 生命周期事件 | 图层数据源更新事件 |
| legend | 生命周期事件 | 数据映射更新,图例更新事件 |
| legend:color | 生命周期事件 | 数据映射更新,颜色图例更新事件 |
| legend:size | 生命周期事件 | 数据映射更新,大小图例更新事件 |

#### 点击事件

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ layer.isVisible() : boolean;
layer.fitBounds(fitBoundsOptions?: Bounds);
```

### getLegend

获取图例。

```js
layer.getLegend(name: string): ILegend;
```

### getLegendItems

获取图例数据。
Expand Down
15 changes: 9 additions & 6 deletions website/docs/common/composite-layers/core-common/event.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ layer.off(eventName: string, callback: (...args) => void);

#### 生命周期事件

| 事件名 | 类型 | 描述 |
| ---------- | ------------ | ------------------------- |
| inited | 生命周期事件 | 图层初始化完成事件 |
| add | 生命周期事件 | 图层添加到场景 scene 事件 |
| remove | 生命周期事件 | 图层移除时事件 |
| dataUpdate | 生命周期事件 | 图层数据源更新事件 |
| 事件名 | 类型 | 描述 |
| ------------ | ------------ | ------------------------------ |
| inited | 生命周期事件 | 图层初始化完成事件 |
| add | 生命周期事件 | 图层添加到场景 scene 事件 |
| remove | 生命周期事件 | 图层移除时事件 |
| dataUpdate | 生命周期事件 | 图层数据源更新事件 |
| legend | 生命周期事件 | 数据映射更新,图例更新事件 |
| legend:color | 生命周期事件 | 数据映射更新,颜色图例更新事件 |
| legend:size | 生命周期事件 | 数据映射更新,大小图例更新事件 |

#### 点击事件

Expand Down
8 changes: 8 additions & 0 deletions website/docs/common/composite-layers/core-common/method.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ layer.fitBounds(fitBoundsOptions?: Bounds);
layer.boxSelect(bounds: [number, number, number, number], callback: (...args: any[]) => void);
```

### getLegend

获取图例。

```js
layer.getLegend(name: string): ILegend;
```

### getLegendItems

获取图例数据。
Expand Down

0 comments on commit 93e21d0

Please sign in to comment.