kfb-view 2.2.1 → 2.2.4

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.1",
4
+ "version": "2.2.4",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -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,6 +83,7 @@ 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 = [];
@@ -181,6 +183,7 @@ export class Area extends ViewerCommon {
181
183
  // moveIndex>-1,表示选中的是图形中可移动的点
182
184
  if (~moveIndex) {
183
185
  this.movePoint = {position: moveIndex, label: item};
186
+ this.currentPressPoint = {x, y};
184
187
  } else if ((item.tool !== POLYGON &&
185
188
  isPointInMatrix(pointList[0], pointList[2], pointList[6], pointList[8],
186
189
  {x, y})) ||
@@ -258,10 +261,14 @@ export class Area extends ViewerCommon {
258
261
  */
259
262
  onCanvasRelease({x, y}) {
260
263
  if (this.movePoint && this.options.drag !== false) {
261
- const label = this.movePoint.label;
262
- this.$emit(EVENT_AREA_MOVE_END, label);
264
+ const dist = getDistance(this.currentPressPoint, {x, y});
265
+ if (Math.abs(dist) > 1) {
266
+ const label = this.movePoint.label;
267
+ this.$emit(EVENT_AREA_MOVE_END, label);
268
+ }
263
269
  }
264
270
  this.movePoint = undefined;
271
+ this.currentPressPoint = undefined;
265
272
  this.lastPoint = undefined;
266
273
  this.draging = false;
267
274
  this.change();
@@ -563,7 +570,7 @@ export class Area extends ViewerCommon {
563
570
  }
564
571
  this[label.tool].setContent(this.canvas, {...label});
565
572
  if (label.measure && label.select) {
566
- this[label.tool].drawMeasureInfo(label,
573
+ this[label.tool].drawMeasureInfo.call(this, label,
567
574
  this.getMeasureContent(label), scale);
568
575
  }
569
576
  }
@@ -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
- if (tool === POLYGON) {
152
- this[tool].drawPoints(points, {
153
- radius: this.options.thumb.radius,
154
- strokeStyle: this.options.thumb.color,
155
- fillStyle: this.options.thumb.bgColor,
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
- if (tool === POLYGON) {
189
- this[tool].drawPoints(points, {
190
- radius: this.options.thumb.radius,
191
- strokeStyle: this.options.thumb.color,
192
- fillStyle: this.options.thumb.bgColor,
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 (point.x === this.points[0].x && point.y === this.points[0].y &&
213
- !NO_NORMAL_REGION_TYPES.includes(tool)) {
214
- this.points = [];
215
- return;
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
- if (tool === POLYGON) {
309
- this[tool].drawPoints(points, {
310
- radius: this.options.thumb.radius,
311
- strokeStyle: this.options.thumb.color,
312
- fillStyle: this.options.thumb.bgColor,
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
  }
@@ -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;
@@ -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
- if (this.tool === POLYGON) {
426
- this[this.tool].drawPoints(points, {
427
- radius: this.options.thumb.radius,
428
- strokeStyle: this.options.thumb.color,
429
- fillStyle: this.options.thumb.bgColor,
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
  }
@@ -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
  /**
@@ -417,6 +422,18 @@ export class ViewerCommon extends EventEmitter {
417
422
 
418
423
  }
419
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
+
420
437
  /**
421
438
  * 清除canvas
422
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,120 @@
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.font = '14px Arial';
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)';
82
+ ctx.moveTo(20, 20);
83
+ ctx.lineTo(20, this.canvas.height);
84
+ ctx.moveTo(20, 20);
85
+ ctx.lineTo(this.canvas.width, 20);
86
+ for (let i = minX; i <= maxX + 1; i++) {
87
+ const point = this.imageToViewerElementCoordinates(i * baseScale, 0);
88
+ ctx.moveTo(point.x, 0);
89
+ ctx.lineTo(point.x, 20);
90
+ for (let j = 1; j < 5; j++) {
91
+ ctx.moveTo(point.x + (basePx / 5) * j, 16);
92
+ ctx.lineTo(point.x + (basePx / 5) * j, 20);
93
+ if (i !== minX) {
94
+ ctx.fillText(i * baseScale, point.x + 5, 13);
95
+ }
96
+ }
97
+ }
98
+ for (let i = minY; i <= maxY + 1; i++) {
99
+ const point = this.imageToViewerElementCoordinates(0, i * baseScale);
100
+ ctx.moveTo(0, point.y);
101
+ ctx.lineTo(20, point.y);
102
+ for (let j = 1; j < 5; j++) {
103
+ ctx.moveTo(16, point.y + (basePx / 5) * j);
104
+ ctx.lineTo(20, point.y + (basePx / 5) * j);
105
+ if (i !== minY) {
106
+ ctx.save();
107
+ ctx.translate(3, point.y + 5);
108
+ ctx.rotate(Math.PI / 2);
109
+ ctx.fillText(i * baseScale, 0, 0);
110
+ ctx.restore();
111
+ }
112
+ }
113
+ }
114
+ ctx.stroke();
115
+ ctx.beginPath();
116
+ ctx.fillStyle = '#fff';
117
+ ctx.fillRect(0, 0, 20, 20);
118
+ }
119
+ }
120
+ }
@@ -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];
@@ -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;
@@ -57,8 +57,8 @@ export class Shape extends ViewerCommon {
57
57
  const labelList = this.labelList.filter((item) => {
58
58
  if (item.show === false) return false;
59
59
  if (!this[item.tool]) 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: [],
@@ -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';