kfb-view 2.2.7 → 2.2.9
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 +69 -49
- package/example/index.js +17 -4
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/area/index.js +28 -2
- package/src/components/board/index.js +17 -2
- package/src/components/common/common.js +4 -3
- package/src/plugin/openseadragon/openseadragon.js +1 -0
- package/src/tool/Brush.js +4 -1
- package/src/view.js +7 -0
package/package.json
CHANGED
|
@@ -517,6 +517,7 @@ export class Area extends ViewerCommon {
|
|
|
517
517
|
*/
|
|
518
518
|
change() {
|
|
519
519
|
this.clearCanvas();
|
|
520
|
+
this.showLabelMeasure();
|
|
520
521
|
const label = this.labelList.find((item) => item.select);
|
|
521
522
|
if (!label) return;
|
|
522
523
|
if (label.show === false) return;
|
|
@@ -572,9 +573,34 @@ export class Area extends ViewerCommon {
|
|
|
572
573
|
}
|
|
573
574
|
}
|
|
574
575
|
this[label.tool].setContent(this.canvas, {...label});
|
|
575
|
-
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
showLabelMeasure() {
|
|
579
|
+
const bounds = this.viewport.getBounds();
|
|
580
|
+
const currentScale = this.getImageZoom(true);
|
|
581
|
+
if (currentScale * this.options.scale < this.options.measure.scale) {
|
|
582
|
+
const label = this.labelList.find((item) => item.select);
|
|
583
|
+
if (!label) return;
|
|
584
|
+
if (label.show === false) return;
|
|
585
|
+
if (label.measure === false) return;
|
|
576
586
|
this[label.tool].drawMeasureInfo.call(this, label,
|
|
577
|
-
this.getMeasureContent(label)
|
|
587
|
+
this.getMeasureContent(label));
|
|
588
|
+
} else {
|
|
589
|
+
this.labelList.forEach((label) => {
|
|
590
|
+
if (label.show === false) return;
|
|
591
|
+
if (label.measure === false) return;
|
|
592
|
+
const content = this.getMeasureContent(label);
|
|
593
|
+
if (label.select) {
|
|
594
|
+
this[label.tool].drawMeasureInfo.call(this, label, content);
|
|
595
|
+
} else if (this.options.measure.defaultShow) {
|
|
596
|
+
if (!this.isInCanvas(label.region, bounds)) return false;
|
|
597
|
+
this[label.tool].drawMeasureInfo.call(this, label, content);
|
|
598
|
+
}
|
|
599
|
+
if (this.options.labelDrawing) {
|
|
600
|
+
this.options.labelDrawing(this.canvas, label,
|
|
601
|
+
this.imageToViewerElementRectangle(label.region));
|
|
602
|
+
}
|
|
603
|
+
});
|
|
578
604
|
}
|
|
579
605
|
}
|
|
580
606
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
EVENT_IN_PAINTING,
|
|
12
12
|
} from '../../const/event';
|
|
13
13
|
import {
|
|
14
|
+
getAngle,
|
|
14
15
|
getDistance,
|
|
15
16
|
pointInOtherPoint,
|
|
16
17
|
pointsToRegion,
|
|
@@ -344,7 +345,18 @@ export class Board extends ViewerCommon {
|
|
|
344
345
|
if (index === 0) return true;
|
|
345
346
|
if (index === this.points.length - 1) return true;
|
|
346
347
|
if (pointInOtherPoint(firstPoint, _p, 30)) {
|
|
347
|
-
|
|
348
|
+
const nextPoint = points[index + 1];
|
|
349
|
+
if (nextPoint) {
|
|
350
|
+
const deg = Math.abs(getAngle(_p, firstPoint, nextPoint));
|
|
351
|
+
const angle = deg * 180 / Math.PI;
|
|
352
|
+
if (angle < 90) {
|
|
353
|
+
firstPoint = _p;
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
} else {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
348
360
|
} else {
|
|
349
361
|
firstPoint = _p;
|
|
350
362
|
return true;
|
|
@@ -371,7 +383,10 @@ export class Board extends ViewerCommon {
|
|
|
371
383
|
});
|
|
372
384
|
if (form.measure) {
|
|
373
385
|
this[this.tool].drawMeasureInfo.call(this, form,
|
|
374
|
-
this.getMeasureContent(
|
|
386
|
+
this.getMeasureContent({
|
|
387
|
+
...form,
|
|
388
|
+
select: true,
|
|
389
|
+
}));
|
|
375
390
|
}
|
|
376
391
|
return form;
|
|
377
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
|
|
|
@@ -17344,6 +17344,7 @@ function OpenSeadragon(options) {
|
|
|
17344
17344
|
sourceHeight: sourceHeight,
|
|
17345
17345
|
position: position,
|
|
17346
17346
|
size: size,
|
|
17347
|
+
pixelDensityRatio: $.pixelDensityRatio,
|
|
17347
17348
|
});
|
|
17348
17349
|
/* context.drawImage(
|
|
17349
17350
|
rendered.canvas,
|
package/src/tool/Brush.js
CHANGED
|
@@ -69,12 +69,15 @@ class Brush {
|
|
|
69
69
|
*/
|
|
70
70
|
drawMeasureInfo(label, info, scale = 1) {
|
|
71
71
|
const {left, top, texts, angle} = info;
|
|
72
|
+
if (!texts.length) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
72
75
|
const ctx = this.canvas.getContext('2d');
|
|
73
76
|
ctx.save();
|
|
74
77
|
ctx.beginPath();
|
|
75
78
|
ctx.translate(left, top);
|
|
76
79
|
ctx.rotate(angle);
|
|
77
|
-
ctx.scale(scale, scale);
|
|
80
|
+
// ctx.scale(scale, scale);
|
|
78
81
|
const widthList = [];
|
|
79
82
|
ctx.font = `${this.options.measure.fontSize}px Arial`;
|
|
80
83
|
texts.forEach((info) => {
|
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],
|