From f81367dc3b268457a3540b3e5e9f7d80f487fe80 Mon Sep 17 00:00:00 2001 From: yanxiong Date: Thu, 13 Oct 2022 19:23:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8E=BB=E9=99=A4=20Control=20?= =?UTF-8?q?=E4=B8=AD=20abstract=20=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/control/baseControl/buttonControl.ts | 2 +- .../component/src/control/baseControl/control.ts | 13 +++++++------ .../src/control/baseControl/popperControl.ts | 2 +- .../src/control/baseControl/selectControl.ts | 6 ++++-- packages/component/src/control/zoom.ts | 7 ++++--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/component/src/control/baseControl/buttonControl.ts b/packages/component/src/control/baseControl/buttonControl.ts index 3a2e1d8add..80d9a9fd26 100644 --- a/packages/component/src/control/baseControl/buttonControl.ts +++ b/packages/component/src/control/baseControl/buttonControl.ts @@ -11,7 +11,7 @@ export interface IButtonControlOption extends IControlOption { vertical?: boolean; } -export default abstract class ButtonControl< +export default class ButtonControl< O extends IButtonControlOption = IButtonControlOption > extends Control { /** diff --git a/packages/component/src/control/baseControl/control.ts b/packages/component/src/control/baseControl/control.ts index cbbb565cb5..ed1c2f6e29 100644 --- a/packages/component/src/control/baseControl/control.ts +++ b/packages/component/src/control/baseControl/control.ts @@ -1,8 +1,6 @@ -import type { - IControlOption -} from '@antv/l7-core'; import { IControl, + IControlOption, IControlService, IGlobalConfigService, ILayerService, @@ -22,7 +20,7 @@ export { PositionType } from '@antv/l7-core'; export { Control, IControlOption }; -export default abstract class Control +export default class Control extends EventEmitter implements IControl { /** @@ -142,12 +140,15 @@ export default abstract class Control /** * Control 被添加的时候被调用,返回 Control 对应的 DOM 容器 */ - public abstract onAdd(): HTMLElement; + public onAdd(): HTMLElement { + return DOM.create('div'); + } /** * Control 被移除时调用 */ - public abstract onRemove(): void; + // tslint:disable-next-line:no-empty + public onRemove() {} /** * 显示控件时触发 diff --git a/packages/component/src/control/baseControl/popperControl.ts b/packages/component/src/control/baseControl/popperControl.ts index d7148e6cb1..e492377c50 100644 --- a/packages/component/src/control/baseControl/popperControl.ts +++ b/packages/component/src/control/baseControl/popperControl.ts @@ -25,7 +25,7 @@ const PopperPlacementMap: Record = { rightbottom: 'top-end', }; -export default abstract class PopperControl< +export default class PopperControl< O extends IPopperControlOption = IPopperControlOption > extends ButtonControl { /** diff --git a/packages/component/src/control/baseControl/selectControl.ts b/packages/component/src/control/baseControl/selectControl.ts index a429d07613..d6503fa9f8 100644 --- a/packages/component/src/control/baseControl/selectControl.ts +++ b/packages/component/src/control/baseControl/selectControl.ts @@ -30,7 +30,7 @@ enum SelectControlConstant { OptionIndexAttrKey = 'data-option-index', } -export default abstract class SelectControl< +export default class SelectControl< O extends ISelectControlOption = ISelectControlOption > extends PopperControl { /** @@ -103,7 +103,9 @@ export default abstract class SelectControl< * 是否为多选 * @protected */ - protected abstract getIsMultiple(): boolean; + protected getIsMultiple() { + return false; + } protected getPopperContent(options: ControlOptionItem[]): HTMLElement { const isImageOptions = this.isImageOptions(); diff --git a/packages/component/src/control/zoom.ts b/packages/component/src/control/zoom.ts index f78f504690..499e664e2b 100644 --- a/packages/component/src/control/zoom.ts +++ b/packages/component/src/control/zoom.ts @@ -1,12 +1,13 @@ import { PositionType } from '@antv/l7-core'; import { DOM } from '@antv/l7-utils'; +import { ELType } from '@antv/l7-utils/src/dom'; import { createL7Icon } from '../utils/icon'; import { Control, IControlOption } from './baseControl'; export interface IZoomControlOption extends IControlOption { - zoomInText: Element | string; + zoomInText: ELType | string; zoomInTitle: string; - zoomOutText: Element | string; + zoomOutText: ELType | string; zoomOutTitle: string; } @@ -105,7 +106,7 @@ export default class Zoom extends Control { } private createButton( - html: Element | string, + html: ELType | string, tile: string, className: string, container: HTMLElement,