kfb-view 2.2.9 → 2.3.0

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.9",
4
+ "version": "2.3.0",
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, IMAGE,
9
+ STAR, IMAGE, RECTANGLE,
10
10
  } from '../../const/mark';
11
11
  import {
12
12
  baseNumber, getAngle, getDistance, getPoint,
@@ -66,6 +66,69 @@ export class Area extends ViewerCommon {
66
66
  });
67
67
  }
68
68
 
69
+ /**
70
+ * 画线
71
+ * @param {Object} point
72
+ * @param {number} index
73
+ * @param {Boolean=} active 是否是激活状态
74
+ */
75
+ drawLine(point, index, active) {
76
+ const ctx = this.canvas.getContext('2d');
77
+ ctx.beginPath();
78
+ const strokeStyle = !active ?
79
+ this.options.thumb.color :
80
+ this.options.thumb.activeColor;
81
+ const lineWidth = (!active ?
82
+ this.options.thumb.radius :
83
+ this.options.thumb.activeRadius) * 2;
84
+ ctx.strokeStyle = strokeStyle || '#01d0b0';
85
+ ctx.lineWidth = 2;
86
+ if (index === 0) {
87
+ ctx.moveTo(point.x - 5, point.y - 5);
88
+ ctx.lineTo(point.x - 5 + lineWidth, point.y - 5);
89
+ ctx.moveTo(point.x - 5, point.y - 5);
90
+ ctx.lineTo(point.x - 5, point.y - 5 + lineWidth);
91
+ } else if (index === 1) {
92
+ ctx.moveTo(point.x, point.y - 5);
93
+ ctx.lineTo(point.x - lineWidth / 2, point.y - 5);
94
+ ctx.moveTo(point.x, point.y - 5);
95
+ ctx.lineTo(point.x + lineWidth / 2, point.y - 5);
96
+ } else if (index === 2) {
97
+ ctx.moveTo(point.x + 5, point.y - 5);
98
+ ctx.lineTo(point.x + 5 - lineWidth, point.y - 5);
99
+ ctx.moveTo(point.x + 5, point.y - 5);
100
+ ctx.lineTo(point.x + 5, point.y - 5 + lineWidth);
101
+ } else if (index === 3) {
102
+ ctx.moveTo(point.x - 5, point.y);
103
+ ctx.lineTo(point.x - 5, point.y - lineWidth / 2);
104
+ ctx.moveTo(point.x - 5, point.y);
105
+ ctx.lineTo(point.x - 5, point.y + lineWidth / 2);
106
+ } else if (index === 4 && active) {
107
+ this.drawPoint(point, active);
108
+ } else if (index === 5) {
109
+ ctx.moveTo(point.x + 5, point.y);
110
+ ctx.lineTo(point.x + 5, point.y - lineWidth / 2);
111
+ ctx.moveTo(point.x + 5, point.y);
112
+ ctx.lineTo(point.x + 5, point.y + lineWidth / 2);
113
+ } else if (index === 6) {
114
+ ctx.moveTo(point.x - 5, point.y + 5);
115
+ ctx.lineTo(point.x - 5, point.y + 5 - lineWidth);
116
+ ctx.moveTo(point.x - 5, point.y + 5);
117
+ ctx.lineTo(point.x - 5 + lineWidth, point.y + 5);
118
+ } else if (index === 7) {
119
+ ctx.moveTo(point.x, point.y + 5);
120
+ ctx.lineTo(point.x - lineWidth / 2, point.y + 5);
121
+ ctx.moveTo(point.x, point.y + 5);
122
+ ctx.lineTo(point.x + lineWidth / 2, point.y + 5);
123
+ } else if (index === 8) {
124
+ ctx.moveTo(point.x + 5, point.y + 5);
125
+ ctx.lineTo(point.x + 5, point.y + 5 - lineWidth);
126
+ ctx.moveTo(point.x + 5, point.y + 5);
127
+ ctx.lineTo(point.x + 5 - lineWidth, point.y + 5);
128
+ }
129
+ ctx.stroke();
130
+ }
131
+
69
132
  /**
70
133
  * 设置List
71
134
  * @param {Object} list
@@ -256,6 +319,26 @@ export class Area extends ViewerCommon {
256
319
  });
257
320
  }
258
321
 
322
+ onCanvasMove({x, y}) {
323
+ const selectLabel = this.labelList.find(
324
+ ({tool, select}) => tool === RECTANGLE && select);
325
+ if (selectLabel) {
326
+ const region = selectLabel.region;
327
+ const startPoint = this.imageToViewerElementCoordinates(region.x,
328
+ region.y);
329
+ const endPoint = this.imageToViewerElementCoordinates(
330
+ region.x + region.width, region.y + region.height);
331
+ const pointList = getRectPoint(startPoint, endPoint);
332
+ const moveIndex = pointList.findIndex(
333
+ (point) => pointInOtherPoint(point, {x, y}));
334
+ if (moveIndex === 4) {
335
+ this.drawPoint(pointList[4], !!this.movePoint);
336
+ } else {
337
+ this.change();
338
+ }
339
+ }
340
+ }
341
+
259
342
  /**
260
343
  * 监听鼠标释放事件
261
344
  * @param {Object} e
@@ -489,6 +572,10 @@ export class Area extends ViewerCommon {
489
572
  y: (points[0].y + points[1].y) / 2,
490
573
  }, position === 4);
491
574
  this.drawPoint(points[1], position === 7);
575
+ } else if (type === RECTANGLE) {
576
+ getRectPoint(points[0], points[1]).forEach((point, i) => {
577
+ this.drawLine(point, i, position === i);
578
+ });
492
579
  } else if (REGION_TYPES.includes(type)) {
493
580
  getRectPoint(points[0], points[1]).forEach((point, i) => {
494
581
  this.drawPoint(point, position === i);
package/src/view.js CHANGED
@@ -411,6 +411,9 @@ function initEvent(kv) {
411
411
  new openSeadragon.MouseTracker({
412
412
  element: kv.viewer.canvas,
413
413
  moveHandler: function(event) {
414
+ if (kv.area?.onCanvasMove) {
415
+ kv.area.onCanvasMove(event.position);
416
+ }
414
417
  if (isRightDown && kv.board?.isInDraw) {
415
418
  console.log('nonprimary drag');
416
419
  let delta = event.position.minus(dragPosition);