kfb-view 3.2.3 → 3.2.4

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": "3.2.3",
4
+ "version": "3.2.4",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -12,7 +12,7 @@ import {
12
12
  getAngle, getDistance, getPoint,
13
13
  getRectPoint,
14
14
  isPointInMatrix,
15
- pointInOtherPoint, isPointInPolygon, pointsToRegion, isPointInLine,
15
+ pointInOtherPoint, isPointInPolygon, pointsToRegion, isPointInLine, getRectPointV2,
16
16
  } from '../../util/calculate';
17
17
  import {
18
18
  EVENT_ADD_POLYGON_POINT,
@@ -69,65 +69,60 @@ export class Area extends ViewerCommon {
69
69
 
70
70
  /**
71
71
  * 画线
72
- * @param {Object} point
73
- * @param {number} index
74
- * @param {Boolean=} active 是否是激活状态
72
+ * @param {array} points
73
+ * @param {number} position
75
74
  */
76
- drawLine(point, index, active) {
75
+ drawLines(points, position) {
77
76
  const ctx = this.canvas.getContext('2d');
78
- ctx.beginPath();
79
- const strokeStyle = !active ?
80
- this.options.thumb.color :
81
- this.options.thumb.activeColor;
82
- const lineWidth = (!active ?
83
- this.options.thumb.radius :
84
- this.options.thumb.activeRadius) * 2;
85
- ctx.strokeStyle = strokeStyle || '#01d0b0';
86
- ctx.lineWidth = 2;
87
- if (index === 0) {
88
- ctx.moveTo(point.x - 5, point.y - 5);
89
- ctx.lineTo(point.x - 5 + lineWidth, point.y - 5);
90
- ctx.moveTo(point.x - 5, point.y - 5);
91
- ctx.lineTo(point.x - 5, point.y - 5 + lineWidth);
92
- } else if (index === 1) {
93
- ctx.moveTo(point.x, point.y - 5);
94
- ctx.lineTo(point.x - lineWidth / 2, point.y - 5);
95
- ctx.moveTo(point.x, point.y - 5);
96
- ctx.lineTo(point.x + lineWidth / 2, point.y - 5);
97
- } else if (index === 2) {
98
- ctx.moveTo(point.x + 5, point.y - 5);
99
- ctx.lineTo(point.x + 5 - lineWidth, point.y - 5);
100
- ctx.moveTo(point.x + 5, point.y - 5);
101
- ctx.lineTo(point.x + 5, point.y - 5 + lineWidth);
102
- } else if (index === 3) {
103
- ctx.moveTo(point.x - 5, point.y);
104
- ctx.lineTo(point.x - 5, point.y - lineWidth / 2);
105
- ctx.moveTo(point.x - 5, point.y);
106
- ctx.lineTo(point.x - 5, point.y + lineWidth / 2);
107
- } else if (index === 4 && active) {
108
- this.drawPoint(point, active);
109
- } else if (index === 5) {
110
- ctx.moveTo(point.x + 5, point.y);
111
- ctx.lineTo(point.x + 5, point.y - lineWidth / 2);
112
- ctx.moveTo(point.x + 5, point.y);
113
- ctx.lineTo(point.x + 5, point.y + lineWidth / 2);
114
- } else if (index === 6) {
115
- ctx.moveTo(point.x - 5, point.y + 5);
116
- ctx.lineTo(point.x - 5, point.y + 5 - lineWidth);
117
- ctx.moveTo(point.x - 5, point.y + 5);
118
- ctx.lineTo(point.x - 5 + lineWidth, point.y + 5);
119
- } else if (index === 7) {
120
- ctx.moveTo(point.x, point.y + 5);
121
- ctx.lineTo(point.x - lineWidth / 2, point.y + 5);
122
- ctx.moveTo(point.x, point.y + 5);
123
- ctx.lineTo(point.x + lineWidth / 2, point.y + 5);
124
- } else if (index === 8) {
125
- ctx.moveTo(point.x + 5, point.y + 5);
126
- ctx.lineTo(point.x + 5, point.y + 5 - lineWidth);
127
- ctx.moveTo(point.x + 5, point.y + 5);
128
- ctx.lineTo(point.x + 5 - lineWidth, point.y + 5);
129
- }
130
- ctx.stroke();
77
+ const dist = 5;
78
+ points.forEach((point, index) => {
79
+ ctx.beginPath();
80
+ ctx.strokeStyle = strokeStyle || '#01d0b0';
81
+ ctx.lineWidth = 2;
82
+ const active = index === position;
83
+ const strokeStyle = !active ?
84
+ this.options.thumb.color :
85
+ this.options.thumb.activeColor;
86
+ let lineWidth = (!active ?
87
+ this.options.thumb.radius :
88
+ this.options.thumb.activeRadius) * 2;
89
+ if (index === 0 || index === 2) {
90
+ const point1 = points[1];
91
+ const point2 = index === 2 ? points[5] : points[3];
92
+ const ratioX = point1.x > point.x ? -1 : 1;
93
+ const ratioY = point2.y > point.y ? -1 : 1;
94
+ ctx.moveTo(point.x + dist * ratioX, point.y + dist * ratioY);
95
+ ctx.lineTo(point.x + (dist - lineWidth) * ratioX, point.y + dist * ratioY);
96
+ ctx.moveTo(point.x + dist * ratioX, point.y + dist * ratioY);
97
+ ctx.lineTo(point.x + dist * ratioX, point.y + (dist - lineWidth) * ratioY);
98
+ } else if (index === 1 || index === 7) {
99
+ const point4 = points[4];
100
+ const ratioY = point4.y > point.y ? -1 : 1;
101
+ ctx.moveTo(point.x, point.y + dist * ratioY);
102
+ ctx.lineTo(point.x - lineWidth / 2, point.y + dist * ratioY);
103
+ ctx.moveTo(point.x, point.y + dist * ratioY);
104
+ ctx.lineTo(point.x + lineWidth / 2, point.y + dist * ratioY);
105
+ } else if (index === 3 || index === 5) {
106
+ const point4 = points[4];
107
+ const ratioX = point4.x > point.x ? -1 : 1;
108
+ ctx.moveTo(point.x + dist * ratioX, point.y);
109
+ ctx.lineTo(point.x + dist * ratioX, point.y - lineWidth / 2);
110
+ ctx.moveTo(point.x + dist * ratioX, point.y);
111
+ ctx.lineTo(point.x + dist * ratioX, point.y + lineWidth / 2);
112
+ } else if (index === 4 && active) {
113
+ this.drawPoint(point, active);
114
+ } else if (index === 6 || index === 8) {
115
+ const point3 = index === 8 ? points[5] : points[3];
116
+ const point7 = points[7];
117
+ const ratioY = point3.y > point.y ? -1 : 1;
118
+ const ratioX = point7.x > point.x ? -1 : 1;
119
+ ctx.moveTo(point.x + dist * ratioX, point.y + dist * ratioY);
120
+ ctx.lineTo(point.x + dist * ratioX, point.y + (dist - lineWidth) * ratioY);
121
+ ctx.moveTo(point.x + dist * ratioX, point.y + dist * ratioY);
122
+ ctx.lineTo(point.x + (dist - lineWidth) * ratioX, point.y + dist * ratioY);
123
+ }
124
+ ctx.stroke();
125
+ });
131
126
  }
132
127
 
133
128
  /**
@@ -154,7 +149,7 @@ export class Area extends ViewerCommon {
154
149
  let selectLabel;
155
150
  let prevSelectLabel = undefined;
156
151
  const bounds = this.viewport.viewportToImageRectangle(
157
- this.viewport.getBounds());
152
+ this.viewport.getBoundsNoRotate());
158
153
  this.labelList.forEach((item) => {
159
154
  if (item.tool === IMAGE) {
160
155
  return;
@@ -172,19 +167,23 @@ export class Area extends ViewerCommon {
172
167
  let moveIndex = -1; // 可移动点位置
173
168
  let pointList = []; // 可移动点的集合
174
169
  const scale = this.getImageZoom(true) / item.scale;
175
- const region = item.region;
176
- const startPoint = this.imageToViewerElementCoordinates(region.x,
177
- region.y);
178
- const endPoint = this.imageToViewerElementCoordinates(
179
- region.x + region.width, region.y + region.height);
170
+ const points = this.imageToViewerElementPoints(item.points);
171
+ const startPoint = {
172
+ x: points[0].x,
173
+ y: points[0].y,
174
+ };
175
+ const endPoint = {
176
+ x: points[points.length - 1].x,
177
+ y: points[points.length - 1].y,
178
+ };
180
179
  if (REGION_TYPES.includes(item.tool)) {
181
180
  // 区域类的图形有9个可移动的点
182
- pointList = getRectPoint(startPoint, endPoint);
181
+ pointList = getRectPointV2(points);
183
182
  moveIndex = pointList.findIndex(
184
183
  (point) => pointInOtherPoint(point, {x, y}));
185
184
  } else if (item.tool === POLYGON) {
186
185
  // 曲线,每个有效的点都可以移动
187
- pointList = this.setPointsMove(item);
186
+ pointList = this.setPointsMove(item, points);
188
187
  moveIndex = pointList.findIndex(
189
188
  (point) => point.canMove && pointInOtherPoint(point, {x, y}));
190
189
  } else if (LINE_TYPES.includes(item.tool)) {
@@ -318,25 +317,20 @@ export class Area extends ViewerCommon {
318
317
  const selectLabel = this.labelList.find(
319
318
  ({tool, select}) => tool === RECTANGLE && select);
320
319
  if (selectLabel && !this.movePoint) {
321
- const region = this.imageToViewerElementRectangle(selectLabel.region);
320
+ const points = this.imageToViewerElementPoints(selectLabel.points);
322
321
  if (this.isContainerInRegion({x, y}, {
323
- ...selectLabel,
324
- region,
322
+ isClose: true,
323
+ points,
324
+ tool: RECTANGLE,
325
+ region: pointsToRegion(points),
325
326
  })) {
326
- const startPoint = {
327
- x: region.x,
328
- y: region.y,
329
- };
330
- const endPoint = {
331
- x: region.x + region.width,
332
- y: region.y + region.height,
327
+ const centerPoint = {
328
+ x: (points[points.length - 1].x + points[0].x) / 2,
329
+ y: (points[points.length - 1].y + points[0].y) / 2,
333
330
  };
334
- const pointList = getRectPoint(startPoint, endPoint);
335
- const moveIndex = pointList.findIndex(
336
- (point) => pointInOtherPoint(point, {x, y}));
337
- if (moveIndex === 4) {
331
+ if (pointInOtherPoint(centerPoint, {x, y})) {
338
332
  this.isHover = true;
339
- this.drawPoint(pointList[4], !!this.movePoint);
333
+ this.drawPoint(centerPoint, !!this.movePoint);
340
334
  } else if (this.isHover) {
341
335
  this.isHover = false;
342
336
  this.change();
@@ -386,67 +380,73 @@ export class Area extends ViewerCommon {
386
380
  e.preventDefaultAction = true;
387
381
  const scale = this.getImageZoom(true) / label.scale;
388
382
  const tool = label.tool;
389
- const region = label.region;
390
- const startPoint = this.imageToViewerElementCoordinates(region.x,
391
- region.y);
392
- const endPoint = this.imageToViewerElementCoordinates(
393
- region.x + region.width, region.y + region.height);
383
+ const points = this.imageToViewerElementPoints(label.points);
384
+ const startPoint = points[0];
385
+ const endPoint = points[points.length - 1];
394
386
  const distX = (x - this.lastPoint.x);
395
387
  const distY = (y - this.lastPoint.y);
396
- let _startPoint = {...startPoint};
397
- let _endPoint = {...endPoint};
398
388
  if (LINE_TYPES.includes(tool)) {
399
389
  if (position === 4) {
400
- _startPoint = {x: startPoint.x + distX, y: startPoint.y + distY};
401
- _endPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
390
+ points[0] = {x: startPoint.x + distX, y: startPoint.y + distY};
391
+ points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
402
392
  }
403
393
  if (position === 1) {
404
- _startPoint = {x: startPoint.x + distX, y: startPoint.y + distY};
394
+ points[0] = {x: startPoint.x + distX, y: startPoint.y + distY};
405
395
  }
406
396
  if (position === 7) {
407
- _endPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
397
+ points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
408
398
  }
409
399
  } else if (REGION_TYPES.includes(tool)) {
410
- const pointList = getRectPoint(startPoint, endPoint);
400
+ const pointList = getRectPointV2(points);
411
401
  switch (position) {
412
402
  case 0:
413
- _startPoint = {x: pointList[0].x + distX, y: pointList[0].y + distY};
403
+ points[0] = {x: pointList[0].x + distX, y: pointList[0].y + distY};
404
+ points[1] = {x: pointList[2].x, y: pointList[2].y + distY};
405
+ points[2] = {x: pointList[6].x + distX, y: pointList[6].y};
414
406
  break;
415
407
  case 1:
416
- _startPoint = {x: pointList[0].x, y: pointList[0].y + distY};
408
+ points[0] = {x: pointList[0].x, y: pointList[0].y + distY};
409
+ points[1] = {x: pointList[2].x, y: pointList[2].y + distY};
417
410
  break;
418
411
  case 2:
419
- _startPoint = {x: pointList[0].x, y: pointList[0].y + distY};
420
- _endPoint = {x: pointList[8].x + distX, y: pointList[8].y};
412
+ points[0] = {x: pointList[0].x, y: pointList[0].y + distY};
413
+ points[1] = {x: pointList[2].x + distX, y: pointList[2].y + distY};
414
+ points[3] = {x: pointList[8].x + distX, y: pointList[8].y};
421
415
  break;
422
416
  case 3:
423
- _startPoint = {x: pointList[0].x + distX, y: pointList[0].y};
417
+ points[0] = {x: pointList[0].x + distX, y: pointList[0].y};
418
+ points[2] = {x: pointList[6].x + distX, y: pointList[6].y};
424
419
  break;
425
420
  case 4:
426
- _startPoint = {x: pointList[0].x + distX, y: pointList[0].y + distY};
427
- _endPoint = {x: pointList[8].x + distX, y: pointList[8].y + distY};
421
+ points[0] = {x: pointList[0].x + distX, y: pointList[0].y + distY};
422
+ points[1] = {x: pointList[2].x + distX, y: pointList[2].y + distY};
423
+ points[2] = {x: pointList[6].x + distX, y: pointList[6].y + distY};
424
+ points[3] = {x: pointList[8].x + distX, y: pointList[8].y + distY};
428
425
  break;
429
426
  case 5:
430
- _endPoint = {x: pointList[8].x + distX, y: pointList[8].y};
427
+ points[1] = {x: pointList[2].x + distX, y: pointList[2].y};
428
+ points[3] = {x: pointList[8].x + distX, y: pointList[8].y};
431
429
  break;
432
430
  case 6:
433
- _startPoint = {x: pointList[0].x + distX, y: pointList[0].y};
434
- _endPoint = {x: pointList[8].x, y: pointList[8].y + distY};
431
+ points[0] = {x: pointList[0].x + distX, y: pointList[0].y};
432
+ points[2] = {x: pointList[6].x + distX, y: pointList[6].y + distY};
433
+ points[3] = {x: pointList[8].x, y: pointList[8].y + distY};
435
434
  break;
436
435
  case 7:
437
- _endPoint = {x: pointList[8].x, y: pointList[8].y + distY};
436
+ points[2] = {x: pointList[6].x, y: pointList[6].y + distY};
437
+ points[3] = {x: pointList[8].x, y: pointList[8].y + distY};
438
438
  break;
439
439
  case 8:
440
- _endPoint = {x: pointList[8].x + distX, y: pointList[8].y + distY};
440
+ points[1] = {x: pointList[2].x + distX, y: pointList[2].y};
441
+ points[2] = {x: pointList[6].x, y: pointList[6].y + distY};
442
+ points[3] = {x: pointList[8].x + distX, y: pointList[8].y + distY};
441
443
  break;
442
444
  }
443
445
  } else if (tool === POLYGON) {
444
- const points = this.imageToViewerElementPoints(label.points).
445
- map((item, index) => ({
446
- ...item,
447
- index,
448
- }));
449
- const movePoints = points.filter(({canMove}) => canMove);
446
+ const movePoints = points.map((item, index) => ({
447
+ ...item,
448
+ index,
449
+ })).filter(({canMove}) => canMove);
450
450
  let lastIndex = undefined;
451
451
  let nextIndex = undefined;
452
452
  // 获取当前移动点的上一个点和下一个点序号
@@ -527,13 +527,13 @@ export class Area extends ViewerCommon {
527
527
  });
528
528
  } else if (tool === FONT || tool === DOT) {
529
529
  if (position === 4) {
530
- _startPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
531
- _endPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
530
+ points[0] = {x: endPoint.x + distX, y: endPoint.y + distY};
531
+ points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
532
532
  }
533
533
  } else if (tool === STAR) {
534
534
  if (position === 4) {
535
- _startPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
536
- _endPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
535
+ points[0] = {x: endPoint.x + distX, y: endPoint.y + distY};
536
+ points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
537
537
  } else if (position === 0 || position === 2) {
538
538
  label.lineWidth -= distY / scale;
539
539
  } else if (position === 6 || position === 8) {
@@ -541,20 +541,18 @@ export class Area extends ViewerCommon {
541
541
  }
542
542
  } else if (tool === FLAG) {
543
543
  if (position === 4) {
544
- _startPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
545
- _endPoint = {x: endPoint.x + distX, y: endPoint.y + distY};
544
+ points[0] = {x: endPoint.x + distX, y: endPoint.y + distY};
545
+ points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
546
546
  } else if (position === 0 || position === 2) {
547
547
  label.lineWidth -= distY / scale;
548
548
  } else if (position === 6 || position === 8) {
549
549
  label.lineWidth += distY / scale;
550
- _endPoint = {x: endPoint.x, y: endPoint.y + distY};
551
- _startPoint = {x: endPoint.x, y: endPoint.y + distY};
550
+ points[1] = {x: endPoint.x, y: endPoint.y + distY};
551
+ points[0] = {x: endPoint.x, y: endPoint.y + distY};
552
552
  }
553
553
  }
554
554
  if (tool !== POLYGON) {
555
- label.points = [
556
- this.viewerElementToImageCoordinates(_startPoint.x, _startPoint.y),
557
- this.viewerElementToImageCoordinates(_endPoint.x, _endPoint.y)];
555
+ label.points = this.viewerElementToImagePoints(points);
558
556
  }
559
557
  label.region = pointsToRegion(label.points);
560
558
  this.mitt.$emit(EVENT_AREA_MOVING, label);
@@ -579,19 +577,9 @@ export class Area extends ViewerCommon {
579
577
  }, position === 4);
580
578
  this.drawPoint(points[1], position === 7);
581
579
  } else if (type === RECTANGLE) {
582
- const sp = {
583
- x: points[0].x < points[1].x ? points[0].x : points[1].x,
584
- y: points[0].y < points[1].y ? points[0].y : points[1].y,
585
- };
586
- const ep = {
587
- x: points[0].x > points[1].x ? points[0].x : points[1].x,
588
- y: points[0].y > points[1].y ? points[0].y : points[1].y,
589
- };
590
- getRectPoint(sp, ep).forEach((point, i) => {
591
- this.drawLine(point, i, position === i);
592
- });
580
+ this.drawLines(getRectPointV2(points), position);
593
581
  } else if (REGION_TYPES.includes(type)) {
594
- getRectPoint(points[0], points[1]).forEach((point, i) => {
582
+ getRectPointV2(points).forEach((point, i) => {
595
583
  this.drawPoint(point, position === i);
596
584
  });
597
585
  } else if (type === POLYGON) {
@@ -622,15 +610,11 @@ export class Area extends ViewerCommon {
622
610
  const label = this.labelList.find((item) => item.select);
623
611
  if (!label) return;
624
612
  if (label.show === false) return;
625
- const region = label.region;
626
- const startPoint =
627
- this.imageToViewerElementCoordinates(region.x, region.y);
628
- const endPoint =
629
- this.imageToViewerElementCoordinates(
630
- region.x + region.width, region.y + region.height);
613
+ const points = this.imageToViewerElementPoints(label.points);
614
+ const startPoint = points[0];
631
615
  const scale = this.getImageZoom(true) / label.scale;
632
616
  if (!NO_NORMAL_REGION_TYPES.includes(label.tool)) {
633
- this.drawThumbPoints([startPoint, endPoint], label.tool);
617
+ this.drawThumbPoints(this.imageToViewerElementPoints(label.points), label.tool);
634
618
  } else if (label.tool === FONT) {
635
619
  const fontWidth = this.getFontWidth(label.text, label.fontSize);
636
620
  const pt = getPoint(startPoint, {
@@ -666,11 +650,9 @@ export class Area extends ViewerCommon {
666
650
  }], label.tool);
667
651
  } else if (label.tool === POLYGON) {
668
652
  if (this.draging) {
669
- const points = this.imageToViewerElementPoints(label.points);
670
653
  this.drawThumbPoints(points, label.tool);
671
654
  } else {
672
- const points = this.setPointsMove(label);
673
- this.drawThumbPoints(points, label.tool);
655
+ this.drawThumbPoints(this.setPointsMove(label, points), label.tool);
674
656
  }
675
657
  }
676
658
  this[label.tool].setContent(this.canvas, {...label});
@@ -678,7 +660,7 @@ export class Area extends ViewerCommon {
678
660
 
679
661
  showLabelMeasure() {
680
662
  const bounds = this.viewport.viewportToImageRectangle(
681
- this.viewport.getBounds());
663
+ this.viewport.getBoundsNoRotate());
682
664
  const currentScale = this.getImageZoom(true) * this.options.scale;
683
665
  this.labelList.forEach((label) => {
684
666
  if (label.show === false) return;
@@ -707,23 +689,23 @@ export class Area extends ViewerCommon {
707
689
  /**
708
690
  * 设置可移动点,两端点相距30px以上认为是可移动点
709
691
  * @param {object} label
692
+ * @param {array} points
710
693
  * @return {{}[]}
711
694
  */
712
- setPointsMove(label) {
713
- const movePoints = this.imageToViewerElementPoints(label.points);
714
- let lastPoint = movePoints[0];
695
+ setPointsMove(label, points) {
696
+ let lastPoint = points[0];
715
697
  const dist = this.options.label?.polygonWidth || 30;
716
- movePoints.forEach((point, index) => {
698
+ points.forEach((point, index) => {
717
699
  point.canMove = false;
718
700
  label.points[index].canMove = false;
719
701
  if (index === 0 || (!pointInOtherPoint(lastPoint, point, dist) &&
720
- !pointInOtherPoint(movePoints[0], point, dist)) ||
721
- (index === movePoints.length - 1)) {
702
+ !pointInOtherPoint(points[0], point, dist)) ||
703
+ (index === points.length - 1)) {
722
704
  lastPoint = point;
723
705
  point.canMove = true;
724
706
  label.points[index].canMove = true;
725
707
  }
726
708
  });
727
- return movePoints;
709
+ return points;
728
710
  }
729
711
  }
@@ -3,7 +3,7 @@ import * as Tools from '../../tool';
3
3
  import {
4
4
  POLYGON, DOT, FLAG, MARKS,
5
5
  NO_NORMAL_REGION_TYPES,
6
- POINT_TYPES, STAR, ELLIPSE,
6
+ POINT_TYPES, STAR, ELLIPSE, REGION_TYPES,
7
7
  } from '../../const/mark';
8
8
  import {
9
9
  EVENT_START_PAINTING,
@@ -12,7 +12,7 @@ import {
12
12
  } from '../../const/event';
13
13
  import {
14
14
  getAngle,
15
- getDistance,
15
+ getDistance, getRectPoints,
16
16
  pointInOtherPoint,
17
17
  pointsToRegion,
18
18
  } from '../../util/calculate';
@@ -142,8 +142,8 @@ export class Board extends ViewerCommon {
142
142
  const tool = this.tool;
143
143
  if (tool === POLYGON) {
144
144
  this.points.push(point);
145
- } else if (ELLIPSE === tool) {
146
- this.points = [point, point];
145
+ } else if (REGION_TYPES.includes(tool)) {
146
+ this.points = [point, point, point, point];
147
147
  } else {
148
148
  this.points = [point];
149
149
  }
@@ -174,14 +174,9 @@ export class Board extends ViewerCommon {
174
174
  }
175
175
  e.preventDefaultAction = true;
176
176
  const tool = this.tool;
177
- if (ELLIPSE === tool) {
178
- const _x = point.x - this.points[1].x;
179
- const _y = point.y - this.points[1].y;
180
- const _point = {
181
- x: this.points[1].x - _x,
182
- y: this.points[1].y - _y,
183
- };
184
- this.points = [_point, this.points[1], point];
177
+ if (REGION_TYPES.includes(tool)) {
178
+ const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x, this.points[0].y);
179
+ this.points = this.viewerElementToImagePoints(getRectPoints([firstPoint, {x, y}]));
185
180
  } else if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
186
181
  this.points = [this.points[0] || point, point];
187
182
  } else if (tool === POLYGON) {
@@ -217,23 +212,7 @@ export class Board extends ViewerCommon {
217
212
  return;
218
213
  }
219
214
  const tool = this.tool;
220
- if (ELLIPSE === tool) {
221
- const _x = point.x - this.points[1].x;
222
- const _y = point.y - this.points[1].y;
223
- const _point = {
224
- x: this.points[1].x - _x,
225
- y: this.points[1].y - _y,
226
- };
227
- this.points = [_point, point];
228
- const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x,
229
- this.points[0].y);
230
- const dist = getDistance(firstPoint, {x, y});
231
- if (Math.abs(dist) < 10) {
232
- this.points = [];
233
- this.clearCanvas();
234
- return;
235
- }
236
- } else if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
215
+ if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
237
216
  const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x,
238
217
  this.points[0].y);
239
218
  const dist = getDistance(firstPoint, {x, y});
@@ -403,13 +382,13 @@ export class Board extends ViewerCommon {
403
382
  }
404
383
 
405
384
  getPaintOptions() {
406
- console.log(this.tool);
407
385
  const form = new LabelModel({
408
386
  ...this[this.tool].options,
409
387
  points: this.points,
410
388
  scale: this.getImageZoom(true),
411
389
  region: pointsToRegion(this.points),
412
390
  tool: this.tool,
391
+ angle: this.viewport.getRotation() % 360,
413
392
  });
414
393
  if (form.measure) {
415
394
  this[this.tool].drawMeasureInfo.call(this, form,
@@ -8,7 +8,7 @@ import {
8
8
  isPointInEllipse,
9
9
  isPointInMatrix,
10
10
  isPointInPolygon,
11
- calculatePolygonArea,
11
+ calculatePolygonArea, getRectPointV2,
12
12
  } from '../../util/calculate';
13
13
  import {Point, Rect} from '../../plugin/openseadragon/openseadragon';
14
14
  import {
@@ -93,6 +93,9 @@ export class ViewerCommon {
93
93
  * @return {boolean}
94
94
  */
95
95
  isContainerInRegion(point, {region, tool, points, isClose}) {
96
+ if (tool === POLYGON && isClose) {
97
+ return isPointInPolygon(point, points);
98
+ }
96
99
  const p1 = {x: region.x, y: region.y};
97
100
  const p2 = {x: region.x + region.width, y: region.y};
98
101
  const p3 = {x: region.x, y: region.y + region.height};
@@ -107,9 +110,6 @@ export class ViewerCommon {
107
110
  if (tool === RECTANGLE) {
108
111
  return isPointInMatrix(p1, p2, p3, p4, point);
109
112
  }
110
- if (tool === POLYGON && isClose) {
111
- return isPointInPolygon(point, points);
112
- }
113
113
  return false;
114
114
  }
115
115
 
@@ -178,6 +178,23 @@ export class ViewerCommon {
178
178
  });
179
179
  }
180
180
 
181
+
182
+ /**
183
+ * 转化图像点数组到元素坐标点数组
184
+ * @param {Array} points
185
+ * @return {{}[]}
186
+ */
187
+ viewerElementToImagePoints(points) {
188
+ return (points || []).map((point) => {
189
+ const p = this.viewerElementToImageCoordinates(point.x, point.y);
190
+ return {
191
+ canMove: point.canMove,
192
+ x: p.x,
193
+ y: p.y,
194
+ };
195
+ });
196
+ }
197
+
181
198
  /**
182
199
  * 返回图像倍率
183
200
  * @param {boolean} current Pass true for the current location; defaults to false (target location).
@@ -224,36 +241,12 @@ export class ViewerCommon {
224
241
  };
225
242
  const w = Math.abs(endPoint.x - startPoint.x);
226
243
  const h = Math.abs(endPoint.y - startPoint.y);
227
- const center = {
228
- x: (endPoint.x + startPoint.x) / 2,
229
- y: (endPoint.y + startPoint.y) / 2,
230
- };
231
- const deg = getAngle(startPoint, {...startPoint, x: startPoint.x + 1},
232
- endPoint);
233
- const p = this.imageToViewerElementCoordinates(center.x,
234
- center.y);
235
- let distY = -50;
236
- let distX = -50;
237
- if (endPoint.y < startPoint.y && endPoint.x > startPoint.x) {
238
- distY = -50;
239
- distX = -50;
240
- }
241
- if (endPoint.y < startPoint.y && endPoint.x < startPoint.x) {
242
- distY = -10;
243
- distX = 50;
244
- }
245
- if (endPoint.y > startPoint.y && endPoint.x > startPoint.x) {
246
- distY = 10;
247
- distX = -50;
248
- }
249
- if (endPoint.y > startPoint.y && endPoint.x < startPoint.x) {
250
- distY = 50;
251
- distX = 80;
252
- }
244
+ const p = this.imageToViewerElementCoordinates(endPoint.x,
245
+ endPoint.y);
253
246
  content = {
254
- left: p.x + distX * scale,
255
- top: p.y + distY * scale,
256
- angle: deg,
247
+ left: p.x + 10 * scale,
248
+ top: p.y,
249
+ angle: 0,
257
250
  texts: [
258
251
  `长:${this.getUnitNumber((Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(2))}`],
259
252
  };
@@ -17,7 +17,7 @@ export class Graduation extends ViewerCommon {
17
17
  constructor({viewer, canvas, cache, options}) {
18
18
  super(viewer, canvas, cache, options);
19
19
  this.microns = options.microns ||
20
- [5000, 2000, 1500, 1250, 1000, 800, 500, 400, 250, 200, 150, 125, 100, 80, 60, 40, 20, 10, 8, 5];
20
+ [5000, 2000, 1500, 1250, 1000, 800, 500, 400, 250, 200, 150, 125, 100, 80, 60, 40, 20, 10, 8, 5, 4, 2, 1];
21
21
  }
22
22
 
23
23
  /**
@@ -25,8 +25,9 @@ export class Graduation extends ViewerCommon {
25
25
  */
26
26
  change() {
27
27
  const microns = this.microns;
28
- const rect = this.viewerElementToImageRectangle({x: 0, y: 0, width: 50, height: 50});
29
- const max = rect.height * this.options.imageCapRes;
28
+ const startPoint = this.viewerElementToImageCoordinates(0, 0);
29
+ const endPoint = this.viewerElementToImageCoordinates(50, 0);
30
+ const max = endPoint.distanceTo(startPoint) * this.options.imageCapRes;
30
31
  const index = this.microns.findIndex((i) => i <= max);
31
32
  if (!~index) {
32
33
  this.setScaleLine(microns[microns.length - 1],
@@ -45,7 +46,7 @@ export class Graduation extends ViewerCommon {
45
46
  setScaleLine(txt, px) {
46
47
  const startPoint = this.imageToViewerElementCoordinates(0, 0);
47
48
  const endPoint = this.imageToViewerElementCoordinates(px, 0);
48
- const width = Math.abs(endPoint.x - startPoint.x);
49
+ const width = endPoint.distanceTo(startPoint);
49
50
  if (this.options.custom) {
50
51
  this.mitt.$emit(EVENT_GRADUATION_CHANGE, {width, txt});
51
52
  } else {