kfb-view 2.2.0 → 2.2.1
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 +43 -43
- package/example/index.js +5 -4
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/common/common.js +12 -22
- package/src/components/shape/index.js +8 -4
package/package.json
CHANGED
|
@@ -387,30 +387,20 @@ export class ViewerCommon extends EventEmitter {
|
|
|
387
387
|
/**
|
|
388
388
|
* 判断region是否在canvas中
|
|
389
389
|
* @param {Object} region
|
|
390
|
-
* @param {
|
|
390
|
+
* @param {Object} bounds
|
|
391
391
|
* @return {boolean}
|
|
392
392
|
*/
|
|
393
|
-
isInCanvas(region,
|
|
394
|
-
const
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const endPoint =
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
endPoint.x = x;
|
|
405
|
-
}
|
|
406
|
-
if (endPoint.y < startPoint.y) {
|
|
407
|
-
const y = startPoint.y;
|
|
408
|
-
startPoint.y = endPoint.y;
|
|
409
|
-
endPoint.y = y;
|
|
410
|
-
}
|
|
411
|
-
return !(startPoint.x > this.canvas.width ||
|
|
412
|
-
startPoint.y > this.canvas.height ||
|
|
413
|
-
endPoint.x < 0 || endPoint.y < 0);
|
|
393
|
+
isInCanvas(region, bounds) {
|
|
394
|
+
const viewReact = this.viewport.imageToViewportRectangle(region.x, region.y,
|
|
395
|
+
region.width, region.height);
|
|
396
|
+
const startPoint = {x: viewReact.x, y: viewReact.y};
|
|
397
|
+
const endPoint = {
|
|
398
|
+
x: viewReact.x + viewReact.width,
|
|
399
|
+
y: viewReact.y + viewReact.height,
|
|
400
|
+
};
|
|
401
|
+
return !(startPoint.x > (bounds.x + bounds.width) || startPoint.y >
|
|
402
|
+
(bounds.y + bounds.height) || endPoint.x < bounds.x || endPoint.y <
|
|
403
|
+
bounds.y);
|
|
414
404
|
}
|
|
415
405
|
|
|
416
406
|
getFontWidth(text, size) {
|
|
@@ -51,12 +51,12 @@ export class Shape extends ViewerCommon {
|
|
|
51
51
|
*/
|
|
52
52
|
change() {
|
|
53
53
|
this.clearCanvas();
|
|
54
|
+
const bounds = this.viewport.getBounds();
|
|
54
55
|
// 区域标注列表
|
|
55
56
|
const regionLabelList = [];
|
|
56
57
|
const labelList = this.labelList.filter((item) => {
|
|
57
58
|
if (item.show === false) return false;
|
|
58
59
|
if (!this[item.tool]) return false;
|
|
59
|
-
if (!this.isInCanvas(item.region)) return false;
|
|
60
60
|
if (REGION_TYPES.includes(item.tool) || item.isClose && item.tool ===
|
|
61
61
|
POLYGON && item.fillStyle) {
|
|
62
62
|
regionLabelList.push({
|
|
@@ -99,8 +99,9 @@ export class Shape extends ViewerCommon {
|
|
|
99
99
|
clearTimeout(this.delaytimer);
|
|
100
100
|
this.delaytimer = undefined;
|
|
101
101
|
}
|
|
102
|
-
this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, 1);
|
|
102
|
+
this.deepDrawLabel(sameFixWidthLabel, sameNormalLabel, 1, bounds);
|
|
103
103
|
regionLabelList.forEach((item) => {
|
|
104
|
+
if (!this.isInCanvas(item.region, bounds)) return false;
|
|
104
105
|
this.combination.setContent(this.canvas, item);
|
|
105
106
|
this.combination.draw({
|
|
106
107
|
points: this.imageToViewerElementPoints(item.points),
|
|
@@ -112,7 +113,7 @@ export class Shape extends ViewerCommon {
|
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
deepDrawLabel(sameFixWidthLabel, sameNormalLabel, count) {
|
|
116
|
+
deepDrawLabel(sameFixWidthLabel, sameNormalLabel, count, bounds) {
|
|
116
117
|
let currentDrawCount = 0; // 当前已绘制数量
|
|
117
118
|
const ctx = this.canvas.getContext('2d');
|
|
118
119
|
const remainFixLabel = {};
|
|
@@ -127,6 +128,7 @@ export class Shape extends ViewerCommon {
|
|
|
127
128
|
remainFixLabel[key] = [item];
|
|
128
129
|
}
|
|
129
130
|
} else {
|
|
131
|
+
if (!this.isInCanvas(item.region, bounds)) return false;
|
|
130
132
|
this.drawLabel(item);
|
|
131
133
|
}
|
|
132
134
|
currentDrawCount++;
|
|
@@ -151,6 +153,7 @@ export class Shape extends ViewerCommon {
|
|
|
151
153
|
remainNormalLabel[key] = [item];
|
|
152
154
|
}
|
|
153
155
|
} else {
|
|
156
|
+
if (!this.isInCanvas(item.region, bounds)) return false;
|
|
154
157
|
this.drawLabel(item);
|
|
155
158
|
}
|
|
156
159
|
currentDrawCount++;
|
|
@@ -166,7 +169,8 @@ export class Shape extends ViewerCommon {
|
|
|
166
169
|
this.delaytimer = undefined;
|
|
167
170
|
} else {
|
|
168
171
|
this.delaytimer = setTimeout(() => {
|
|
169
|
-
this.deepDrawLabel(remainFixLabel, remainNormalLabel, count + 1
|
|
172
|
+
this.deepDrawLabel(remainFixLabel, remainNormalLabel, count + 1,
|
|
173
|
+
bounds);
|
|
170
174
|
}, 100);
|
|
171
175
|
}
|
|
172
176
|
}
|