kfb-view 2.2.0 → 2.2.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "2.2.0",
4
+ "version": "2.2.3",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -563,7 +563,7 @@ export class Area extends ViewerCommon {
563
563
  }
564
564
  this[label.tool].setContent(this.canvas, {...label});
565
565
  if (label.measure && label.select) {
566
- this[label.tool].drawMeasureInfo(label,
566
+ this[label.tool].drawMeasureInfo.call(this, label,
567
567
  this.getMeasureContent(label), scale);
568
568
  }
569
569
  }
@@ -370,7 +370,7 @@ export class Board extends ViewerCommon {
370
370
  tool: this.tool,
371
371
  });
372
372
  if (form.measure) {
373
- this[this.tool].drawMeasureInfo(form,
373
+ this[this.tool].drawMeasureInfo.call(this, form,
374
374
  this.getMeasureContent(form));
375
375
  }
376
376
  return form;
@@ -185,7 +185,7 @@ export class ViewerCommon extends EventEmitter {
185
185
  left: 0,
186
186
  top: 0,
187
187
  angle: 0,
188
- content: [],
188
+ texts: [],
189
189
  };
190
190
  if (label.points.length <= 1) return content;
191
191
  const scale = this.getImageZoom(true) / label.scale;
@@ -230,7 +230,7 @@ export class ViewerCommon extends EventEmitter {
230
230
  left: p.x + distX * scale,
231
231
  top: p.y + distY * scale,
232
232
  angle: deg,
233
- content: [
233
+ texts: [
234
234
  `长:${(Math.sqrt(w * w + h * h) * this.options.imageCapRes).toFixed(
235
235
  2)}${this.options.unit}`],
236
236
  };
@@ -250,7 +250,7 @@ export class ViewerCommon extends EventEmitter {
250
250
  left: p.x + 10 * scale,
251
251
  top: p.y,
252
252
  angle: 0,
253
- content: [
253
+ texts: [
254
254
  `长轴:${(w * this.options.imageCapRes).toFixed(
255
255
  2)}${this.options.unit}`,
256
256
  `短轴:${(h * this.options.imageCapRes).toFixed(
@@ -274,7 +274,7 @@ export class ViewerCommon extends EventEmitter {
274
274
  left: p.x + 10 * scale,
275
275
  top: p.y,
276
276
  angle: 0,
277
- content: [
277
+ texts: [
278
278
  `长:${(w * this.options.imageCapRes).toFixed(
279
279
  2)}${this.options.unit}`,
280
280
  `宽:${(h * this.options.imageCapRes).toFixed(
@@ -298,7 +298,7 @@ export class ViewerCommon extends EventEmitter {
298
298
  left: p.x,
299
299
  top: p.y,
300
300
  angle: 0,
301
- content: [
301
+ texts: [
302
302
  `周长:${(pt * this.options.imageCapRes).toFixed(
303
303
  2)}${this.options.unit}`],
304
304
  };
@@ -309,12 +309,17 @@ export class ViewerCommon extends EventEmitter {
309
309
  left: 0,
310
310
  right: 0,
311
311
  angle: 0,
312
- content: [],
312
+ texts: [],
313
313
  };
314
314
  }
315
315
  break;
316
316
  }
317
- return content;
317
+ return {
318
+ ...content,
319
+ texts: this.options.measure.handler ?
320
+ this.options.measure.handler(content.texts, label) :
321
+ content.texts,
322
+ };
318
323
  }
319
324
 
320
325
  /**
@@ -387,30 +392,20 @@ export class ViewerCommon extends EventEmitter {
387
392
  /**
388
393
  * 判断region是否在canvas中
389
394
  * @param {Object} region
390
- * @param {boolean} status
395
+ * @param {Object} bounds
391
396
  * @return {boolean}
392
397
  */
393
- isInCanvas(region, status = false) {
394
- const startPoint = status ?
395
- {x: region.x, y: region.y} :
396
- this.imageToViewerElementCoordinates(region.x, region.y);
397
- const endPoint = status ?
398
- {x: region.x + region.width, y: region.y + region.height} :
399
- this.imageToViewerElementCoordinates(
400
- region.x + region.width, region.y + region.height);
401
- if (endPoint.x < startPoint.x) {
402
- const x = startPoint.x;
403
- startPoint.x = endPoint.x;
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);
398
+ isInCanvas(region, bounds) {
399
+ const viewReact = this.viewport.imageToViewportRectangle(region.x, region.y,
400
+ region.width, region.height);
401
+ const startPoint = {x: viewReact.x, y: viewReact.y};
402
+ const endPoint = {
403
+ x: viewReact.x + viewReact.width,
404
+ y: viewReact.y + viewReact.height,
405
+ };
406
+ return !(startPoint.x > (bounds.x + bounds.width) || startPoint.y >
407
+ (bounds.y + bounds.height) || endPoint.x < bounds.x || endPoint.y <
408
+ bounds.y);
414
409
  }
415
410
 
416
411
  getFontWidth(text, size) {
@@ -427,6 +422,18 @@ export class ViewerCommon extends EventEmitter {
427
422
 
428
423
  }
429
424
 
425
+ /**
426
+ * updated
427
+ * @param {Object=} options
428
+ */
429
+ updated(options = {}) {
430
+ this.options = {
431
+ ...this.options,
432
+ ...options,
433
+ };
434
+ this.change();
435
+ }
436
+
430
437
  /**
431
438
  * 清除canvas
432
439
  */
@@ -14,28 +14,16 @@ export class Graduation extends ViewerCommon {
14
14
  */
15
15
  constructor({viewer, canvas, cache, options}) {
16
16
  super(viewer, canvas, cache, options);
17
- this.scales = options.scales || [0.2, 0.5, 0.8, 1, 2, 4, 10, 20, 40, 100];
17
+ this.scales = options.scales ||
18
+ [0.1, 0.4, 0.6, 1, 2, 4, 8, 10, 20, 40, 60, 100, 140, 200];
18
19
  this.microns = options.microns ||
19
- [5000, 2000, 1250, 1000, 500, 250, 100, 50, 25, 10];
20
- this.init();
21
- }
22
-
23
- /**
24
- * 初始化函数
25
- */
26
- init() {
27
- this.viewer.addHandler('animation', (res) => {
28
- this.changeZoom();
29
- });
30
- setTimeout(() => {
31
- this.changeZoom();
32
- }, 100);
20
+ [5000, 2000, 1250, 1000, 500, 250, 200, 100, 50, 25, 20, 10, 5, 2];
33
21
  }
34
22
 
35
23
  /**
36
24
  * 倍率大小改变
37
25
  */
38
- changeZoom() {
26
+ change() {
39
27
  const scales = [...this.scales];
40
28
  const zoom = this.viewport.viewportToImageZoom(
41
29
  this.viewport.getZoom(true)) * 40;
@@ -71,6 +59,9 @@ export class Graduation extends ViewerCommon {
71
59
  const height = this.canvas.height;
72
60
  ctx.beginPath();
73
61
  ctx.clearRect(0, 0, width, height);
62
+ if (!this.options.show) {
63
+ return;
64
+ }
74
65
  const {left, top, right, bottom} = this.options;
75
66
  let x = 10;
76
67
  let y = height - 10;
@@ -85,17 +76,18 @@ export class Graduation extends ViewerCommon {
85
76
  y = height - bottom;
86
77
  }
87
78
  ctx.beginPath();
88
- ctx.strokeStyle = '#454545';
89
- ctx.lineWidth = 2;
90
- ctx.moveTo(x, y - 5);
79
+ ctx.strokeStyle = '#000000';
80
+ ctx.lineWidth = 3;
81
+ ctx.moveTo(x, y - 8);
91
82
  ctx.lineTo(x, y);
92
83
  ctx.lineTo(x + lineWidth, y);
93
- ctx.lineTo(x + lineWidth, y - 5);
84
+ ctx.lineTo(x + lineWidth, y - 8);
94
85
  ctx.stroke();
95
86
  ctx.beginPath();
96
- ctx.fillStyle = '#454545';
87
+ ctx.fillStyle = '#000000';
88
+ ctx.font = 'bold 16px Arial';
97
89
  const t = txt.toFixed(0) + this.options.unit;
98
90
  const fontWidth = ctx.measureText(t).width;
99
- ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 10 : y - 10);
91
+ ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 12 : y - 12);
100
92
  }
101
93
  }
@@ -0,0 +1,117 @@
1
+ import {ViewerCommon} from '../common/common';
2
+
3
+ /**
4
+ * 网格
5
+ * @class
6
+ */
7
+ export class Grid extends ViewerCommon {
8
+ /**
9
+ * 初始化视图测量工具
10
+ * @param {Object} viewer
11
+ * @param {Object} canvas
12
+ * @param {Object} cache
13
+ * @param {Object} options
14
+ */
15
+ constructor({viewer, canvas, cache, options}) {
16
+ super(viewer, canvas, cache, options);
17
+ if (!this.options.scale) {
18
+ this.options.scale = 20;
19
+ }
20
+ }
21
+
22
+ change() {
23
+ const imageViewStartPoint = this.viewerElementToImageCoordinates(0, 0);
24
+ const imageViewXEndPoint = this.viewerElementToImageCoordinates(
25
+ this.canvas.width, 0);
26
+ const imageViewYEndPoint = this.viewerElementToImageCoordinates(0,
27
+ this.canvas.height);
28
+ let currentZoom = this.getImageZoom(true) * this.options.scale;
29
+ let baseScale = this.options.scale === 40 ? 3200 : 1600;
30
+ let twoCount = 0;
31
+ if (currentZoom >= 1) {
32
+ while (currentZoom / 2 >= 1) {
33
+ twoCount++;
34
+ currentZoom = currentZoom / 2;
35
+ }
36
+ if (twoCount) {
37
+ baseScale /= Math.pow(2, twoCount);
38
+ }
39
+ } else if (currentZoom < 1) {
40
+ while (currentZoom * 2 <= 1) {
41
+ twoCount++;
42
+ currentZoom = currentZoom * 2;
43
+ }
44
+ if (twoCount) {
45
+ baseScale *= Math.pow(2, twoCount);
46
+ }
47
+ }
48
+ const distX = imageViewXEndPoint.distanceTo(imageViewStartPoint);
49
+ const distY = imageViewYEndPoint.distanceTo(imageViewStartPoint);
50
+ const minX = Math.floor(imageViewStartPoint.x / baseScale);
51
+ const maxX = Math.floor((imageViewXEndPoint.x + distX) / baseScale);
52
+ const minY = Math.floor(imageViewStartPoint.y / baseScale);
53
+ const maxY = Math.floor((imageViewYEndPoint.y + distY) / baseScale);
54
+ const ctx = this.canvas.getContext('2d');
55
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
56
+ if (this.options.show) {
57
+ ctx.beginPath();
58
+ ctx.lineWidth = 1;
59
+ for (let i = minX; i <= maxX + 1; i++) {
60
+ const point = this.imageToViewerElementCoordinates(i * baseScale, 0);
61
+ ctx.moveTo(point.x, 0);
62
+ ctx.lineTo(point.x, this.canvas.height);
63
+ }
64
+ for (let i = minY; i <= maxY + 1; i++) {
65
+ const point = this.imageToViewerElementCoordinates(0, i * baseScale);
66
+ ctx.moveTo(0, point.y);
67
+ ctx.lineTo(this.canvas.width, point.y);
68
+ }
69
+ ctx.stroke();
70
+ }
71
+ if (this.options.ruler) {
72
+ const basePx = this.imageToViewerElementCoordinates(baseScale, 0).
73
+ minus(this.imageToViewerElementCoordinates(0, 0)).x;
74
+ ctx.beginPath();
75
+ ctx.strokeStyle = 'rgba(0, 0, 0, .8)';
76
+ ctx.fillStyle = 'rgba(0, 0, 0, .3)';
77
+ ctx.font = '14px Arial';
78
+ ctx.clearRect(0, 0, 20, this.canvas.height);
79
+ ctx.clearRect(0, 0, this.canvas.width, 20);
80
+ ctx.moveTo(20, 20);
81
+ ctx.lineTo(20, this.canvas.height);
82
+ ctx.moveTo(20, 20);
83
+ ctx.lineTo(this.canvas.width, 20);
84
+ for (let i = minX; i <= maxX + 1; i++) {
85
+ const point = this.imageToViewerElementCoordinates(i * baseScale, 0);
86
+ ctx.moveTo(point.x, 0);
87
+ ctx.lineTo(point.x, 20);
88
+ for (let j = 1; j < 5; j++) {
89
+ ctx.moveTo(point.x + (basePx / 5) * j, 16);
90
+ ctx.lineTo(point.x + (basePx / 5) * j, 20);
91
+ if (i !== minX) {
92
+ ctx.fillText(i * baseScale, point.x + 5, 13);
93
+ }
94
+ }
95
+ }
96
+ for (let i = minY; i <= maxY + 1; i++) {
97
+ const point = this.imageToViewerElementCoordinates(0, i * baseScale);
98
+ ctx.moveTo(0, point.y);
99
+ ctx.lineTo(20, point.y);
100
+ for (let j = 1; j < 5; j++) {
101
+ ctx.moveTo(16, point.y + (basePx / 5) * j);
102
+ ctx.lineTo(20, point.y + (basePx / 5) * j);
103
+ if (i !== minY) {
104
+ ctx.save();
105
+ ctx.translate(3, point.y + 5);
106
+ ctx.rotate(Math.PI / 2);
107
+ ctx.fillText(i * baseScale, 0, 0);
108
+ ctx.restore();
109
+ }
110
+ }
111
+ }
112
+ ctx.stroke();
113
+ ctx.beginPath();
114
+ ctx.clearRect(0, 0, 20, 20);
115
+ }
116
+ }
117
+ }
@@ -6,3 +6,4 @@ export {Shape} from './shape';
6
6
  export {Area} from './area';
7
7
  export {Board} from './board';
8
8
  export {Graduation} from './graduation';
9
+ export {Grid} from './grid';
@@ -19,14 +19,32 @@ export class Navigator extends EventEmitter {
19
19
  this.viewport = rest.viewer.viewport;
20
20
  this.viewer = rest.viewer;
21
21
  this.el = rest.el;
22
- this.height = rest.height || 200;
23
- this.width = rest.width || 200;
22
+ this.height = rest.height || 150;
23
+ this.width = rest.width || 150;
24
24
  this.containerHeight = rest.containerHeight || window.innerHeight;
25
25
  this.containerWidth = rest.containerWidth || window.innerWidth;
26
26
  this.element = rest.element;
27
27
  this.pointList = rest.pointList || [];
28
- this.info = '';
28
+ this.loadStatus = false; // 导航图加载状态
29
29
  this.init();
30
+ this.vestige = this.options.vestige ? {
31
+ show: true,
32
+ delay: 1000,
33
+ colors: [
34
+ 'rgba(255, 255, 0, .5)',
35
+ 'rgba(0, 255, 255, .5)',
36
+ 'rgba(255, 0, 255, .5)'],
37
+ zooms: [5, 10, 20],
38
+ ...this.options.vestige,
39
+ } : {
40
+ show: true,
41
+ delay: 1000,
42
+ colors: [
43
+ 'rgba(255, 255, 0, .5)',
44
+ 'rgba(0, 255, 255, .5)',
45
+ 'rgba(255, 0, 255, .5)'],
46
+ zooms: [5, 10, 20],
47
+ };
30
48
  }
31
49
 
32
50
  /**
@@ -51,15 +69,20 @@ export class Navigator extends EventEmitter {
51
69
  hLine.style.top =
52
70
  Math.round(rect.getBoundingClientRect().height / 2 +
53
71
  rect.offsetTop) + 'px';
72
+ vLine.style.backgroundColor = 'red';
73
+ hLine.style.backgroundColor = 'red';
54
74
  });
55
75
  this.$on('rect-draw', (e) => {
56
76
  const left = rect.offsetLeft;
57
77
  const top = rect.offsetTop;
78
+ const index = e.detail;
58
79
  const rectObj = {
59
80
  left: left,
60
81
  top: top,
61
82
  width: rect.clientWidth,
62
83
  height: rect.clientHeight,
84
+ scale: [...this.vestige.zooms].reverse()[index],
85
+ color: [...this.vestige.colors].reverse()[index],
63
86
  };
64
87
  this.pointList.push(rectObj);
65
88
  this.drawPointList(this.pointList);
@@ -82,9 +105,10 @@ export class Navigator extends EventEmitter {
82
105
  const colorCanvas = this.element.getElementsByClassName(
83
106
  'navigator-color-rect')[0];
84
107
  const ctx = colorCanvas.getContext('2d');
85
- this.pointList.forEach((item) => {
86
- this.drawRect(ctx, item);
87
- });
108
+ this.pointList.sort((a, b) => a.scale > b.scale ? 1 : -1).
109
+ forEach((item) => {
110
+ this.drawRect(ctx, item);
111
+ });
88
112
  }
89
113
 
90
114
  /**
@@ -96,7 +120,7 @@ export class Navigator extends EventEmitter {
96
120
  // if (clear)
97
121
  // ctx.clearRect(0, 0, this.containerWidth, this.containerHeight);
98
122
  ctx.beginPath();
99
- ctx.fillStyle = this.options.vestigeColor || 'rgba(255, 0, 255, .5)';
123
+ ctx.fillStyle = item.color;
100
124
  ctx.clearRect(item.left, item.top, item.width + 1, item.height + 1);
101
125
  ctx.fillRect(item.left, item.top, item.width + 1, item.height + 1);
102
126
  }
@@ -108,6 +132,9 @@ export class Navigator extends EventEmitter {
108
132
  * @param {Object=} rect 遮罩层元素
109
133
  */
110
134
  navigatorChange(zoom, refPoint, rect) {
135
+ if (!this.loadStatus) {
136
+ return;
137
+ }
111
138
  if (!refPoint) {
112
139
  refPoint = this.viewport.getCenter(true);
113
140
  }
@@ -270,14 +297,17 @@ export class Navigator extends EventEmitter {
270
297
  };
271
298
  rect.style.left = refPoint.x + 'px';
272
299
  rect.style.top = refPoint.y + 'px';
300
+ rect.style.border = '1px solid red';
273
301
  this.$emit('rect-change');
274
- if (this.options.vestige) {
302
+ if (this.vestige.show !== false) {
275
303
  if (this.clearTimeId) window.clearTimeout(this.clearTimeId);
276
- if (this.viewport.viewportToImageZoom(currentZoom) >=
277
- (this.options.vestigeZoom ?? 1)) {
304
+ const currentImageZoom = this.viewport.viewportToImageZoom(currentZoom);
305
+ const index = [...this.vestige.zooms].reverse().findIndex(
306
+ (z) => currentImageZoom >= (z / (this.options.scale || 40)));
307
+ if (index !== -1) {
278
308
  this.clearTimeId = window.setTimeout(() => {
279
- this.$emit('rect-draw');
280
- }, this.options.vestigeDelay || 1000);
309
+ this.$emit('rect-draw', index);
310
+ }, this.vestige.delay || 1000);
281
311
  }
282
312
  }
283
313
  }
@@ -295,24 +325,25 @@ export class Navigator extends EventEmitter {
295
325
  const imgHeight = img.height;
296
326
  let scale = 1;
297
327
  if (imgWidth >= imgHeight) {
298
- scale = imgWidth / this.width;
299
- const trueHeight = imgHeight / scale;
300
- canvas.width = this.width;
301
- canvas.height = trueHeight;
302
- ctx.drawImage(img, 0, 0, canvas.width, trueHeight);
303
- }
304
- if (imgHeight > imgWidth) {
305
328
  scale = imgHeight / this.height;
306
329
  const trueWidth = imgWidth / scale;
307
330
  canvas.height = this.height;
308
331
  canvas.width = trueWidth;
309
332
  ctx.drawImage(img, 0, 0, trueWidth, canvas.height);
310
333
  }
334
+ if (imgHeight > imgWidth) {
335
+ scale = imgWidth / this.width;
336
+ const trueHeight = imgHeight / scale;
337
+ canvas.width = this.width;
338
+ canvas.height = trueHeight;
339
+ ctx.drawImage(img, 0, 0, canvas.width, trueHeight);
340
+ }
311
341
  this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
312
342
  const colorCanvas = this.element.getElementsByClassName(
313
343
  'navigator-color-rect')[0];
314
344
  colorCanvas.width = this.canvas.width;
315
345
  colorCanvas.height = this.canvas.height;
346
+ this.loadStatus = true;
316
347
  };
317
348
  img.src = this.options.thumbnail; // 设置图片源地
318
349
  return canvas;
@@ -327,14 +358,6 @@ export class Navigator extends EventEmitter {
327
358
  const imgHeight = img.height;
328
359
  let scale = 1;
329
360
  if (imgWidth >= imgHeight) {
330
- scale = imgWidth / this.width;
331
- const trueHeight = imgHeight / scale;
332
- this.canvas.width = this.width;
333
- this.canvas.height = trueHeight;
334
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
335
- ctx.drawImage(img, 0, 0, this.canvas.width, trueHeight);
336
- }
337
- if (imgHeight > imgWidth) {
338
361
  scale = imgHeight / this.height;
339
362
  const trueWidth = imgWidth / scale;
340
363
  this.canvas.height = this.height;
@@ -342,6 +365,14 @@ export class Navigator extends EventEmitter {
342
365
  ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
343
366
  ctx.drawImage(img, 0, 0, trueWidth, this.canvas.height);
344
367
  }
368
+ if (imgHeight > imgWidth) {
369
+ scale = imgWidth / this.width;
370
+ const trueHeight = imgHeight / scale;
371
+ this.canvas.width = this.width;
372
+ this.canvas.height = trueHeight;
373
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
374
+ ctx.drawImage(img, 0, 0, this.canvas.width, trueHeight);
375
+ }
345
376
  this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
346
377
  const colorCanvas = this.element.getElementsByClassName(
347
378
  'navigator-color-rect')[0];
@@ -350,4 +381,14 @@ export class Navigator extends EventEmitter {
350
381
  };
351
382
  img.src = this.options.thumbnail; // 设置图片源地
352
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
+ }
353
394
  }
@@ -14,7 +14,6 @@
14
14
  line-height: 1px;
15
15
  position: absolute;
16
16
  top: 0;
17
- background-color: rgb(255, 0, 0);
18
17
  }
19
18
 
20
19
  .h-line {
@@ -23,12 +22,10 @@
23
22
  line-height: 1px;
24
23
  position: absolute;
25
24
  left: 0;
26
- background-color: rgb(255, 0, 0);
27
25
  }
28
26
 
29
27
  .view-rect {
30
28
  top: -1px;
31
- border: 1px solid rgb(255, 0, 0);
32
29
  background-color: rgb(255, 255, 255);
33
30
  position: absolute;
34
31
  cursor: pointer;
@@ -51,14 +51,14 @@ 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
- if (REGION_TYPES.includes(item.tool) || item.isClose && item.tool ===
61
- POLYGON && item.fillStyle) {
60
+ if ((REGION_TYPES.includes(item.tool) || item.isClose && item.tool ===
61
+ POLYGON) && item.fillStyle) {
62
62
  regionLabelList.push({
63
63
  ...item,
64
64
  child: [],
@@ -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
  }
@@ -105,7 +105,7 @@ export class Tailoring extends ViewerCommon {
105
105
  ctx.stroke();
106
106
  ctx.beginPath();
107
107
  ctx.fillStyle = this.color;
108
- ctx.font = '18px';
108
+ ctx.font = '18px Arial';
109
109
  ctx.fillText(
110
110
  `区域大小为:${rightTop.x - leftTop.x}*${rightBottom.y - rightTop.y}`,
111
111
  leftTop.x, leftTop.y - 50);
@@ -6,3 +6,4 @@ export const COMPONENT_ROTATION = 'rotation';
6
6
  export const COMPONENT_TAILORING = 'tailoring';
7
7
  export const COMPONENT_NAVIGATOR = 'navigator';
8
8
  export const COMPONENT_CACHE = 'cache';
9
+ export const COMPONENT_FRID = 'grid';
package/src/tool/Brush.js CHANGED
@@ -62,27 +62,26 @@ class Brush {
62
62
  * @param {number} [scale=1]
63
63
  */
64
64
  drawMeasureInfo(label, info, scale = 1) {
65
- const {left, top, content, angle} = info;
65
+ const {left, top, texts, angle} = info;
66
66
  const ctx = this.canvas.getContext('2d');
67
67
  ctx.save();
68
68
  ctx.beginPath();
69
69
  ctx.translate(left, top);
70
70
  ctx.rotate(angle);
71
71
  ctx.scale(scale, scale);
72
- ctx.font = `14px Arial`;
73
72
  const widthList = [];
74
- content.forEach((info) => {
73
+ ctx.font = `${this.options.measure.fontSize}px Arial`;
74
+ texts.forEach((info) => {
75
75
  widthList.push(ctx.measureText(info).width);
76
76
  });
77
77
  const width = Math.max(...widthList);
78
- ctx.fillStyle = 'rgba(0,0,0,.5)';
79
- const height = content.length * 20 + 16 + (content.length - 1) * 4;
78
+ ctx.fillStyle = this.options.measure.backgroundColor;
79
+ const height = texts.length * 20 + 16 + (texts.length - 1) * 4;
80
80
  ctx.rect(0, 0, width + 22, height);
81
81
  ctx.fill();
82
82
  ctx.beginPath();
83
- ctx.font = `14px Arial`;
84
- ctx.fillStyle = '#FDFDFD';
85
- content.forEach((info, index) => {
83
+ ctx.fillStyle = this.options.measure.color;
84
+ texts.forEach((info, index) => {
86
85
  ctx.fillText(info, 11, 8 + 14 + index * 24);
87
86
  });
88
87
  ctx.fill();