kfb-view 3.2.2 → 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/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/area/index.js +154 -177
- package/src/components/board/index.js +9 -30
- package/src/components/common/common.js +26 -33
- package/src/components/graduation/index.js +5 -4
- package/src/components/shape/index.js +10 -6
- package/src/tool/Combination.js +14 -4
- package/src/tool/Ellipse.js +12 -13
- package/src/tool/Font.js +4 -3
- package/src/tool/Rectangle.js +10 -23
- package/src/util/calculate.js +62 -0
package/package.json
CHANGED
|
@@ -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 {
|
|
73
|
-
* @param {number}
|
|
74
|
-
* @param {Boolean=} active 是否是激活状态
|
|
72
|
+
* @param {array} points
|
|
73
|
+
* @param {number} position
|
|
75
74
|
*/
|
|
76
|
-
|
|
75
|
+
drawLines(points, position) {
|
|
77
76
|
const ctx = this.canvas.getContext('2d');
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
ctx.
|
|
126
|
-
|
|
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.
|
|
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
|
|
176
|
-
const startPoint =
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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 =
|
|
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
|
|
320
|
+
const points = this.imageToViewerElementPoints(selectLabel.points);
|
|
322
321
|
if (this.isContainerInRegion({x, y}, {
|
|
323
|
-
|
|
324
|
-
|
|
322
|
+
isClose: true,
|
|
323
|
+
points,
|
|
324
|
+
tool: RECTANGLE,
|
|
325
|
+
region: pointsToRegion(points),
|
|
325
326
|
})) {
|
|
326
|
-
const
|
|
327
|
-
x:
|
|
328
|
-
y:
|
|
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,
|
|
329
330
|
};
|
|
330
|
-
|
|
331
|
-
x: region.x + region.width,
|
|
332
|
-
y: region.y + region.height,
|
|
333
|
-
};
|
|
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(
|
|
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
|
|
390
|
-
const startPoint =
|
|
391
|
-
|
|
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
|
-
|
|
401
|
-
|
|
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
|
-
|
|
394
|
+
points[0] = {x: startPoint.x + distX, y: startPoint.y + distY};
|
|
405
395
|
}
|
|
406
396
|
if (position === 7) {
|
|
407
|
-
|
|
397
|
+
points[1] = {x: endPoint.x + distX, y: endPoint.y + distY};
|
|
408
398
|
}
|
|
409
399
|
} else if (REGION_TYPES.includes(tool)) {
|
|
410
|
-
const pointList =
|
|
400
|
+
const pointList = getRectPointV2(points);
|
|
411
401
|
switch (position) {
|
|
412
402
|
case 0:
|
|
413
|
-
|
|
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
|
-
|
|
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
|
-
|
|
420
|
-
|
|
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
|
-
|
|
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
|
-
|
|
427
|
-
|
|
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
|
-
|
|
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
|
-
|
|
434
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
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
|
-
|
|
531
|
-
|
|
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
|
-
|
|
536
|
-
|
|
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
|
-
|
|
545
|
-
|
|
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
|
-
|
|
551
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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,57 +660,52 @@ export class Area extends ViewerCommon {
|
|
|
678
660
|
|
|
679
661
|
showLabelMeasure() {
|
|
680
662
|
const bounds = this.viewport.viewportToImageRectangle(
|
|
681
|
-
this.viewport.
|
|
682
|
-
const currentScale = this.getImageZoom(true);
|
|
683
|
-
|
|
684
|
-
const label = this.labelList.find((item) => item.select);
|
|
685
|
-
if (!label) return;
|
|
663
|
+
this.viewport.getBoundsNoRotate());
|
|
664
|
+
const currentScale = this.getImageZoom(true) * this.options.scale;
|
|
665
|
+
this.labelList.forEach((label) => {
|
|
686
666
|
if (label.show === false) return;
|
|
667
|
+
if (!this.isInCanvas(label.region, bounds)) return;
|
|
668
|
+
this.labelDrawingFunc(label);
|
|
687
669
|
if (label.measure === false) return;
|
|
688
|
-
|
|
689
|
-
this.
|
|
690
|
-
|
|
691
|
-
this.
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
this.options.labelDrawing;
|
|
705
|
-
drawingFunc(this.canvas, label,
|
|
706
|
-
this.imageToViewerElementRectangle(label.region));
|
|
707
|
-
}
|
|
708
|
-
});
|
|
670
|
+
if (label.select) {
|
|
671
|
+
this[label.tool].drawMeasureInfo.call(this, label,
|
|
672
|
+
this.getMeasureContent(label));
|
|
673
|
+
} else if (currentScale >= this.options.measure.scale && this.options.measure.defaultShow) {
|
|
674
|
+
this[label.tool].drawMeasureInfo.call(this, label,
|
|
675
|
+
this.getMeasureContent(label));
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
labelDrawingFunc(label) {
|
|
681
|
+
if (this.options.labelDrawing || this.options.label?.drawing) {
|
|
682
|
+
const drawingFunc = this.options.label?.drawing ||
|
|
683
|
+
this.options.labelDrawing;
|
|
684
|
+
drawingFunc(this.canvas, label,
|
|
685
|
+
this.imageToViewerElementRectangle(label.region));
|
|
709
686
|
}
|
|
710
687
|
}
|
|
711
688
|
|
|
712
689
|
/**
|
|
713
690
|
* 设置可移动点,两端点相距30px以上认为是可移动点
|
|
714
691
|
* @param {object} label
|
|
692
|
+
* @param {array} points
|
|
715
693
|
* @return {{}[]}
|
|
716
694
|
*/
|
|
717
|
-
setPointsMove(label) {
|
|
718
|
-
|
|
719
|
-
let lastPoint = movePoints[0];
|
|
695
|
+
setPointsMove(label, points) {
|
|
696
|
+
let lastPoint = points[0];
|
|
720
697
|
const dist = this.options.label?.polygonWidth || 30;
|
|
721
|
-
|
|
698
|
+
points.forEach((point, index) => {
|
|
722
699
|
point.canMove = false;
|
|
723
700
|
label.points[index].canMove = false;
|
|
724
701
|
if (index === 0 || (!pointInOtherPoint(lastPoint, point, dist) &&
|
|
725
|
-
!pointInOtherPoint(
|
|
726
|
-
(index ===
|
|
702
|
+
!pointInOtherPoint(points[0], point, dist)) ||
|
|
703
|
+
(index === points.length - 1)) {
|
|
727
704
|
lastPoint = point;
|
|
728
705
|
point.canMove = true;
|
|
729
706
|
label.points[index].canMove = true;
|
|
730
707
|
}
|
|
731
708
|
});
|
|
732
|
-
return
|
|
709
|
+
return points;
|
|
733
710
|
}
|
|
734
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 (
|
|
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 (
|
|
178
|
-
const
|
|
179
|
-
|
|
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 (
|
|
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,
|