Skip to content

Commit

Permalink
Merge e14aea1 into c01de03
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Jun 17, 2022
2 parents c01de03 + e14aea1 commit 1a3aa31
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 47 deletions.
@@ -1,26 +1,20 @@
import { DEFAULT_HIGHLIGHT_COLOR } from '../common/constants';
import { BubbleLayerActiveOptions, BubbleLayerOptions } from './types';

/**
* 空值 source
*/
export const EMPTY_SOURCE = { data: [], parser: { type: 'json', x: 'x', y: 'y' } };

const defaultHighlightColor = '#2f54eb';

/**
* 默认的全部交互状态配置
*/
export const DEFAULT_STATE: { active: Required<BubbleLayerActiveOptions>; select: Required<BubbleLayerActiveOptions> } =
{
active: {
fillColor: false,
strokeColor: defaultHighlightColor,
strokeColor: DEFAULT_HIGHLIGHT_COLOR,
lineWidth: 1.5,
lineOpacity: 1,
},
select: {
fillColor: false,
strokeColor: defaultHighlightColor,
strokeColor: DEFAULT_HIGHLIGHT_COLOR,
lineWidth: 1.5,
lineOpacity: 1,
},
Expand Down
Expand Up @@ -23,10 +23,6 @@ export class BubbleLayer extends CompositeLayer<BubbleLayerOptions> {
protected get layer() {
return this.fillLayer;
}
/**
* 图层间共享 source 实例
*/
public source!: ISource;
/**
* 填充图层
*/
Expand Down
@@ -1,12 +1,11 @@
import { DEFAULT_HIGHLIGHT_COLOR } from '../common/constants';
import { ChoroplethLayerActiveOptions, ChoroplethLayerOptions } from './types';

/**
* 空值 source
*/
export const EMPTY_SOURCE = { data: { type: 'FeatureCollection', features: [] }, parser: { type: 'geojson' } };

const defaultHighlightColor = '#2f54eb';

/**
* 默认的全部交互状态配置
*/
Expand All @@ -16,13 +15,13 @@ export const DEFAULT_STATE: {
} = {
active: {
fillColor: false,
strokeColor: defaultHighlightColor,
strokeColor: DEFAULT_HIGHLIGHT_COLOR,
lineWidth: 1,
lineOpacity: 1,
},
select: {
fillColor: false,
strokeColor: defaultHighlightColor,
strokeColor: DEFAULT_HIGHLIGHT_COLOR,
lineWidth: 1,
lineOpacity: 1,
},
Expand Down
@@ -1,8 +1,6 @@
import { IconLayerOptions, IconLayerActiveOptions } from './types';
import { DEFAULT_HIGHLIGHT_COLOR, EMPTY_JSON_SOURCE } from '../common/constants';

export const EMPTY_SOURCE = { data: [], parser: { type: 'json', x: 'x', y: 'y' } };

/**
* 默认的全部交互状态配置
*/
Expand All @@ -26,7 +24,7 @@ export const DEFAULT_STATE: { active: Required<IconLayerActiveOptions>; select:
*/
export const DEFAULT_OPTIONS: Partial<IconLayerOptions> = {
visible: true,
source: EMPTY_SOURCE,
source: EMPTY_JSON_SOURCE,
radius: 12,
icon: {
value: '1',
Expand Down
@@ -1,12 +1,14 @@
import { CompositeLayer, CompositeEventEnum } from '../../core/composite-layer';
import { CompositeLayer } from '../../core/composite-layer';
import { TextLayer } from '../../core-layers/text-layer';
import { PointLayer } from '../../core-layers/point-layer';
import { LabelService } from '../common/service/label';
import { IconFontLayerOptions } from './types';
import { getDefaultState } from './adaptor';
import { DEFAULT_OPTIONS, DEFAULT_STATE, EMPTY_SOURCE } from './constants';
import { DEFAULT_OPTIONS, DEFAULT_STATE } from './constants';
import { ICoreLayer, ISource, MouseEvent } from '../../types';
import { IconLayer } from './icon';
import { CompositeLayerEvent } from '../../core/constants';

export class IconFontLayer extends IconLayer<IconFontLayerOptions> {
/**
* 默认配置项
Expand All @@ -20,15 +22,14 @@ export class IconFontLayer extends IconLayer<IconFontLayerOptions> {
if (this.scene) {
this.loadIconAtlas();
} else {
this.once(CompositeEventEnum.ONADD, () => {
this.once(CompositeLayerEvent.ADD, () => {
this.loadIconAtlas();
});
}
}

/**
* load 图片资源
* @returns
*/
protected loadIconAtlas() {
const { fontFamily, fontPath, iconFonts } = this.options.iconAtlas;
Expand Down
@@ -1,12 +1,14 @@
import { CompositeLayer, CompositeEventEnum } from '../../core/composite-layer';
import { CompositeLayer } from '../../core/composite-layer';
import { TextLayer } from '../../core-layers/text-layer';
import { PointLayer } from '../../core-layers/point-layer';
import { LabelService } from '../common/service/label';
import { IconImageLayerOptions } from './types';
import { getDefaultState } from './adaptor';
import { DEFAULT_OPTIONS, DEFAULT_STATE, EMPTY_SOURCE } from './constants';
import { DEFAULT_OPTIONS, DEFAULT_STATE } from './constants';
import { ICoreLayer, ISource, MouseEvent } from '../../types';
import { IconLayer } from './icon';
import { CompositeLayerEvent } from '../../core/constants';

export class IconImageLayer extends IconLayer<IconImageLayerOptions> {
/**
* 默认配置项
Expand All @@ -20,15 +22,14 @@ export class IconImageLayer extends IconLayer<IconImageLayerOptions> {
if (this.scene) {
this.loadIconAtlas();
} else {
this.once(CompositeEventEnum.ONADD, () => {
this.once(CompositeLayerEvent.ADD, () => {
this.loadIconAtlas();
});
}
}

/**
* load 图片资源
* @returns
*/
protected loadIconAtlas() {
const iconAtlas = this.options.iconAtlas;
Expand Down
@@ -1,12 +1,12 @@
import { CompositeLayer, CompositeEventEnum } from '../../core/composite-layer';
import { BubbleLayer } from '../bubble-layer';
import { CompositeLayer } from '../../core/composite-layer';
import { TextLayer } from '../../core-layers/text-layer';
import { PointLayer } from '../../core-layers/point-layer';
import { LabelService } from '../common/service/label';
import { IconLayerOptions } from './types';
import { getDefaultState } from './adaptor';
import { DEFAULT_OPTIONS, DEFAULT_STATE, EMPTY_SOURCE } from './constants';
import { DEFAULT_OPTIONS, DEFAULT_STATE } from './constants';
import { ICoreLayer, ISource, MouseEvent } from '../../types';

export abstract class IconLayer<T extends IconLayerOptions> extends CompositeLayer<T> {
/**
* 默认配置项
Expand All @@ -29,10 +29,6 @@ export abstract class IconLayer<T extends IconLayerOptions> extends CompositeLay
protected get layer() {
return this.iconLayer;
}
/**
* 图层间共享 source 实例
*/
public source!: ISource;
/**
* 填充面图层
*/
Expand Down
Expand Up @@ -2,13 +2,15 @@ import { ISourceCFG, ISource } from '../../types';
import { TextLayerStyleOptions, TextLayerOptions } from '../../core-layers/text-layer/types';
import { PointLayerOptions } from '../../core-layers/point-layer/types';
import { CompositeLayerOptions } from '../../core/composite-layer';

/**
* 数据配置
*/
export interface IconLayerSourceOptions extends Pick<ISourceCFG, 'parser' | 'transforms'> {
/** 图标数据 */
data: any;
}

export type IconLayerActiveOptions = {
enable?: boolean;
/**图标大小 */
Expand Down
Expand Up @@ -16,7 +16,6 @@ export class PointLayer extends CoreLayer<PointLayerOptions> {
protected createLayer(): ILayer {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { source, shape, size, ...config } = this.options;

const layer = new L7PointLayer(config);

return layer;
Expand Down
12 changes: 5 additions & 7 deletions packages/composite-layers/src/core/composite-layer.ts
Expand Up @@ -2,7 +2,7 @@ import { deepMix, uniqueId } from '@antv/util';
import EventEmitter from '@antv/event-emitter';
import Source from '@antv/l7-source';
import { Scene, SourceOptions, ICompositeLayer, CompositeLayerType, LayerBlend, ICoreLayer, ISource } from '../types';
import { LayerEventList } from './constants';
import { CompositeLayerEvent, LayerEventList } from './constants';
import { LayerGroup } from './layer-group';

/**
Expand Down Expand Up @@ -33,9 +33,7 @@ export interface CompositeLayerOptions {
/** 数据源 */
source: any;
}
export enum CompositeEventEnum {
ONADD = 'onadd',
}

export abstract class CompositeLayer<O extends CompositeLayerOptions> extends EventEmitter implements ICompositeLayer {
/**
* 复合图层类型
Expand Down Expand Up @@ -81,7 +79,6 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
* 图层是否具有交互效果,用于 tooltip
*/
public abstract readonly interaction: boolean;

/**
* 图层间共享 source 实例
*/
Expand Down Expand Up @@ -112,7 +109,7 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
}

/**
* 创建 source 工具方法
* 创建图层间共享 source 方法
*/
protected createSource() {
const sourceOptions = this.options.source;
Expand Down Expand Up @@ -157,7 +154,7 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
public addTo(scene: Scene) {
this.scene = scene;
this.subLayers.addTo(scene);
this.emit(CompositeEventEnum.ONADD);
this.emit(CompositeLayerEvent.ADD);
}

/**
Expand All @@ -166,6 +163,7 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
public remove() {
if (!this.scene) return;
this.subLayers.remove();
this.emit(CompositeLayerEvent.REMOVE);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/composite-layers/src/core/constants.ts
Expand Up @@ -4,7 +4,6 @@ export const LayerEventList: string[] = [
'add',
'remove',
'dataUpdate',

// 鼠标事件
// 单击事件
'click',
Expand All @@ -23,3 +22,8 @@ export const LayerEventList: string[] = [
'uncontextmenu',
'unpick',
];

export enum CompositeLayerEvent {
ADD = 'add',
REMOVE = 'remove',
}
4 changes: 2 additions & 2 deletions packages/composite-layers/src/index.ts
Expand Up @@ -31,6 +31,6 @@ export * from './composite-layers/bubble-layer/types';
// 区域图层及类型定义 | author by [yunji]](https://github.com/lvisei)
export { ChoroplethLayer } from './composite-layers/choropleth-layer';
export * from './composite-layers/choropleth-layer/types';
// 标注图层
export * from './composite-layers/icon-layer';
// 标注图层及类型定义 | author by [lzxue]](https://github.com/lzxue)
export { IconFontLayer, IconImageLayer } from './composite-layers/icon-layer';
export * from './composite-layers/icon-layer/types';
2 changes: 1 addition & 1 deletion packages/composite-layers/src/types/category.ts
Expand Up @@ -5,5 +5,5 @@ export enum CompositeLayerType {
BubbleLayer = 'bubbleLayer',
ChoroplethLayer = 'choroplethLayer',
IconImageLayer = 'iconImageLayer',
IconFontLayer = 'iconfontLayer',
IconFontLayer = 'iconFontLayer',
}

0 comments on commit 1a3aa31

Please sign in to comment.