kfb-view 2.1.20 → 2.2.2
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 +114 -109
- package/example/index.js +21 -9
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/components/area/index.js +66 -44
- package/src/components/board/index.js +31 -18
- package/src/components/common/common.js +12 -22
- package/src/components/graduation/index.js +7 -5
- package/src/components/navigator/index.js +53 -24
- package/src/components/navigator/navigator.scss +0 -3
- package/src/components/rotation/index.js +5 -7
- package/src/components/shape/index.js +76 -52
- package/src/components/tailoring/index.js +4 -6
- package/src/const/event.js +3 -0
- package/src/tool/Brush.js +1 -1
- package/src/tool/Combination.js +1 -0
- package/src/tool/Polygon.js +2 -5
- package/src/tool/Thumb.js +2 -2
- package/src/util/calculate.js +26 -3
- package/src/view.js +64 -24
package/package.json
CHANGED
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
baseNumber, getAngle, getDistance, getPoint,
|
|
13
13
|
getRectPoint,
|
|
14
14
|
isPointInMatrix,
|
|
15
|
-
pointInOtherPoint, isPointInPolygon, pointsToRegion,
|
|
15
|
+
pointInOtherPoint, isPointInPolygon, pointsToRegion, isPointInLine,
|
|
16
16
|
} from '../../util/calculate';
|
|
17
17
|
import {
|
|
18
|
+
EVENT_ADD_POLYGON_POINT,
|
|
18
19
|
EVENT_AREA_MOVE_END,
|
|
19
20
|
EVENT_AREA_MOVE_START, EVENT_AREA_MOVING, EVENT_CANCEL_SELECT_LABEL,
|
|
20
21
|
EVENT_DB_CLICK_LABEL,
|
|
@@ -48,12 +49,19 @@ export class Area extends ViewerCommon {
|
|
|
48
49
|
/**
|
|
49
50
|
* 画点
|
|
50
51
|
* @param {Object} point
|
|
51
|
-
* @param {
|
|
52
|
+
* @param {Boolean=} active 是否是激活状态
|
|
52
53
|
*/
|
|
53
|
-
drawPoint(point,
|
|
54
|
+
drawPoint(point, active) {
|
|
54
55
|
this.thumb.draw(point, {
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
radius: !active ?
|
|
57
|
+
this.options.thumb.radius :
|
|
58
|
+
this.options.thumb.activeRadius,
|
|
59
|
+
strokeStyle: !active ?
|
|
60
|
+
this.options.thumb.color :
|
|
61
|
+
this.options.thumb.activeColor,
|
|
62
|
+
fillStyle: !active ?
|
|
63
|
+
this.options.thumb.bgColor :
|
|
64
|
+
this.options.thumb.activeBgColor,
|
|
57
65
|
});
|
|
58
66
|
}
|
|
59
67
|
|
|
@@ -214,7 +222,31 @@ export class Area extends ViewerCommon {
|
|
|
214
222
|
onCanvasDblClick({x, y}) {
|
|
215
223
|
setTimeout(() => {
|
|
216
224
|
const label = this.labelList.find((item) => item.select);
|
|
217
|
-
|
|
225
|
+
if (label?.tool === POLYGON) {
|
|
226
|
+
const points = this.imageToViewerElementPoints(label.points);
|
|
227
|
+
let index = -1;
|
|
228
|
+
for (let i = 0, l = points.length, j = l - 1; i < l; j = i, i++) {
|
|
229
|
+
const s = points[i];
|
|
230
|
+
const t = points[j];
|
|
231
|
+
if (isPointInLine({x, y}, [s, t])) {
|
|
232
|
+
index = i;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (index > -1) {
|
|
237
|
+
const p = this.viewerElementToImageCoordinates(x, y);
|
|
238
|
+
label.points.splice(index, 0, {
|
|
239
|
+
...p,
|
|
240
|
+
canMove: true,
|
|
241
|
+
});
|
|
242
|
+
this.$emit(EVENT_ADD_POLYGON_POINT, label);
|
|
243
|
+
this.change();
|
|
244
|
+
} else {
|
|
245
|
+
this.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
this.$emit(EVENT_DB_CLICK_LABEL, label);
|
|
249
|
+
}
|
|
218
250
|
});
|
|
219
251
|
}
|
|
220
252
|
|
|
@@ -237,11 +269,12 @@ export class Area extends ViewerCommon {
|
|
|
237
269
|
|
|
238
270
|
/**
|
|
239
271
|
* 监听鼠标拖动事件
|
|
272
|
+
* @param {Object} position
|
|
273
|
+
* @param {number} position.x
|
|
274
|
+
* @param {number} position.y
|
|
240
275
|
* @param {Object} e
|
|
241
|
-
* @param {number} e.x
|
|
242
|
-
* @param {number} e.y
|
|
243
276
|
*/
|
|
244
|
-
onCanvasDrag({x, y}) {
|
|
277
|
+
onCanvasDrag({x, y}, e) {
|
|
245
278
|
if (this.options.drag === false) return;
|
|
246
279
|
if (!this.lastPoint) this.lastPoint = {x, y};
|
|
247
280
|
const label = this.movePoint.label;
|
|
@@ -251,6 +284,7 @@ export class Area extends ViewerCommon {
|
|
|
251
284
|
if (!isMove && !isResize) return;
|
|
252
285
|
if (position === 4 && !isMove) return;
|
|
253
286
|
if (position !== 4 && !isResize) return;
|
|
287
|
+
e.preventDefaultAction = true;
|
|
254
288
|
const scale = this.getImageZoom(true) / label.scale;
|
|
255
289
|
const tool = label.tool;
|
|
256
290
|
const region = label.region;
|
|
@@ -428,54 +462,42 @@ export class Area extends ViewerCommon {
|
|
|
428
462
|
this.lastPoint = {x, y};
|
|
429
463
|
}
|
|
430
464
|
|
|
431
|
-
/**
|
|
432
|
-
* 监听鼠标按钮事件
|
|
433
|
-
* @param {Object} e
|
|
434
|
-
*/
|
|
435
|
-
onCanvasKey(e) {
|
|
436
|
-
const {originalEvent} = e;
|
|
437
|
-
const label = this.labelList.find((item) => item.select);
|
|
438
|
-
if (originalEvent.code === 'Escape' && label) {
|
|
439
|
-
this.$emit(EVENT_CANCEL_SELECT_LABEL, label);
|
|
440
|
-
this.change();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
465
|
/**
|
|
445
466
|
* 绘制点
|
|
446
467
|
* @param {Object} points
|
|
447
468
|
* @param {string} type
|
|
448
469
|
*/
|
|
449
|
-
|
|
450
|
-
if (this.options.thumb === false) {
|
|
470
|
+
drawThumbPoints(points, type) {
|
|
471
|
+
if (this.options.thumb.show === false) {
|
|
451
472
|
return;
|
|
452
473
|
}
|
|
453
|
-
const
|
|
474
|
+
const position = this.movePoint?.position;
|
|
454
475
|
if (LINE_TYPES.includes(type)) {
|
|
455
|
-
this.drawPoint(points[0],
|
|
476
|
+
this.drawPoint(points[0], position === 1);
|
|
456
477
|
this.drawPoint({
|
|
457
478
|
x: (points[0].x + points[1].x) / 2,
|
|
458
479
|
y: (points[0].y + points[1].y) / 2,
|
|
459
|
-
},
|
|
460
|
-
this.drawPoint(points[1],
|
|
480
|
+
}, position === 4);
|
|
481
|
+
this.drawPoint(points[1], position === 7);
|
|
461
482
|
} else if (REGION_TYPES.includes(type)) {
|
|
462
|
-
getRectPoint(points[0], points[1]).forEach((point) => {
|
|
463
|
-
this.drawPoint(point,
|
|
483
|
+
getRectPoint(points[0], points[1]).forEach((point, i) => {
|
|
484
|
+
this.drawPoint(point, position === i);
|
|
464
485
|
});
|
|
465
486
|
} else if (type === POLYGON) {
|
|
466
|
-
points.forEach((point) => {
|
|
487
|
+
points.forEach((point, i) => {
|
|
467
488
|
if (point.canMove) {
|
|
468
|
-
this.drawPoint(point,
|
|
489
|
+
this.drawPoint(point, position === i);
|
|
469
490
|
}
|
|
470
491
|
});
|
|
471
492
|
} else if (type === FONT || type === DOT) {
|
|
472
|
-
this.drawPoint(points[0],
|
|
493
|
+
this.drawPoint(points[0], position === 4);
|
|
473
494
|
} else if (type === STAR || type === FLAG) {
|
|
474
495
|
getRectPoint(points[0], points[1]).
|
|
475
|
-
|
|
476
|
-
index ===
|
|
477
|
-
|
|
478
|
-
|
|
496
|
+
forEach((point, index) => {
|
|
497
|
+
if (index === 0 || index === 2 || index === 4 ||
|
|
498
|
+
index === 6 || index === 8) {
|
|
499
|
+
this.drawPoint(point, position === index);
|
|
500
|
+
}
|
|
479
501
|
});
|
|
480
502
|
}
|
|
481
503
|
}
|
|
@@ -496,17 +518,17 @@ export class Area extends ViewerCommon {
|
|
|
496
518
|
region.x + region.width, region.y + region.height);
|
|
497
519
|
const scale = this.getImageZoom(true) / label.scale;
|
|
498
520
|
if (!NO_NORMAL_REGION_TYPES.includes(label.tool)) {
|
|
499
|
-
this.
|
|
521
|
+
this.drawThumbPoints([startPoint, endPoint], label.tool);
|
|
500
522
|
} else if (label.tool === FONT) {
|
|
501
523
|
const fontWidth = this.getFontWidth(label.text, label.fontSize);
|
|
502
524
|
const pt = getPoint(startPoint, {
|
|
503
525
|
x: startPoint.x + fontWidth / 2 * scale,
|
|
504
526
|
y: startPoint.y - label.fontSize / 2 * scale + 4,
|
|
505
527
|
}, label.angle);
|
|
506
|
-
this.
|
|
528
|
+
this.drawThumbPoints([pt], label.tool);
|
|
507
529
|
} else if (label.tool === STAR) {
|
|
508
530
|
const dist = label.lineWidth * scale;
|
|
509
|
-
this.
|
|
531
|
+
this.drawThumbPoints([
|
|
510
532
|
{
|
|
511
533
|
x: startPoint.x - dist,
|
|
512
534
|
y: startPoint.y - dist,
|
|
@@ -515,14 +537,14 @@ export class Area extends ViewerCommon {
|
|
|
515
537
|
y: startPoint.y + dist,
|
|
516
538
|
}], label.tool);
|
|
517
539
|
} else if (label.tool === DOT) {
|
|
518
|
-
this.
|
|
540
|
+
this.drawThumbPoints([
|
|
519
541
|
{
|
|
520
542
|
x: startPoint.x,
|
|
521
543
|
y: startPoint.y,
|
|
522
544
|
}], label.tool);
|
|
523
545
|
} else if (label.tool === FLAG) {
|
|
524
546
|
const dist = label.lineWidth * scale;
|
|
525
|
-
this.
|
|
547
|
+
this.drawThumbPoints([
|
|
526
548
|
{
|
|
527
549
|
x: startPoint.x,
|
|
528
550
|
y: startPoint.y - dist,
|
|
@@ -533,10 +555,10 @@ export class Area extends ViewerCommon {
|
|
|
533
555
|
} else if (label.tool === POLYGON) {
|
|
534
556
|
if (this.draging) {
|
|
535
557
|
const points = this.imageToViewerElementPoints(label.points);
|
|
536
|
-
this.
|
|
558
|
+
this.drawThumbPoints(points, label.tool);
|
|
537
559
|
} else {
|
|
538
560
|
const points = this.setPointsMove(label);
|
|
539
|
-
this.
|
|
561
|
+
this.drawThumbPoints(points, label.tool);
|
|
540
562
|
}
|
|
541
563
|
}
|
|
542
564
|
this[label.tool].setContent(this.canvas, {...label});
|
|
@@ -149,7 +149,11 @@ export class Board extends ViewerCommon {
|
|
|
149
149
|
this[tool].draw(points);
|
|
150
150
|
this[tool].endDraw();
|
|
151
151
|
if (tool === POLYGON) {
|
|
152
|
-
this[tool].drawPoints(points
|
|
152
|
+
this[tool].drawPoints(points, {
|
|
153
|
+
radius: this.options.thumb.radius,
|
|
154
|
+
strokeStyle: this.options.thumb.color,
|
|
155
|
+
fillStyle: this.options.thumb.bgColor,
|
|
156
|
+
});
|
|
153
157
|
}
|
|
154
158
|
this.$emit(EVENT_START_PAINTING, this.getPaintOptions());
|
|
155
159
|
}
|
|
@@ -182,7 +186,11 @@ export class Board extends ViewerCommon {
|
|
|
182
186
|
this[tool].draw(points);
|
|
183
187
|
this[tool].endDraw();
|
|
184
188
|
if (tool === POLYGON) {
|
|
185
|
-
this[tool].drawPoints(points
|
|
189
|
+
this[tool].drawPoints(points, {
|
|
190
|
+
radius: this.options.thumb.radius,
|
|
191
|
+
strokeStyle: this.options.thumb.color,
|
|
192
|
+
fillStyle: this.options.thumb.bgColor,
|
|
193
|
+
});
|
|
186
194
|
}
|
|
187
195
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
188
196
|
}
|
|
@@ -298,7 +306,11 @@ export class Board extends ViewerCommon {
|
|
|
298
306
|
this[tool].draw(points);
|
|
299
307
|
this[tool].endDraw();
|
|
300
308
|
if (tool === POLYGON) {
|
|
301
|
-
this[tool].drawPoints(points
|
|
309
|
+
this[tool].drawPoints(points, {
|
|
310
|
+
radius: this.options.thumb.radius,
|
|
311
|
+
strokeStyle: this.options.thumb.color,
|
|
312
|
+
fillStyle: this.options.thumb.bgColor,
|
|
313
|
+
});
|
|
302
314
|
}
|
|
303
315
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
304
316
|
}
|
|
@@ -309,18 +321,16 @@ export class Board extends ViewerCommon {
|
|
|
309
321
|
* @param {Object} e
|
|
310
322
|
*/
|
|
311
323
|
onCanvasKey(e) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
this.change();
|
|
323
|
-
}
|
|
324
|
+
const {originalEvent} = e;
|
|
325
|
+
if (originalEvent.key === 'Escape') {
|
|
326
|
+
this.endDraw();
|
|
327
|
+
}
|
|
328
|
+
if (originalEvent.key === 'Delete' || originalEvent.key ===
|
|
329
|
+
'Backspace') {
|
|
330
|
+
// 曲线绘制中,按删除键,删除上一个标注点
|
|
331
|
+
if (this.tool === POLYGON && this.points.length > 1) {
|
|
332
|
+
this.points.splice(this.points.length - 2, 1);
|
|
333
|
+
this.change();
|
|
324
334
|
}
|
|
325
335
|
}
|
|
326
336
|
}
|
|
@@ -345,8 +355,7 @@ export class Board extends ViewerCommon {
|
|
|
345
355
|
const lastTwoPoint = this.points[this.points.length - 2];
|
|
346
356
|
if (pointInOtherPoint(
|
|
347
357
|
this.imageToViewerElementCoordinates(lastPoint.x, lastPoint.y),
|
|
348
|
-
this.imageToViewerElementCoordinates(lastTwoPoint.x, lastTwoPoint.y)
|
|
349
|
-
30)) {
|
|
358
|
+
this.imageToViewerElementCoordinates(lastTwoPoint.x, lastTwoPoint.y))) {
|
|
350
359
|
this.points.splice(this.points.length - 2, 1);
|
|
351
360
|
}
|
|
352
361
|
}
|
|
@@ -414,7 +423,11 @@ export class Board extends ViewerCommon {
|
|
|
414
423
|
this[this.tool].draw(points);
|
|
415
424
|
this[this.tool].endDraw();
|
|
416
425
|
if (this.tool === POLYGON) {
|
|
417
|
-
this[this.tool].drawPoints(points
|
|
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
|
+
});
|
|
418
431
|
}
|
|
419
432
|
this.$emit(EVENT_IN_PAINTING, this.getPaintOptions());
|
|
420
433
|
}
|
|
@@ -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) {
|
|
@@ -14,9 +14,10 @@ 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 ||
|
|
17
|
+
this.scales = options.scales ||
|
|
18
|
+
[0.1, 0.4, 0.6, 1, 2, 4, 8, 10, 20, 40, 80, 100];
|
|
18
19
|
this.microns = options.microns ||
|
|
19
|
-
[5000, 2000, 1250, 1000, 500, 250, 100, 50, 25, 10];
|
|
20
|
+
[5000, 2000, 1250, 1000, 500, 250, 200, 100, 50, 25, 10, 5];
|
|
20
21
|
this.init();
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -85,15 +86,16 @@ export class Graduation extends ViewerCommon {
|
|
|
85
86
|
y = height - bottom;
|
|
86
87
|
}
|
|
87
88
|
ctx.beginPath();
|
|
88
|
-
ctx.strokeStyle = '#
|
|
89
|
-
ctx.lineWidth =
|
|
89
|
+
ctx.strokeStyle = '#000000';
|
|
90
|
+
ctx.lineWidth = 3;
|
|
90
91
|
ctx.moveTo(x, y - 5);
|
|
91
92
|
ctx.lineTo(x, y);
|
|
92
93
|
ctx.lineTo(x + lineWidth, y);
|
|
93
94
|
ctx.lineTo(x + lineWidth, y - 5);
|
|
94
95
|
ctx.stroke();
|
|
95
96
|
ctx.beginPath();
|
|
96
|
-
ctx.fillStyle = '#
|
|
97
|
+
ctx.fillStyle = '#000000';
|
|
98
|
+
ctx.font = 'bold 16px Arial';
|
|
97
99
|
const t = txt.toFixed(0) + this.options.unit;
|
|
98
100
|
const fontWidth = ctx.measureText(t).width;
|
|
99
101
|
ctx.fillText(t, x + lineWidth / 2 - fontWidth / 2, top ? y + 10 : y - 10);
|
|
@@ -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 ||
|
|
23
|
-
this.width = rest.width ||
|
|
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.
|
|
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,19 @@ 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
|
+
color: [...this.vestige.colors].reverse()[index],
|
|
63
85
|
};
|
|
64
86
|
this.pointList.push(rectObj);
|
|
65
87
|
this.drawPointList(this.pointList);
|
|
@@ -96,7 +118,7 @@ export class Navigator extends EventEmitter {
|
|
|
96
118
|
// if (clear)
|
|
97
119
|
// ctx.clearRect(0, 0, this.containerWidth, this.containerHeight);
|
|
98
120
|
ctx.beginPath();
|
|
99
|
-
ctx.fillStyle =
|
|
121
|
+
ctx.fillStyle = item.color;
|
|
100
122
|
ctx.clearRect(item.left, item.top, item.width + 1, item.height + 1);
|
|
101
123
|
ctx.fillRect(item.left, item.top, item.width + 1, item.height + 1);
|
|
102
124
|
}
|
|
@@ -108,6 +130,9 @@ export class Navigator extends EventEmitter {
|
|
|
108
130
|
* @param {Object=} rect 遮罩层元素
|
|
109
131
|
*/
|
|
110
132
|
navigatorChange(zoom, refPoint, rect) {
|
|
133
|
+
if (!this.loadStatus) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
111
136
|
if (!refPoint) {
|
|
112
137
|
refPoint = this.viewport.getCenter(true);
|
|
113
138
|
}
|
|
@@ -270,14 +295,17 @@ export class Navigator extends EventEmitter {
|
|
|
270
295
|
};
|
|
271
296
|
rect.style.left = refPoint.x + 'px';
|
|
272
297
|
rect.style.top = refPoint.y + 'px';
|
|
298
|
+
rect.style.border = '1px solid red';
|
|
273
299
|
this.$emit('rect-change');
|
|
274
|
-
if (this.
|
|
300
|
+
if (this.vestige.show !== false) {
|
|
275
301
|
if (this.clearTimeId) window.clearTimeout(this.clearTimeId);
|
|
276
|
-
|
|
277
|
-
|
|
302
|
+
const currentImageZoom = this.viewport.viewportToImageZoom(currentZoom);
|
|
303
|
+
const index = [...this.vestige.zooms].reverse().findIndex(
|
|
304
|
+
(z) => currentImageZoom > (z / (this.options.scale || 40)));
|
|
305
|
+
if (index !== -1) {
|
|
278
306
|
this.clearTimeId = window.setTimeout(() => {
|
|
279
|
-
this.$emit('rect-draw');
|
|
280
|
-
}, this.
|
|
307
|
+
this.$emit('rect-draw', index);
|
|
308
|
+
}, this.vestige.delay || 1000);
|
|
281
309
|
}
|
|
282
310
|
}
|
|
283
311
|
}
|
|
@@ -295,24 +323,25 @@ export class Navigator extends EventEmitter {
|
|
|
295
323
|
const imgHeight = img.height;
|
|
296
324
|
let scale = 1;
|
|
297
325
|
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
326
|
scale = imgHeight / this.height;
|
|
306
327
|
const trueWidth = imgWidth / scale;
|
|
307
328
|
canvas.height = this.height;
|
|
308
329
|
canvas.width = trueWidth;
|
|
309
330
|
ctx.drawImage(img, 0, 0, trueWidth, canvas.height);
|
|
310
331
|
}
|
|
332
|
+
if (imgHeight > imgWidth) {
|
|
333
|
+
scale = imgWidth / this.width;
|
|
334
|
+
const trueHeight = imgHeight / scale;
|
|
335
|
+
canvas.width = this.width;
|
|
336
|
+
canvas.height = trueHeight;
|
|
337
|
+
ctx.drawImage(img, 0, 0, canvas.width, trueHeight);
|
|
338
|
+
}
|
|
311
339
|
this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
|
|
312
340
|
const colorCanvas = this.element.getElementsByClassName(
|
|
313
341
|
'navigator-color-rect')[0];
|
|
314
342
|
colorCanvas.width = this.canvas.width;
|
|
315
343
|
colorCanvas.height = this.canvas.height;
|
|
344
|
+
this.loadStatus = true;
|
|
316
345
|
};
|
|
317
346
|
img.src = this.options.thumbnail; // 设置图片源地
|
|
318
347
|
return canvas;
|
|
@@ -327,14 +356,6 @@ export class Navigator extends EventEmitter {
|
|
|
327
356
|
const imgHeight = img.height;
|
|
328
357
|
let scale = 1;
|
|
329
358
|
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
359
|
scale = imgHeight / this.height;
|
|
339
360
|
const trueWidth = imgWidth / scale;
|
|
340
361
|
this.canvas.height = this.height;
|
|
@@ -342,6 +363,14 @@ export class Navigator extends EventEmitter {
|
|
|
342
363
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
343
364
|
ctx.drawImage(img, 0, 0, trueWidth, this.canvas.height);
|
|
344
365
|
}
|
|
366
|
+
if (imgHeight > imgWidth) {
|
|
367
|
+
scale = imgWidth / this.width;
|
|
368
|
+
const trueHeight = imgHeight / scale;
|
|
369
|
+
this.canvas.width = this.width;
|
|
370
|
+
this.canvas.height = trueHeight;
|
|
371
|
+
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
372
|
+
ctx.drawImage(img, 0, 0, this.canvas.width, trueHeight);
|
|
373
|
+
}
|
|
345
374
|
this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
|
|
346
375
|
const colorCanvas = this.element.getElementsByClassName(
|
|
347
376
|
'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;
|
|
@@ -91,7 +91,7 @@ class Rotation extends ViewerCommon {
|
|
|
91
91
|
this.drawPoint({
|
|
92
92
|
x: point.x,
|
|
93
93
|
y: point.y,
|
|
94
|
-
}, {
|
|
94
|
+
}, {radius: 5});
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -151,12 +151,10 @@ class Rotation extends ViewerCommon {
|
|
|
151
151
|
* @param {Object} e
|
|
152
152
|
*/
|
|
153
153
|
onCanvasKey(e) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.stopRotation();
|
|
159
|
-
}
|
|
154
|
+
const {originalEvent} = e;
|
|
155
|
+
if (originalEvent.key === 'Escape') {
|
|
156
|
+
this.viewport.setRotation(0);
|
|
157
|
+
this.stopRotation();
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
|