10.0.0-rc7.3 • Published 1 year ago

@bixi/label-angular v10.0.0-rc7.3

Weekly downloads
618
License
-
Repository
-
Last release
1 year ago

1. 安装使用

安装依赖

yarn add @bixi/label-angular

修改 angular.json

{
  "architect": {
    "build": {
      "options": {
        "assets": [
          {
            "glob": "**/*",
            "input": "node_modules/@bixi/label-angular/engine",
            "output": "/bixi-label-engine"
          }
        ]
      }
    }    
  }
}

模块注册

import { BixiLabelModule } from '@bixi/label-angular';

@NgModule({
  imports: [
    BixiLabelModule,
  ]
})
export class SharedModule { }

2. 设计理念

Label Engine

标注引擎(通过 iframe 引入), 只负责单纯做两件事:

  1. 标注图层的渲染
  2. 标注事件的监听

LabelTextHub 和 LabelTableHub

在使用标注器组件时候你需要先实例化一个标注控制器,然后将其传入标注组件,之后标注的所有事件都将会被它所接管,以文本标注为例

import { LabelTextHub } from '@bixi/label-angular';

@Component({
  template: `
  <bixi-label-text
    engine="./bixi-label-engine/index.html"
    [hub]="hub">
  </bixi-label-text>`
})
export class LabelHubDemoComponent{
  hub = new LabelTextHub({
    dev: true,
  });
}

对于业务组件而言, LabelTextHub 就像是一个邮局,它可以告诉你有哪些事件发生,也允许你主动往它上面投递事件等待引擎处理,比如

export class LabelHubDemoComponent{
  hub = new LabelHub({
    dev: true,
  });

  ngOnInit() {
    this.hub.pagination$
      .subscribe(({ pageNumber }) => {
        console.warn('内部更改了页码', pageNumber);
      });
  }

  pageChange() {
    // 业务组件主动更改页码
    this.hub.setPageNumber(2);
  }
}

LabelTextHub 对修改是封闭的,但是对扩展是完全开放的,我们将核心数据都实现了成员保护,只有当你需要完全定制 Hub 的时候,你可以继承它然后扩展它,就像下面这样可以实现 Hook 的功能

import { LabelTextHub } from '@bixi/label-angular';

export class MyHub extends LabelTextHub {
  constructor(options) {
    super(options);
  }

  setZoom(zoom) {
    console.warn('set zoom1', zoom);
    this._api.setZoom(zoom);
    console.warn('set zoom2', zoom);
  }
}

但如果像上面这样仅仅是打印日志的话,那么你可以不必这么舍近求远,我们提供了开发模式,丰富的日志可以帮助你快速排查问题,而它仅需要一行配置

hub = new LabelTextHub({
  dev: true
});

3. 使用细节

3.0 文本和表格通用 API

首先我们需要知道,不管是 LabelTextHub 还是 LabelTableHub,实际上都是继承自 LabelHub,以下是通用的 API

LabelHub

构造参数

名称类型描述
devboolean开启开发模式,将会打印所有 hub 的核心方法执行过程,以及执行时间
logUnhandledEventsboolean打印未处理事件
logAllEventsboolean打印所有日志
logIgnoreEventsstring[]忽略的事件

成员属性

名称类型描述
ready$BehaviorSubject<boolean>在标注引擎准备好标注的准备工作后触发
searchResult$BehaviorSubject<ISearchResult>搜索结果
pagination$BehaviorSubject<IPagination>页码
pageNumber$BehaviorSubject<number>当前页码
pageCount$Subject<number>总页码
zoom$BehaviorSubject<number>缩放比
loadedboolean引擎加载完成
readyboolean引擎准备完备
api引擎 API(不建议直接操作)

成员方法

名称类型描述
setPagination(pagination: IPagination)=> void修改页码
setZoom(zoom: number) => void修改缩放比
search(params: ISearchParams) => void搜索
getViewport() => IViewPort[]获取页面的显示相关信息
destroy() => void销毁控制器

3.1 文本标注

示例代码

LabelTextHub

成员方法

名称类型描述
init(options: IInitOptions) => void初始化标注器
patch(options: Partial<IInitOptions>) => void更新标注器
setLabels(labels: ILabel[]) => void设置标注列表
getSelectedLabels() => []ILabel获取选中的标注列表
getLabels() => []ILabel获取标注列表
search(params: ISearchParams) => void搜索
scrollToLabelByUuid(params: IScrollToLabelLabelByUuidParams) => void通过uuid滚动到某个标注
scrollToLabelByIndex(params: IScrollToLabelByIndexParams) => void通过索引跳转到某个标注
scrollToTableCell(params: IScrollToTableCellsParams) => void通过坐标跳转到某个单元格
restore() => void丢掉临时标注重新渲染

bixi-label-text

成员说明类型默认值
[engine]标注引擎地址string./bixi-label/index.html
[hub]标注器控制器LabelHub-
[labelTooltipContent]Tooltip 内容TemplateRef-
[labelTooltipDisabled]是否禁用 Tooltipbooleanfalse
[labelModalTitle]标注框标题string-
[labelModalContent]标注框内容TemplateRef-
[labelModalDisabled]是否禁用标注框booleanfalse
(createLabels)开始标注事件EventEmitter<ICreateLabelsEvent>-
(deleteLabels)删除标注事件EventEmitter<IDeleteLabelsEvent>-
(clickLabels)点击标注事件EventEmitter<IClickLabelsEvent>-
(pdfLoadFailed)PDF 加载失败EventEmitter-

3.2 表格标注

示例代码

LabelTableHub

成员方法

名称类型描述
init(options: IInitTableOptions) => void初始化标注器
patch(options: Partial<IInitTableOptions>) => void更新标注器
setTables(labels: ITables) => void设置表格标注列表
getTables() => ITables获取表格标注列表
getDirtyTables() => ITables获取表格标注数据(差量)
scrollToTableCell(params: IScrollToTableCellsParams) => void通过坐标跳转到某个单元格
restore() => void丢掉临时标注重新渲染

bixi-label-text

成员说明类型默认值
[engine]标注引擎地址string./bixi-label/index.html
[hub]标注器控制器LabelHub-
(pdfLoadFailed)PDF 加载失败EventEmitter-
(mergeTables)合并跨页表格EventEmitter-
(separateTable)拆分跨页表格EventEmitter-

Type

interface IInitBaseOptions {
  id: string;
  pdfUrl: string;
  pdfInfoUrl: string;
  pdfCharsUrl: string;
  engineMode: EngineMode;
  pdfSize?: number;
}

export interface ITextInitOptions extends IInitBaseOptions {
  operateMode: TextOperateMode;
  selectedLabeStyle?: Partial<CSSStyleDeclaration>;
  labelStyle?: Partial<CSSStyleDeclaration>;
}

export interface ITableInitOptions extends IInitBaseOptions {
  operateMode: TableOperateMode;
  mergeable?: boolean;
  splitable?: boolean;
}

更多详细类型定义

10.0.0-rc9.14.0

1 year ago

10.0.0-rc9.13.0

2 years ago

10.0.0-rc9.5.0

2 years ago

10.0.0-rc9.6.0

2 years ago

10.0.0-rc9.11.0

2 years ago

10.0.0-rc9.7.0

2 years ago

10.0.0-rc9.4.0

2 years ago

10.0.0-rc8.30

2 years ago

10.0.0-rc8.31

2 years ago

10.0.0-rc8.32

2 years ago

10.0.0-rc8.33

2 years ago

10.0.0-rc8.29

2 years ago

10.0.0-rc8.27

2 years ago

10.0.0-rc8.28

2 years ago

10.0.0-rc9.3.0

2 years ago

10.0.0-rc8.20

2 years ago

10.0.0-rc8.25

2 years ago

10.0.0-rc8.26

2 years ago

10.0.0-rc8.21

2 years ago

10.0.0-rc8.22

2 years ago

10.0.0-rc8.23

2 years ago

10.0.0-rc8.16

3 years ago

10.0.0-rc8.14

3 years ago

10.0.0-rc8.15

3 years ago

10.0.0-rc8.10

3 years ago

10.0.0-rc8.11

3 years ago

10.0.0-rc8.12

3 years ago

10.0.0-rc8.13

3 years ago

10.0.0-rc8.8

3 years ago

10.0.0-rc8.7

3 years ago

10.0.0-rc8.6

3 years ago

10.0.0-rc8.9

3 years ago

10.0.0-rc8.5

3 years ago

10.0.0-rc8.4

3 years ago

10.0.0-rc8.3

3 years ago

10.0.0-rc8.0

3 years ago

10.0.0-rc8.2

3 years ago

10.0.0-rc8.1

3 years ago

10.0.0-rc7.14

3 years ago

10.0.0-rc7.15

3 years ago

10.0.0-rc7.13

3 years ago

10.0.0-rc7.12

3 years ago

10.0.0-rc7.11

3 years ago

10.0.0-rc7.10

3 years ago

10.0.0-rc7.6.1

3 years ago

10.0.0-rc7.9

3 years ago

10.0.0-rc7.8

3 years ago

10.0.0-rc7.7

3 years ago

10.0.0-rc7.6

3 years ago

10.0.0-rc7.5

3 years ago

10.0.0-rc7.4

3 years ago

10.0.0-rc7.3

3 years ago

10.0.0-rc7.2

3 years ago

10.0.0-test7

3 years ago

10.0.0-test7.1

3 years ago

10.0.0-rc7

3 years ago

10.0.0-rc6.31

3 years ago

10.0.0-rc6.30

3 years ago

10.0.0-rc6.23

3 years ago

10.0.0-rc6.17

3 years ago

10.0.0-rc6.16

3 years ago

10.0.0-rc6.19

3 years ago

10.0.0-rc6.18

3 years ago

10.0.0-rc6.13

3 years ago

10.0.0-rc6.15

3 years ago

10.0.0-rc6.14

3 years ago

10.0.0-rc6.20

3 years ago

10.0.0-rc6.22

3 years ago

10.0.0-rc6.21

3 years ago

10.0.0-rc6.12

3 years ago

10.0.0-rc5.28

3 years ago

10.0.0-rc5.29

3 years ago

10.0.0-rc5.26

3 years ago

10.0.0-rc5.27

3 years ago

10.0.0-rc5.24

3 years ago

10.0.0-rc5.25

3 years ago

10.0.0-rc5.22

3 years ago

10.0.0-rc5.23

3 years ago

10.0.0-rc5.21

3 years ago

10.0.0-rc5.19

3 years ago

10.0.0-rc6.6

3 years ago

10.0.0-rc5.17

3 years ago

10.0.0-rc6.5

3 years ago

10.0.0-rc5.18

3 years ago

10.0.0-rc6.4

3 years ago

10.0.0-rc5.15

3 years ago

10.0.0-rc6.3

3 years ago

10.0.0-rc5.16

3 years ago

10.0.0-rc5.14

3 years ago

10.0.0-rc6.2

3 years ago

10.0.0-rc6.1

3 years ago

10.0.0-rc6.0

3 years ago

10.0.0-rc5.13

3 years ago

10.0.0-rc5.11

3 years ago

10.0.0-rc5.12

3 years ago

10.0.0-rc5.10

3 years ago

10.0.0-rc5.9

3 years ago

10.0.0-rc5.8

3 years ago

10.0.0-rc5.7

3 years ago

10.0.0-rc5.6

3 years ago

10.0.0-rc5.3

3 years ago

10.0.0-rc5.5

3 years ago

10.0.0-rc5.2

3 years ago

10.0.0-rc5.1

3 years ago

10.0.0-rc5.0

3 years ago

10.0.0-rc4.5

3 years ago

10.0.0-rc4.4

3 years ago

10.0.0-rc4.3

3 years ago

10.0.0-rc4.2

3 years ago

10.0.0-rc4.1

3 years ago

10.0.0-rc4.0

3 years ago

10.0.0-rc3.6

3 years ago

10.0.0-rc3.5

3 years ago

10.0.0-rc3.4

3 years ago

10.0.0-rc3.3

3 years ago

10.0.0-rc3.2

3 years ago

10.0.0-rc3.1

3 years ago

10.0.0-rc3.0

3 years ago

10.0.0-rc1.2

3 years ago

10.0.0-rc1.0

3 years ago

10.0.0-rc2.0

3 years ago

10.0.0-beta8.4

3 years ago

10.0.0-beta8.5

3 years ago

10.0.0-beta8.2

3 years ago

10.0.0-beta8.3

3 years ago

10.0.0-beta8.1

3 years ago

10.0.0-beta8.0

3 years ago

10.0.0-beta7.2

3 years ago

10.0.0-beta7.1

3 years ago

10.0.0-beta7.0

3 years ago

10.0.0-beta6

3 years ago

10.0.0-beta6.1

3 years ago

10.0.0-beta5.19

3 years ago

10.0.0-beta5.17

3 years ago

10.0.0-beta5.18

3 years ago

10.0.0-beta5.16

3 years ago

10.0.0-beta5.15

3 years ago

10.0.0-beta5.13

3 years ago

10.0.0-beta5.14

3 years ago

10.0.0-beta5.12

3 years ago

10.0.0-beta5.11

3 years ago

10.0.0-beta5.10

3 years ago

10.0.0-beta5.9

3 years ago

10.0.0-beta5.8

3 years ago

10.0.0-beta5.7

3 years ago

10.0.0-beta5.6

3 years ago

10.0.0-beta5.5

3 years ago

10.0.0-beta5.4

3 years ago

10.0.0-beta5.2

3 years ago

10.0.0-beta5.3

3 years ago

10.0.0-beta5.1

3 years ago

10.0.0-beta5

3 years ago

10.0.0-alpha27

3 years ago

10.0.0-beta4.2

3 years ago

10.0.0-beta4.1

3 years ago

10.0.0-beta4

3 years ago

10.0.0-beta3

3 years ago

10.0.0-beta2

3 years ago

10.0.0-beta1

3 years ago

10.0.0-alpha26

3 years ago

10.0.0-alpha25

3 years ago

10.0.0-alpha24

3 years ago

10.0.0-alpha23

3 years ago

10.0.0-alpha22

3 years ago

10.0.0-alpha19

3 years ago

10.0.0-alpha21

3 years ago

10.0.0-alpha20

3 years ago

10.0.0-alpha18

3 years ago

10.0.0-alpha17

3 years ago

10.0.0-alpha16

3 years ago

10.0.0-alpha15

3 years ago

10.0.0-alpha14

3 years ago

10.0.0-alpha13

3 years ago

10.0.0-alpha12

3 years ago

10.0.0-alpha11

3 years ago

10.0.0-alpha6

3 years ago

10.0.0-alpha5

3 years ago

10.0.0-alpha10

3 years ago

10.0.0-alpha4

3 years ago

10.0.0-alpha9

3 years ago

10.0.0-alpha8

3 years ago

10.0.0-alpha7

3 years ago

10.0.0-alpha2

3 years ago

10.0.0-alpha3

3 years ago

10.0.0-alpha1

3 years ago