Skip to content

Commit

Permalink
feat: 复合图层新增获取带有交互图层方法
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Nov 10, 2022
1 parent f1518f4 commit cc050e1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
Expand Up @@ -66,10 +66,6 @@ export class BubbleLayer extends CompositeLayer<BubbleLayerOptions> {
* 图层交互状态配置
*/
private layerState = DEFAULT_STATE;
/**
* 图层是否具有交互属性
*/
public interaction = true;

constructor(options: BubbleLayerOptions) {
super(options);
Expand All @@ -96,6 +92,7 @@ export class BubbleLayer extends CompositeLayer<BubbleLayerOptions> {
id: 'fillLayer',
shape: 'circle',
source,
interaction: true,
});

// 高亮描边图层
Expand Down
Expand Up @@ -73,10 +73,6 @@ export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
* 图层交互状态配置
*/
private layerState = DEFAULT_STATE;
/**
* 图层是否具有交互属性
*/
public interaction = true;

constructor(options: ChoroplethLayerOptions) {
super(options);
Expand All @@ -103,6 +99,7 @@ export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
id: 'fillLayer',
shape: 'fill',
source,
interaction: true,
});
const fillBottomColor = this.options.fillBottomColor;
fillBottomColor && fillLayer.layer.setBottomColor(fillBottomColor);
Expand Down
Expand Up @@ -52,11 +52,6 @@ export abstract class IconLayer<T extends IconLayerOptions> extends CompositeLay
return this.subLayers.getLayer('selectIconLayer') as ICoreLayer;
}

/**
* 图层是否具有交互属性
*/
public interaction = true;

constructor(options: T) {
super(options);
this.initSubLayersEvent();
Expand Down Expand Up @@ -187,6 +182,7 @@ export abstract class IconLayer<T extends IconLayerOptions> extends CompositeLay
...this.getIconLayerOptions(),
id: 'iconLayer',
source,
interaction: true,
});
// 选中效果
const selectLayer = new PointLayer({
Expand Down
15 changes: 10 additions & 5 deletions packages/composite-layers/src/core/composite-layer.ts
Expand Up @@ -89,15 +89,10 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
* 主子图层实例
*/
protected abstract readonly layer: ICoreLayer;
/**
* 图层是否具有交互效果,用于 tooltip
*/
public abstract readonly interaction: boolean;
/**
* 图层间共享 source 实例
*/
public source!: ISource;

/**
* 子图层组
*/
Expand Down Expand Up @@ -325,6 +320,16 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
return [];
}

/**
* 获取带有交互的子图层
* 一般用于是否启用 tooltip,图层事件绑定
*/
public getInteractionSubLayers(): ICoreLayer[] {
const layers = this.subLayers.getLayers().filter((layer) => layer.interaction === true);

return layers;
}

/**
* 摧毁
*/
Expand Down
11 changes: 10 additions & 1 deletion packages/composite-layers/src/core/core-layer.ts
Expand Up @@ -66,6 +66,10 @@ export interface CoreLayerOptions extends Partial<LayerBaseConfig> {
* 交互反馈
*/
state?: StateAttribute;
/**
* 图层是否具有交互效果,用于复合图层 tooltip 是否启用
*/
interaction?: boolean;
}

export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter implements ICoreLayer {
Expand All @@ -89,6 +93,10 @@ export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter
* 图层类型
*/
public abstract readonly type: string;
/**
* 图层是否具有交互效果,用于复合图层 tooltip 是否启用
*/
public interaction: boolean;
/**
* 图层 schema 配置
*/
Expand Down Expand Up @@ -120,9 +128,10 @@ export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter

constructor(options: O) {
super();
const { id, name, source } = options;
const { id, name, source, interaction = false } = options;
this.id = id ? id : uniqueId('core-layer');
this.name = name ? name : this.id;
this.interaction = interaction;
this.options = deepMergeLayerOptions<O>(this.getDefaultOptions() as O, options);
this.lastOptions = this.options;
this.layer = this.createLayer();
Expand Down
3 changes: 3 additions & 0 deletions packages/composite-layers/src/types/interface.ts
Expand Up @@ -33,6 +33,7 @@ export interface ICoreLayer {
name: string;
id: string;
type: string;
interaction: boolean;
layer: ILayer;
inited: boolean;
source: ISource;
Expand Down Expand Up @@ -106,6 +107,8 @@ export interface ICompositeLayer {
getLegendItems(type: string): Record<string, any>[];
getColorLegendItems(): Record<string, any>[];

getInteractionSubLayers(): ICoreLayer[];

destroy(): void;

on(name: string, callback: (...args: any[]) => void): this;
Expand Down

0 comments on commit cc050e1

Please sign in to comment.