kfb-view 2.2.8 → 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/.idea/workspace.xml +100 -85
- package/example/index.js +18 -9
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/area/index.js +116 -3
- package/src/components/board/index.js +4 -1
- package/src/components/common/common.js +4 -3
- package/src/tool/Brush.js +3 -0
- package/src/view.js +10 -0
package/package.json
CHANGED
|
@@ -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);
|
|
@@ -517,6 +604,7 @@ export class Area extends ViewerCommon {
|
|
|
517
604
|
*/
|
|
518
605
|
change() {
|
|
519
606
|
this.clearCanvas();
|
|
607
|
+
this.showLabelMeasure();
|
|
520
608
|
const label = this.labelList.find((item) => item.select);
|
|
521
609
|
if (!label) return;
|
|
522
610
|
if (label.show === false) return;
|
|
@@ -572,9 +660,34 @@ export class Area extends ViewerCommon {
|
|
|
572
660
|
}
|
|
573
661
|
}
|
|
574
662
|
this[label.tool].setContent(this.canvas, {...label});
|
|
575
|
-
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
showLabelMeasure() {
|
|
666
|
+
const bounds = this.viewport.getBounds();
|
|
667
|
+
const currentScale = this.getImageZoom(true);
|
|
668
|
+
if (currentScale * this.options.scale < this.options.measure.scale) {
|
|
669
|
+
const label = this.labelList.find((item) => item.select);
|
|
670
|
+
if (!label) return;
|
|
671
|
+
if (label.show === false) return;
|
|
672
|
+
if (label.measure === false) return;
|
|
576
673
|
this[label.tool].drawMeasureInfo.call(this, label,
|
|
577
|
-
this.getMeasureContent(label)
|
|
674
|
+
this.getMeasureContent(label));
|
|
675
|
+
} else {
|
|
676
|
+
this.labelList.forEach((label) => {
|
|
677
|
+
if (label.show === false) return;
|
|
678
|
+
if (label.measure === false) return;
|
|
679
|
+
const content = this.getMeasureContent(label);
|
|
680
|
+
if (label.select) {
|
|
681
|
+
this[label.tool].drawMeasureInfo.call(this, label, content);
|
|
682
|
+
} else if (this.options.measure.defaultShow) {
|
|
683
|
+
if (!this.isInCanvas(label.region, bounds)) return false;
|
|
684
|
+
this[label.tool].drawMeasureInfo.call(this, label, content);
|
|
685
|
+
}
|
|
686
|
+
if (this.options.labelDrawing) {
|
|
687
|
+
this.options.labelDrawing(this.canvas, label,
|
|
688
|
+
this.imageToViewerElementRectangle(label.region));
|
|
689
|
+
}
|
|
690
|
+
});
|
|
578
691
|
}
|
|
579
692
|
}
|
|
580
693
|
|
|
@@ -383,7 +383,10 @@ export class Board extends ViewerCommon {
|
|
|
383
383
|
});
|
|
384
384
|
if (form.measure) {
|
|
385
385
|
this[this.tool].drawMeasureInfo.call(this, form,
|
|
386
|
-
this.getMeasureContent(
|
|
386
|
+
this.getMeasureContent({
|
|
387
|
+
...form,
|
|
388
|
+
select: true,
|
|
389
|
+
}));
|
|
387
390
|
}
|
|
388
391
|
return form;
|
|
389
392
|
}
|
|
@@ -314,11 +314,12 @@ export class ViewerCommon extends EventEmitter {
|
|
|
314
314
|
}
|
|
315
315
|
break;
|
|
316
316
|
}
|
|
317
|
+
const handler = label.select ?
|
|
318
|
+
(this.options.measure.selectHandler || this.options.measure.handler) :
|
|
319
|
+
this.options.measure.handler;
|
|
317
320
|
return {
|
|
318
321
|
...content,
|
|
319
|
-
texts:
|
|
320
|
-
this.options.measure.handler(content.texts, label) :
|
|
321
|
-
content.texts,
|
|
322
|
+
texts: handler ? handler(content.texts, label) : content.texts,
|
|
322
323
|
};
|
|
323
324
|
}
|
|
324
325
|
|
package/src/tool/Brush.js
CHANGED
package/src/view.js
CHANGED
|
@@ -66,9 +66,13 @@ export default class KfbView extends EventEmitter {
|
|
|
66
66
|
* @param {boolean=} config.grid.show 是否显示网格线
|
|
67
67
|
* @param {boolean=} config.grid.ruler 是否启用标尺
|
|
68
68
|
* @param {function=} config.measure.handler 标注信息的回调处理
|
|
69
|
+
* @param {function=} config.measure.selectHandler 标注信息选中时的回调处理
|
|
69
70
|
* @param {boolean=} config.measure.color 标注注释颜色
|
|
70
71
|
* @param {boolean=} config.measure.backgroundColor 标注注释背景色
|
|
71
72
|
* @param {boolean=} config.measure.fontSize 标注注释文字大小
|
|
73
|
+
* @param {boolean=} config.measure.defaultShow 标注是否默认永久显示,false表示只在选中时显示
|
|
74
|
+
* @param {boolean=} config.measure.scale 标注默认永久显示时的倍率,
|
|
75
|
+
* @param {boolean=} config.labelDrawing 标注绘制回调,
|
|
72
76
|
* @param {array} config.labelList 标注列表
|
|
73
77
|
*/
|
|
74
78
|
constructor(config) {
|
|
@@ -272,10 +276,13 @@ function initComponentsOptions(kv, type) {
|
|
|
272
276
|
canvas: createCanvas(kv),
|
|
273
277
|
options: {
|
|
274
278
|
scale: config.scale,
|
|
279
|
+
labelDrawing: config.labelDrawing,
|
|
275
280
|
measure: {
|
|
276
281
|
backgroundColor: 'rgba(0,0,0,.5)',
|
|
277
282
|
color: '#FFF',
|
|
278
283
|
fontSize: 14,
|
|
284
|
+
scale: 10,
|
|
285
|
+
defaultShow: false,
|
|
279
286
|
...(config.measure || {}),
|
|
280
287
|
},
|
|
281
288
|
...config[type],
|
|
@@ -404,6 +411,9 @@ function initEvent(kv) {
|
|
|
404
411
|
new openSeadragon.MouseTracker({
|
|
405
412
|
element: kv.viewer.canvas,
|
|
406
413
|
moveHandler: function(event) {
|
|
414
|
+
if (kv.area?.onCanvasMove) {
|
|
415
|
+
kv.area.onCanvasMove(event.position);
|
|
416
|
+
}
|
|
407
417
|
if (isRightDown && kv.board?.isInDraw) {
|
|
408
418
|
console.log('nonprimary drag');
|
|
409
419
|
let delta = event.position.minus(dragPosition);
|