kfb-view 2.2.1 → 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 +56 -52
- package/example/index.js +14 -4
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- 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/shape/index.js +2 -2
- package/src/components/tailoring/index.js +1 -1
- package/src/view.js +5 -4
package/package.json
CHANGED
|
@@ -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;
|
|
@@ -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);
|
package/src/view.js
CHANGED
|
@@ -27,10 +27,11 @@ export default class KfbView extends EventEmitter {
|
|
|
27
27
|
* @param {string} config.navigator.width navigator宽度
|
|
28
28
|
* @param {string} config.navigator.height navigator高度
|
|
29
29
|
* @param {string} config.navigator.thumbnail 缩略图地址
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {
|
|
30
|
+
* @param {Object} config.navigator.vestige 缩略图浏览痕迹配置
|
|
31
|
+
* @param {boolean=} config.navigator.vestige.show 是否显示缩略图浏览痕迹
|
|
32
|
+
* @param {number=} config.navigator.vestige.delay 浏览痕迹颜色时间
|
|
33
|
+
* @param {string[]=} config.navigator.vestige.colors 浏览痕迹颜色
|
|
34
|
+
* @param {number[]=} config.navigator.vestige.zooms 浏览痕迹触发倍率
|
|
34
35
|
* @param {Object} config.pxConversion 像素转换参数
|
|
35
36
|
* @param {number} config.pxConversion.imageCapRes 像素转换倍率
|
|
36
37
|
* @param {string} config.pxConversion.unit 单位
|