kfb-view 2.2.3 → 2.2.6
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 +61 -45
- package/example/index.js +9 -4
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/area/index.js +13 -3
- package/src/components/board/index.js +30 -32
- package/src/components/grid/index.js +8 -5
- package/src/components/navigator/index.js +0 -10
- package/src/components/shape/index.js +9 -3
- package/src/const/mark.js +3 -1
- package/src/model/label.model.js +9 -0
- package/src/tool/Brush.js +6 -0
- package/src/tool/Image.js +45 -0
- package/src/tool/Polygon.js +0 -6
- package/src/tool/index.js +1 -0
- package/src/view.js +1 -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,
|
|
9
|
+
STAR, IMAGE,
|
|
10
10
|
} from '../../const/mark';
|
|
11
11
|
import {
|
|
12
12
|
baseNumber, getAngle, getDistance, getPoint,
|
|
@@ -39,6 +39,7 @@ export class Area extends ViewerCommon {
|
|
|
39
39
|
super(viewer, canvas, cache, options);
|
|
40
40
|
this.labelList = [];
|
|
41
41
|
this.movePoint = undefined;
|
|
42
|
+
this.currentPressPoint = undefined;
|
|
42
43
|
this.lastPoint = undefined;
|
|
43
44
|
this.draging = false;
|
|
44
45
|
MARKS.forEach((mark) => {
|
|
@@ -82,12 +83,16 @@ export class Area extends ViewerCommon {
|
|
|
82
83
|
*/
|
|
83
84
|
onCanvasPress({x, y}) {
|
|
84
85
|
this.movePoint = undefined;
|
|
86
|
+
this.currentPressPoint = undefined;
|
|
85
87
|
this.lastPoint = undefined;
|
|
86
88
|
this.draging = false;
|
|
87
89
|
let selectList = [];
|
|
88
90
|
let selectLabel;
|
|
89
91
|
let prevSelectLabel = undefined;
|
|
90
92
|
this.labelList.forEach((item) => {
|
|
93
|
+
if (item.tool === IMAGE) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
91
96
|
if (item.select) {
|
|
92
97
|
prevSelectLabel = item;
|
|
93
98
|
}
|
|
@@ -181,6 +186,7 @@ export class Area extends ViewerCommon {
|
|
|
181
186
|
// moveIndex>-1,表示选中的是图形中可移动的点
|
|
182
187
|
if (~moveIndex) {
|
|
183
188
|
this.movePoint = {position: moveIndex, label: item};
|
|
189
|
+
this.currentPressPoint = {x, y};
|
|
184
190
|
} else if ((item.tool !== POLYGON &&
|
|
185
191
|
isPointInMatrix(pointList[0], pointList[2], pointList[6], pointList[8],
|
|
186
192
|
{x, y})) ||
|
|
@@ -258,10 +264,14 @@ export class Area extends ViewerCommon {
|
|
|
258
264
|
*/
|
|
259
265
|
onCanvasRelease({x, y}) {
|
|
260
266
|
if (this.movePoint && this.options.drag !== false) {
|
|
261
|
-
const
|
|
262
|
-
|
|
267
|
+
const dist = getDistance(this.currentPressPoint, {x, y});
|
|
268
|
+
if (Math.abs(dist) > 1) {
|
|
269
|
+
const label = this.movePoint.label;
|
|
270
|
+
this.$emit(EVENT_AREA_MOVE_END, label);
|
|
271
|
+
}
|
|
263
272
|
}
|
|
264
273
|
this.movePoint = undefined;
|
|
274
|
+
this.currentPressPoint = undefined;
|
|
265
275
|
this.lastPoint = undefined;
|
|
266
276
|
this.draging = false;
|
|
267
277
|
this.change();
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
EVENT_IN_PAINTING,
|
|
12
12
|
} from '../../const/event';
|
|
13
13
|
import {
|
|
14
|
+
getDistance,
|
|
14
15
|
pointInOtherPoint,
|
|
15
16
|
pointsToRegion,
|
|
16
17
|
} from '../../util/calculate';
|
|
@@ -148,13 +149,11 @@ export class Board extends ViewerCommon {
|
|
|
148
149
|
const points = this.imageToViewerElementPoints(this.points);
|
|
149
150
|
this[tool].draw(points);
|
|
150
151
|
this[tool].endDraw();
|
|
151
|
-
|
|
152
|
-
this
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
}
|
|
152
|
+
this[tool].drawPoints(points, {
|
|
153
|
+
radius: this.options.thumb.radius,
|
|
154
|
+
strokeStyle: this.options.thumb.color,
|
|
155
|
+
fillStyle: this.options.thumb.bgColor,
|
|
156
|
+
});
|
|
158
157
|
this.$emit(EVENT_START_PAINTING, this.getPaintOptions());
|
|
159
158
|
}
|
|
160
159
|
|
|
@@ -185,13 +184,11 @@ export class Board extends ViewerCommon {
|
|
|
185
184
|
const points = this.imageToViewerElementPoints(this.points);
|
|
186
185
|
this[tool].draw(points);
|
|
187
186
|
this[tool].endDraw();
|
|
188
|
-
|
|
189
|
-
this
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
}
|
|
187
|
+
this[tool].drawPoints(points, {
|
|
188
|
+
radius: this.options.thumb.radius,
|
|
189
|
+
strokeStyle: this.options.thumb.color,
|
|
190
|
+
fillStyle: this.options.thumb.bgColor,
|
|
191
|
+
});
|
|
195
192
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
196
193
|
}
|
|
197
194
|
|
|
@@ -209,10 +206,15 @@ export class Board extends ViewerCommon {
|
|
|
209
206
|
return;
|
|
210
207
|
}
|
|
211
208
|
const tool = this.tool;
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
if (!NO_NORMAL_REGION_TYPES.includes(tool)) {
|
|
210
|
+
const firstPoint = this.imageToViewerElementCoordinates(this.points[0].x,
|
|
211
|
+
this.points[0].y);
|
|
212
|
+
const dist = getDistance(firstPoint, {x, y});
|
|
213
|
+
if (Math.abs(dist) < 10) {
|
|
214
|
+
this.points = [];
|
|
215
|
+
this.clearCanvas();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
216
218
|
} else if (POINT_TYPES.includes(tool)) {
|
|
217
219
|
this.points = [point, point];
|
|
218
220
|
} else if (tool === POLYGON) {
|
|
@@ -305,13 +307,11 @@ export class Board extends ViewerCommon {
|
|
|
305
307
|
const points = this.imageToViewerElementPoints(this.points);
|
|
306
308
|
this[tool].draw(points);
|
|
307
309
|
this[tool].endDraw();
|
|
308
|
-
|
|
309
|
-
this
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
});
|
|
314
|
-
}
|
|
310
|
+
this[tool].drawPoints(points, {
|
|
311
|
+
radius: this.options.thumb.radius,
|
|
312
|
+
strokeStyle: this.options.thumb.color,
|
|
313
|
+
fillStyle: this.options.thumb.bgColor,
|
|
314
|
+
});
|
|
315
315
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
316
316
|
}
|
|
317
317
|
}
|
|
@@ -422,13 +422,11 @@ export class Board extends ViewerCommon {
|
|
|
422
422
|
this[this.tool].startDraw();
|
|
423
423
|
this[this.tool].draw(points);
|
|
424
424
|
this[this.tool].endDraw();
|
|
425
|
-
|
|
426
|
-
this
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
});
|
|
431
|
-
}
|
|
425
|
+
this[this.tool].drawPoints(points, {
|
|
426
|
+
radius: this.options.thumb.radius,
|
|
427
|
+
strokeStyle: this.options.thumb.color,
|
|
428
|
+
fillStyle: this.options.thumb.bgColor,
|
|
429
|
+
});
|
|
432
430
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
433
431
|
}
|
|
434
432
|
}
|
|
@@ -72,11 +72,13 @@ export class Grid extends ViewerCommon {
|
|
|
72
72
|
const basePx = this.imageToViewerElementCoordinates(baseScale, 0).
|
|
73
73
|
minus(this.imageToViewerElementCoordinates(0, 0)).x;
|
|
74
74
|
ctx.beginPath();
|
|
75
|
-
ctx.strokeStyle = 'rgba(0, 0, 0, .8)';
|
|
76
|
-
ctx.fillStyle = 'rgba(0, 0, 0, .3)';
|
|
77
75
|
ctx.font = '14px Arial';
|
|
78
|
-
ctx.
|
|
79
|
-
ctx.
|
|
76
|
+
ctx.fillStyle = '#fff';
|
|
77
|
+
ctx.fillRect(0, 0, 20, this.canvas.height);
|
|
78
|
+
ctx.fillRect(0, 0, this.canvas.width, 20);
|
|
79
|
+
ctx.beginPath();
|
|
80
|
+
ctx.fillStyle = 'rgba(0, 0, 0, .3)';
|
|
81
|
+
ctx.strokeStyle = 'rgba(0, 0, 0, .8)';
|
|
80
82
|
ctx.moveTo(20, 20);
|
|
81
83
|
ctx.lineTo(20, this.canvas.height);
|
|
82
84
|
ctx.moveTo(20, 20);
|
|
@@ -111,7 +113,8 @@ export class Grid extends ViewerCommon {
|
|
|
111
113
|
}
|
|
112
114
|
ctx.stroke();
|
|
113
115
|
ctx.beginPath();
|
|
114
|
-
ctx.
|
|
116
|
+
ctx.fillStyle = '#fff';
|
|
117
|
+
ctx.fillRect(0, 0, 20, 20);
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
}
|
|
@@ -381,14 +381,4 @@ export class Navigator extends EventEmitter {
|
|
|
381
381
|
};
|
|
382
382
|
img.src = this.options.thumbnail; // 设置图片源地
|
|
383
383
|
}
|
|
384
|
-
|
|
385
|
-
toggleNavigator() {
|
|
386
|
-
const navigatorMain = this.element.getElementsByClassName(
|
|
387
|
-
'navigator-main')[0];
|
|
388
|
-
if (navigatorMain.style.display === 'none') {
|
|
389
|
-
navigatorMain.style.display = 'block';
|
|
390
|
-
} else {
|
|
391
|
-
navigatorMain.style.display = 'none';
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
384
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
HAS_REGION_TYPES,
|
|
2
|
+
HAS_REGION_TYPES, IMAGE,
|
|
3
3
|
MARKS, NO_NORMAL_REGION_TYPES, POINT_TYPES, POLYGON, REGION_TYPES,
|
|
4
4
|
} from '../../const/mark';
|
|
5
5
|
import {ViewerCommon} from '../common/common';
|
|
6
6
|
import * as Tools from '../../tool';
|
|
7
7
|
import {Combination} from '../../tool/Combination';
|
|
8
|
-
import {EVENT_CANCEL_SELECT_LABEL} from '../../const/event';
|
|
9
|
-
import * as EVENTS from '../../const/event';
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* 用来显示标注线的canvas
|
|
@@ -70,7 +68,12 @@ export class Shape extends ViewerCommon {
|
|
|
70
68
|
// strokeStyle, lineWidth, fillStyle 相同认为是一个路径下的图形,一起绘制,优化性能
|
|
71
69
|
const sameFixWidthLabel = {}; // star, flag, star, font lineWidth固定为2
|
|
72
70
|
const sameNormalLabel = {};
|
|
71
|
+
const imageLabel = [];
|
|
73
72
|
labelList.forEach((item) => {
|
|
73
|
+
if (item.tool === IMAGE) {
|
|
74
|
+
imageLabel.push(item);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
74
77
|
const key = `${item.strokeStyle ?? ''}_${item.lineWidth ??
|
|
75
78
|
''}_${item.fillStyle ?? ''}`;
|
|
76
79
|
const regionKey = `${item.strokeStyle ?? ''}_${item.lineWidth ?? ''}`;
|
|
@@ -111,6 +114,9 @@ export class Shape extends ViewerCommon {
|
|
|
111
114
|
tool,
|
|
112
115
|
})), this.viewport.getRotation());
|
|
113
116
|
});
|
|
117
|
+
imageLabel.forEach((item) => {
|
|
118
|
+
this.drawLabel(item);
|
|
119
|
+
});
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
deepDrawLabel(sameFixWidthLabel, sameNormalLabel, count, bounds) {
|
package/src/const/mark.js
CHANGED
|
@@ -8,6 +8,7 @@ export const FONT = 'Font';
|
|
|
8
8
|
export const STAR = 'Star';
|
|
9
9
|
export const FLAG = 'Flag';
|
|
10
10
|
export const DOT = 'Dot';
|
|
11
|
+
export const IMAGE = 'Image';
|
|
11
12
|
|
|
12
13
|
export const POINT_TYPES = [FONT, STAR, FLAG, DOT];
|
|
13
14
|
export const REGION_TYPES = [RECTANGLE, ELLIPSE];
|
|
@@ -24,4 +25,5 @@ export const MARKS = [
|
|
|
24
25
|
FONT,
|
|
25
26
|
STAR,
|
|
26
27
|
FLAG,
|
|
27
|
-
DOT
|
|
28
|
+
DOT,
|
|
29
|
+
IMAGE];
|
package/src/model/label.model.js
CHANGED
|
@@ -17,6 +17,7 @@ export class LabelModel {
|
|
|
17
17
|
this.measure = data.measure; // 是否显示测量信息
|
|
18
18
|
this.points = data.points; // 绘制点
|
|
19
19
|
this.tool = data.tool; // 绘制工具
|
|
20
|
+
this.src = data.src; // 图片地址
|
|
20
21
|
this.scale = data.scale; // 绘制倍率
|
|
21
22
|
this.region = data.region; // 绘制区域
|
|
22
23
|
this.move = data.move; // 是否可移动
|
|
@@ -27,5 +28,13 @@ export class LabelModel {
|
|
|
27
28
|
this.show = data.show ?? true; // 是否显示
|
|
28
29
|
this.__other__ = data.__other__ || {}; // 其他信息
|
|
29
30
|
this.__data__ = data.__data__ ?? data; // 记录原始数据
|
|
31
|
+
if (this.src) {
|
|
32
|
+
this.img = new Image();
|
|
33
|
+
this.img.src = this.src;
|
|
34
|
+
this.imgLoadSuccess = false;
|
|
35
|
+
this.img.onload = () => {
|
|
36
|
+
this.imgLoadSuccess = true;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
}
|
package/src/tool/Brush.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {Brush} from './Brush';
|
|
2
|
+
import {pointsToRegion} from '../util/calculate';
|
|
3
|
+
import {EventEmitter} from '../util/event-emitter';
|
|
4
|
+
|
|
5
|
+
const et = new EventEmitter();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 线段类
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
class Image extends Brush {
|
|
12
|
+
/**
|
|
13
|
+
* 初始化数据
|
|
14
|
+
*/
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 画线
|
|
21
|
+
* @param {Object[]} points - 绘制的点
|
|
22
|
+
* @param {number} points[].x - 绘制的点x坐标
|
|
23
|
+
* @param {number} points[].y - 绘制的点y坐标
|
|
24
|
+
* @param {number=} scale
|
|
25
|
+
*/
|
|
26
|
+
draw(points, scale = 1) {
|
|
27
|
+
const region = pointsToRegion(points);
|
|
28
|
+
if (this.options.imgLoadSuccess) {
|
|
29
|
+
this.drawImage(this.options.img, region);
|
|
30
|
+
} else if (this.options.img) {
|
|
31
|
+
et.$once('load', () => {
|
|
32
|
+
this.drawImage(this.options.img, region);
|
|
33
|
+
}, true, this.options.img);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
drawImage(img, region) {
|
|
38
|
+
const ctx = this.canvas.getContext('2d');
|
|
39
|
+
ctx.drawImage(img, region.x, region.y, region.width, region.height);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
Image,
|
|
45
|
+
};
|
package/src/tool/Polygon.js
CHANGED
package/src/tool/index.js
CHANGED