kfb-view 2.2.4 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "2.2.4",
4
+ "version": "2.2.5",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -6,7 +6,7 @@ import {
6
6
  LINE_TYPES, MARKS,
7
7
  NO_NORMAL_REGION_TYPES,
8
8
  REGION_TYPES,
9
- STAR,
9
+ STAR, IMAGE,
10
10
  } from '../../const/mark';
11
11
  import {
12
12
  baseNumber, getAngle, getDistance, getPoint,
@@ -90,6 +90,9 @@ export class Area extends ViewerCommon {
90
90
  let selectLabel;
91
91
  let prevSelectLabel = undefined;
92
92
  this.labelList.forEach((item) => {
93
+ if (item.tool === IMAGE) {
94
+ return;
95
+ }
93
96
  if (item.select) {
94
97
  prevSelectLabel = item;
95
98
  }
@@ -1,12 +1,10 @@
1
1
  import {
2
- HAS_REGION_TYPES,
2
+ HAS_REGION_TYPES, IMAGE,
3
3
  MARKS, NO_NORMAL_REGION_TYPES, POINT_TYPES, POLYGON, REGION_TYPES,
4
4
  } from '../../const/mark';
5
5
  import {ViewerCommon} from '../common/common';
6
6
  import * as Tools from '../../tool';
7
7
  import {Combination} from '../../tool/Combination';
8
- import {EVENT_CANCEL_SELECT_LABEL} from '../../const/event';
9
- import * as EVENTS from '../../const/event';
10
8
 
11
9
  /**
12
10
  * 用来显示标注线的canvas
@@ -70,7 +68,12 @@ export class Shape extends ViewerCommon {
70
68
  // strokeStyle, lineWidth, fillStyle 相同认为是一个路径下的图形,一起绘制,优化性能
71
69
  const sameFixWidthLabel = {}; // star, flag, star, font lineWidth固定为2
72
70
  const sameNormalLabel = {};
71
+ const imageLabel = [];
73
72
  labelList.forEach((item) => {
73
+ if (item.tool === IMAGE) {
74
+ imageLabel.push(item);
75
+ return;
76
+ }
74
77
  const key = `${item.strokeStyle ?? ''}_${item.lineWidth ??
75
78
  ''}_${item.fillStyle ?? ''}`;
76
79
  const regionKey = `${item.strokeStyle ?? ''}_${item.lineWidth ?? ''}`;
@@ -111,6 +114,9 @@ export class Shape extends ViewerCommon {
111
114
  tool,
112
115
  })), this.viewport.getRotation());
113
116
  });
117
+ imageLabel.forEach((item) => {
118
+ this.drawLabel(item);
119
+ });
114
120
  }
115
121
 
116
122
  deepDrawLabel(sameFixWidthLabel, sameNormalLabel, count, bounds) {
package/src/const/mark.js CHANGED
@@ -8,6 +8,7 @@ export const FONT = 'Font';
8
8
  export const STAR = 'Star';
9
9
  export const FLAG = 'Flag';
10
10
  export const DOT = 'Dot';
11
+ export const IMAGE = 'Image';
11
12
 
12
13
  export const POINT_TYPES = [FONT, STAR, FLAG, DOT];
13
14
  export const REGION_TYPES = [RECTANGLE, ELLIPSE];
@@ -24,4 +25,5 @@ export const MARKS = [
24
25
  FONT,
25
26
  STAR,
26
27
  FLAG,
27
- DOT];
28
+ DOT,
29
+ IMAGE];
@@ -17,6 +17,7 @@ export class LabelModel {
17
17
  this.measure = data.measure; // 是否显示测量信息
18
18
  this.points = data.points; // 绘制点
19
19
  this.tool = data.tool; // 绘制工具
20
+ this.src = data.src; // 图片地址
20
21
  this.scale = data.scale; // 绘制倍率
21
22
  this.region = data.region; // 绘制区域
22
23
  this.move = data.move; // 是否可移动
@@ -27,5 +28,13 @@ export class LabelModel {
27
28
  this.show = data.show ?? true; // 是否显示
28
29
  this.__other__ = data.__other__ || {}; // 其他信息
29
30
  this.__data__ = data.__data__ ?? data; // 记录原始数据
31
+ if (this.src) {
32
+ this.img = new Image();
33
+ this.img.src = this.src;
34
+ this.imgLoadSuccess = false;
35
+ this.img.onload = () => {
36
+ this.imgLoadSuccess = true;
37
+ };
38
+ }
30
39
  }
31
40
  }
@@ -0,0 +1,41 @@
1
+ import {Brush} from './Brush';
2
+ import {pointsToRegion} from '../util/calculate';
3
+
4
+ /**
5
+ * 线段类
6
+ * @class
7
+ */
8
+ class Image extends Brush {
9
+ /**
10
+ * 初始化数据
11
+ */
12
+ constructor() {
13
+ super();
14
+ }
15
+
16
+ /**
17
+ * 画线
18
+ * @param {Object[]} points - 绘制的点
19
+ * @param {number} points[].x - 绘制的点x坐标
20
+ * @param {number} points[].y - 绘制的点y坐标
21
+ * @param {number=} scale
22
+ */
23
+ draw(points, scale = 1) {
24
+ const region = pointsToRegion(points);
25
+ const ctx = this.canvas.getContext('2d');
26
+ const drawImage = () => {
27
+ ctx.drawImage(this.options.img, region.x, region.y, region.width,
28
+ region.height);
29
+ this.options.img.removeEventListener('load', drawImage);
30
+ };
31
+ if (this.options.imgLoadSuccess) {
32
+ drawImage();
33
+ } else if (this.options.img) {
34
+ this.options.img.addEventListener('load', drawImage);
35
+ }
36
+ }
37
+ }
38
+
39
+ export {
40
+ Image,
41
+ };
package/src/tool/index.js CHANGED
@@ -9,3 +9,4 @@ export {Font} from './Font';
9
9
  export {Star} from './Star';
10
10
  export {Flag} from './Flag';
11
11
  export {Dot} from './Dot';
12
+ export {Image} from './Image';