@inweb/markup 26.3.3 → 26.4.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/dist/markup.js +698 -285
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +709 -175
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/IMarkupArrow.d.ts +8 -8
- package/lib/markup/IMarkupCloud.d.ts +12 -5
- package/lib/markup/IMarkupEllipse.d.ts +4 -4
- package/lib/markup/IMarkupImage.d.ts +3 -3
- package/lib/markup/IMarkupLine.d.ts +2 -2
- package/lib/markup/IMarkupObject.d.ts +4 -0
- package/lib/markup/IMarkupRectangle.d.ts +10 -3
- package/lib/markup/IMarkupText.d.ts +3 -3
- package/lib/markup/Konva/KonvaArrow.d.ts +4 -1
- package/lib/markup/Konva/KonvaCloud.d.ts +4 -1
- package/lib/markup/Konva/KonvaEllipse.d.ts +4 -1
- package/lib/markup/Konva/KonvaImage.d.ts +4 -1
- package/lib/markup/Konva/KonvaLine.d.ts +4 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
- package/lib/markup/Konva/KonvaRectangle.d.ts +4 -1
- package/lib/markup/Konva/KonvaText.d.ts +4 -1
- package/package.json +3 -3
- package/src/markup/IMarkupArrow.ts +8 -8
- package/src/markup/IMarkupCloud.ts +10 -5
- package/src/markup/IMarkupEllipse.ts +4 -4
- package/src/markup/IMarkupImage.ts +3 -3
- package/src/markup/IMarkupLine.ts +2 -2
- package/src/markup/IMarkupObject.ts +5 -0
- package/src/markup/IMarkupRectangle.ts +8 -3
- package/src/markup/IMarkupText.ts +3 -3
- package/src/markup/Konva/KonvaArrow.ts +49 -4
- package/src/markup/Konva/KonvaCloud.ts +110 -11
- package/src/markup/Konva/KonvaEllipse.ts +102 -2
- package/src/markup/Konva/KonvaImage.ts +60 -2
- package/src/markup/Konva/KonvaLine.ts +97 -3
- package/src/markup/Konva/KonvaMarkup.ts +182 -166
- package/src/markup/Konva/KonvaRectangle.ts +103 -4
- package/src/markup/Konva/KonvaText.ts +61 -2
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
IViewpoint,
|
|
36
36
|
PanEvent,
|
|
37
37
|
ZoomAtEvent,
|
|
38
|
+
ResizeEvent,
|
|
38
39
|
} from "@inweb/viewer-core";
|
|
39
40
|
|
|
40
41
|
import { IMarkup, MarkupMode } from "../IMarkup";
|
|
@@ -58,34 +59,47 @@ const MarkupMode2Konva = {
|
|
|
58
59
|
},
|
|
59
60
|
Line: {
|
|
60
61
|
name: "Line",
|
|
61
|
-
initializer: (ref: any, params = null) => new KonvaLine(params, ref),
|
|
62
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaLine(params, ref, ...attr),
|
|
62
63
|
},
|
|
63
64
|
Text: {
|
|
64
65
|
name: "Text",
|
|
65
|
-
initializer: (ref: any, params = null) => new KonvaText(params, ref),
|
|
66
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaText(params, ref, ...attr),
|
|
66
67
|
},
|
|
67
68
|
Rectangle: {
|
|
68
69
|
name: "Rect",
|
|
69
|
-
initializer: (ref: any, params = null) => new KonvaRectangle(params, ref),
|
|
70
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaRectangle(params, ref, ...attr),
|
|
70
71
|
},
|
|
71
72
|
Ellipse: {
|
|
72
73
|
name: "Ellipse",
|
|
73
|
-
initializer: (ref: any, params = null) => new KonvaEllipse(params, ref),
|
|
74
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaEllipse(params, ref, ...attr),
|
|
74
75
|
},
|
|
75
76
|
Arrow: {
|
|
76
77
|
name: "Arrow",
|
|
77
|
-
initializer: (ref: any, params = null) => new KonvaArrow(params, ref),
|
|
78
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaArrow(params, ref, ...attr),
|
|
78
79
|
},
|
|
79
80
|
Image: {
|
|
80
81
|
name: "Image",
|
|
81
|
-
initializer: (ref: any, params = null) => new KonvaImage(params, ref),
|
|
82
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaImage(params, ref, ...attr),
|
|
82
83
|
},
|
|
83
84
|
Cloud: {
|
|
84
85
|
name: "Cloud",
|
|
85
|
-
initializer: (ref: any, params = null) => new KonvaCloud(params, ref),
|
|
86
|
+
initializer: (ref: any, params = null, ...attr: any) => new KonvaCloud(params, ref, ...attr),
|
|
86
87
|
},
|
|
87
88
|
};
|
|
88
89
|
|
|
90
|
+
function debounce(func, wait: number) {
|
|
91
|
+
let timeout = null;
|
|
92
|
+
return (...args) => {
|
|
93
|
+
if (timeout) {
|
|
94
|
+
clearTimeout(timeout);
|
|
95
|
+
}
|
|
96
|
+
timeout = setTimeout(() => {
|
|
97
|
+
timeout = null;
|
|
98
|
+
func(...args);
|
|
99
|
+
}, wait);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
89
103
|
/**
|
|
90
104
|
* 2D markup core.
|
|
91
105
|
*/
|
|
@@ -93,7 +107,6 @@ export class KonvaMarkup implements IMarkup {
|
|
|
93
107
|
private _viewer: IEventEmitter;
|
|
94
108
|
private _worldTransformer: IWorldTransform;
|
|
95
109
|
private _container: HTMLElement;
|
|
96
|
-
private _containerEvents: string[] = [];
|
|
97
110
|
private _markupIsActive = false;
|
|
98
111
|
private _markupMode: MarkupMode;
|
|
99
112
|
private _markupColor = new MarkupColor(255, 0, 0);
|
|
@@ -130,7 +143,6 @@ export class KonvaMarkup implements IMarkup {
|
|
|
130
143
|
this._viewer = viewer;
|
|
131
144
|
this._worldTransformer = worldTransformer ?? new WorldTransform();
|
|
132
145
|
this._container = container;
|
|
133
|
-
this._containerEvents = containerEvents ?? [];
|
|
134
146
|
|
|
135
147
|
this._markupContainer = document.createElement("div");
|
|
136
148
|
this._markupContainer.id = "markup-container";
|
|
@@ -143,15 +155,14 @@ export class KonvaMarkup implements IMarkup {
|
|
|
143
155
|
const parentDiv = this._container.parentElement;
|
|
144
156
|
parentDiv.appendChild(this._markupContainer);
|
|
145
157
|
|
|
146
|
-
this.
|
|
147
|
-
this._resizeObserver.
|
|
158
|
+
if (viewer) this._viewer.addEventListener("resize", this.resizeViewer);
|
|
159
|
+
else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
|
|
148
160
|
|
|
149
161
|
this._markupColor.setColor(255, 0, 0);
|
|
150
162
|
|
|
151
163
|
this.initializeKonva();
|
|
152
164
|
|
|
153
165
|
if (this._viewer) {
|
|
154
|
-
// this._containerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
|
|
155
166
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
156
167
|
this._viewer.addEventListener("pan", this.pan);
|
|
157
168
|
this._viewer.addEventListener("zoomat", this.zoomAt);
|
|
@@ -163,7 +174,6 @@ export class KonvaMarkup implements IMarkup {
|
|
|
163
174
|
this._viewer.removeEventListener("zoomat", this.zoomAt);
|
|
164
175
|
this._viewer.removeEventListener("pan", this.pan);
|
|
165
176
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
166
|
-
// this._containerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
167
177
|
}
|
|
168
178
|
|
|
169
179
|
this.destroyKonva();
|
|
@@ -205,25 +215,36 @@ export class KonvaMarkup implements IMarkup {
|
|
|
205
215
|
|
|
206
216
|
this._konvaStage.width(width);
|
|
207
217
|
this._konvaStage.height(height);
|
|
218
|
+
|
|
219
|
+
this.getObjects().forEach((markupObject) => {
|
|
220
|
+
markupObject.updateScreenCoordinates();
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
resizeViewer = (event: ResizeEvent) => {
|
|
225
|
+
const { width, height } = event;
|
|
226
|
+
|
|
227
|
+
if (!width || !height) return; // <- invisible container, or container with parent removed
|
|
228
|
+
if (!this._konvaStage) return;
|
|
229
|
+
|
|
230
|
+
this._konvaStage.width(width);
|
|
231
|
+
this._konvaStage.height(height);
|
|
232
|
+
|
|
233
|
+
this.getObjects().forEach((markupObject) => {
|
|
234
|
+
markupObject.updateScreenCoordinates();
|
|
235
|
+
});
|
|
208
236
|
};
|
|
209
237
|
|
|
210
238
|
pan = (event: PanEvent) => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
};
|
|
215
|
-
this._konvaStage.position(newPos);
|
|
239
|
+
this.getObjects().forEach((markupObject) => {
|
|
240
|
+
markupObject.updateScreenCoordinates();
|
|
241
|
+
});
|
|
216
242
|
};
|
|
217
243
|
|
|
218
244
|
zoomAt = (event: ZoomAtEvent) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const newPos = {
|
|
223
|
-
x: event.x - (event.x - this._konvaStage.x()) * event.data,
|
|
224
|
-
y: event.y - (event.y - this._konvaStage.y()) * event.data,
|
|
225
|
-
};
|
|
226
|
-
this._konvaStage.position(newPos);
|
|
245
|
+
this.getObjects().forEach((markupObject) => {
|
|
246
|
+
markupObject.updateScreenCoordinates();
|
|
247
|
+
});
|
|
227
248
|
};
|
|
228
249
|
|
|
229
250
|
redirectToViewer = (event: any) => {
|
|
@@ -285,7 +306,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
285
306
|
|
|
286
307
|
viewpoint.rectangles?.forEach((rect: IRectangle) => {
|
|
287
308
|
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
288
|
-
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
309
|
+
this.addRectangle(screenPoint, null, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
289
310
|
});
|
|
290
311
|
|
|
291
312
|
viewpoint.ellipses?.forEach((ellipse: IEllipse) => {
|
|
@@ -301,7 +322,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
301
322
|
|
|
302
323
|
viewpoint.clouds?.forEach((cloud: ICloud) => {
|
|
303
324
|
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
304
|
-
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
325
|
+
this.addCloud(screenPoint, null, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
305
326
|
});
|
|
306
327
|
|
|
307
328
|
viewpoint.images?.forEach((image: IImage) => {
|
|
@@ -347,7 +368,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
347
368
|
if (!konvaShape || !konvaShape.initializer)
|
|
348
369
|
throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
|
|
349
370
|
|
|
350
|
-
const object = konvaShape.initializer(null, params);
|
|
371
|
+
const object = konvaShape.initializer(null, params, this._worldTransformer);
|
|
351
372
|
this.addObject(object);
|
|
352
373
|
|
|
353
374
|
return object;
|
|
@@ -357,7 +378,9 @@ export class KonvaMarkup implements IMarkup {
|
|
|
357
378
|
const objects = [];
|
|
358
379
|
Object.keys(MarkupMode2Konva).forEach((type) => {
|
|
359
380
|
const konvaShape = MarkupMode2Konva[type];
|
|
360
|
-
this.konvaLayerFind(type).forEach((ref) =>
|
|
381
|
+
this.konvaLayerFind(type).forEach((ref) =>
|
|
382
|
+
objects.push(konvaShape.initializer(ref, null, this._worldTransformer))
|
|
383
|
+
);
|
|
361
384
|
});
|
|
362
385
|
return objects;
|
|
363
386
|
}
|
|
@@ -370,7 +393,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
370
393
|
.map((ref) => {
|
|
371
394
|
const name = ref.className;
|
|
372
395
|
const konvaShape = Object.values(MarkupMode2Konva).find((shape) => shape.name === name);
|
|
373
|
-
return konvaShape ? konvaShape.initializer(ref) : null;
|
|
396
|
+
return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
|
|
374
397
|
})
|
|
375
398
|
.filter((x) => x);
|
|
376
399
|
}
|
|
@@ -490,7 +513,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
490
513
|
const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
|
|
491
514
|
if (defParams) {
|
|
492
515
|
if (this._markupMode === "Rectangle") {
|
|
493
|
-
this.addRectangle({ x: startX, y: startY }, dX, dY);
|
|
516
|
+
this.addRectangle({ x: startX, y: startY }, null, dX, dY);
|
|
494
517
|
} else if (this._markupMode === "Ellipse") {
|
|
495
518
|
this.addEllipse({ x: startX, y: startY }, { x: dX / 2, y: dY / 2 });
|
|
496
519
|
} else if (this._markupMode === "Arrow") {
|
|
@@ -499,7 +522,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
499
522
|
{ x: defParams ? mouseDownPos.x + 200 : pos.x, y: defParams ? startY : pos.y }
|
|
500
523
|
);
|
|
501
524
|
} else if (this._markupMode === "Cloud") {
|
|
502
|
-
this.addCloud({ x: startX, y: startY }, Math.max(100, dX), Math.max(100, dY));
|
|
525
|
+
this.addCloud({ x: startX, y: startY }, null, Math.max(100, dX), Math.max(100, dY));
|
|
503
526
|
}
|
|
504
527
|
}
|
|
505
528
|
}
|
|
@@ -534,7 +557,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
534
557
|
lastObj.setPosition(startX, startY);
|
|
535
558
|
lastObj.setWidth(dX);
|
|
536
559
|
lastObj.setHeight(dY);
|
|
537
|
-
} else lastObj = this.addRectangle({ x: startX, y: startY }, dX, dY);
|
|
560
|
+
} else lastObj = this.addRectangle({ x: startX, y: startY }, null, dX, dY);
|
|
538
561
|
} else if (this._markupMode === "Ellipse") {
|
|
539
562
|
if (lastObj) {
|
|
540
563
|
lastObj.setPosition(startX, startY);
|
|
@@ -546,7 +569,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
546
569
|
lastObj.setPosition(startX, startY);
|
|
547
570
|
lastObj.setWidth(Math.max(100, dX));
|
|
548
571
|
lastObj.setHeight(Math.max(100, dY));
|
|
549
|
-
} else lastObj = this.addCloud({ x: startX, y: startY }, dX, dY);
|
|
572
|
+
} else lastObj = this.addCloud({ x: startX, y: startY }, null, dX, dY);
|
|
550
573
|
}
|
|
551
574
|
});
|
|
552
575
|
|
|
@@ -678,27 +701,13 @@ export class KonvaMarkup implements IMarkup {
|
|
|
678
701
|
const lines = [];
|
|
679
702
|
|
|
680
703
|
this.konvaLayerFind("Line").forEach((ref) => {
|
|
681
|
-
const
|
|
682
|
-
if (!
|
|
683
|
-
|
|
684
|
-
const worldPoints = [];
|
|
685
|
-
const absoluteTransform = ref.getAbsoluteTransform();
|
|
686
|
-
for (let i = 0; i < linePoints.length; i += 2) {
|
|
687
|
-
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
688
|
-
// https://stackoverflow.com/a/57641487 - check answer's comments
|
|
689
|
-
const atPoint = absoluteTransform.point({
|
|
690
|
-
x: linePoints[i],
|
|
691
|
-
y: linePoints[i + 1],
|
|
692
|
-
});
|
|
693
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
704
|
+
const wcsPoints = ref.getAttr("wcsPoints");
|
|
705
|
+
if (!wcsPoints) return;
|
|
694
706
|
|
|
695
|
-
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
const konvaLine = new KonvaLine(null, ref);
|
|
707
|
+
const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
|
|
699
708
|
const line: ILine = {
|
|
700
709
|
id: konvaLine.id(),
|
|
701
|
-
points:
|
|
710
|
+
points: wcsPoints,
|
|
702
711
|
color: konvaLine.getColor() || "#ff0000",
|
|
703
712
|
type: konvaLine.getLineType() || this.lineType,
|
|
704
713
|
width: konvaLine.getLineWidth() || this.lineWidth,
|
|
@@ -717,16 +726,13 @@ export class KonvaMarkup implements IMarkup {
|
|
|
717
726
|
const textSize = 0.02;
|
|
718
727
|
const textScale = this._worldTransformer.getScale();
|
|
719
728
|
|
|
720
|
-
const
|
|
729
|
+
const wcsPosition = ref.getAttr("wcsStart");
|
|
721
730
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
722
|
-
const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
|
|
723
|
-
|
|
724
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
725
731
|
|
|
726
|
-
const shape = new KonvaText(null, ref);
|
|
732
|
+
const shape = new KonvaText(null, ref, this._worldTransformer);
|
|
727
733
|
const text: IText = {
|
|
728
734
|
id: shape.id(),
|
|
729
|
-
position:
|
|
735
|
+
position: wcsPosition,
|
|
730
736
|
text: shape.getText(),
|
|
731
737
|
text_size: textSize * textScale.y,
|
|
732
738
|
angle: shape.getRotation(),
|
|
@@ -744,18 +750,17 @@ export class KonvaMarkup implements IMarkup {
|
|
|
744
750
|
const rectangles = [];
|
|
745
751
|
|
|
746
752
|
this.konvaLayerFind("Rectangle").forEach((ref) => {
|
|
747
|
-
const
|
|
748
|
-
const
|
|
749
|
-
const
|
|
750
|
-
const
|
|
751
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
753
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
754
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
755
|
+
const screenStart = this._worldTransformer.worldToScreen(wcsStart);
|
|
756
|
+
const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
|
|
752
757
|
|
|
753
|
-
const shape = new KonvaRectangle(null, ref);
|
|
758
|
+
const shape = new KonvaRectangle(null, ref, this._worldTransformer);
|
|
754
759
|
const rectangle: IRectangle = {
|
|
755
760
|
id: shape.id(),
|
|
756
|
-
position:
|
|
757
|
-
width:
|
|
758
|
-
height:
|
|
761
|
+
position: wcsStart,
|
|
762
|
+
width: Math.abs(screenStart.x - screenEnd.x),
|
|
763
|
+
height: Math.abs(screenStart.y - screenEnd.y),
|
|
759
764
|
line_width: shape.getLineWidth(),
|
|
760
765
|
color: shape.getColor(),
|
|
761
766
|
};
|
|
@@ -770,16 +775,14 @@ export class KonvaMarkup implements IMarkup {
|
|
|
770
775
|
const ellipses = [];
|
|
771
776
|
|
|
772
777
|
this.konvaLayerFind("Ellipse").forEach((ref) => {
|
|
773
|
-
const
|
|
778
|
+
const wcsPosition = ref.getAttr("wcsPosition");
|
|
774
779
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
775
|
-
const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
|
|
776
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
777
780
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
778
781
|
|
|
779
|
-
const shape = new KonvaEllipse(null, ref);
|
|
782
|
+
const shape = new KonvaEllipse(null, ref, this._worldTransformer);
|
|
780
783
|
const ellipse: IEllipse = {
|
|
781
784
|
id: shape.id(),
|
|
782
|
-
position:
|
|
785
|
+
position: wcsPosition,
|
|
783
786
|
radius: {
|
|
784
787
|
x: ref.getRadiusX() * scale,
|
|
785
788
|
y: ref.getRadiusY() * scale,
|
|
@@ -799,25 +802,14 @@ export class KonvaMarkup implements IMarkup {
|
|
|
799
802
|
|
|
800
803
|
this.konvaLayerFind("Arrow").forEach((ref) => {
|
|
801
804
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
802
|
-
const
|
|
805
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
806
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
803
807
|
|
|
804
|
-
const
|
|
805
|
-
x: ref.points()[0],
|
|
806
|
-
y: ref.points()[1],
|
|
807
|
-
});
|
|
808
|
-
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
809
|
-
|
|
810
|
-
const atEndPoint = absoluteTransform.point({
|
|
811
|
-
x: ref.points()[2],
|
|
812
|
-
y: ref.points()[3],
|
|
813
|
-
});
|
|
814
|
-
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
815
|
-
|
|
816
|
-
const shape = new KonvaArrow(null, ref);
|
|
808
|
+
const shape = new KonvaArrow(null, ref, this._worldTransformer);
|
|
817
809
|
const arrow: IArrow = {
|
|
818
810
|
id: shape.id(),
|
|
819
|
-
start:
|
|
820
|
-
end:
|
|
811
|
+
start: wcsStart,
|
|
812
|
+
end: wcsEnd,
|
|
821
813
|
color: shape.getColor(),
|
|
822
814
|
};
|
|
823
815
|
|
|
@@ -831,16 +823,14 @@ export class KonvaMarkup implements IMarkup {
|
|
|
831
823
|
const images = [];
|
|
832
824
|
|
|
833
825
|
this.konvaLayerFind("Image").forEach((ref) => {
|
|
834
|
-
const
|
|
826
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
835
827
|
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
836
|
-
const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
|
|
837
|
-
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
838
828
|
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
839
829
|
|
|
840
|
-
const shape = new KonvaImage(null, ref);
|
|
830
|
+
const shape = new KonvaImage(null, ref, this._worldTransformer);
|
|
841
831
|
const image: IImage = {
|
|
842
832
|
id: shape.id(),
|
|
843
|
-
position:
|
|
833
|
+
position: wcsStart,
|
|
844
834
|
src: shape.getSrc(),
|
|
845
835
|
width: shape.getWidth() * scale,
|
|
846
836
|
height: shape.getHeight() * scale,
|
|
@@ -856,18 +846,17 @@ export class KonvaMarkup implements IMarkup {
|
|
|
856
846
|
const clouds = [];
|
|
857
847
|
|
|
858
848
|
this.konvaLayerFind("Cloud").forEach((ref) => {
|
|
859
|
-
const
|
|
860
|
-
const
|
|
861
|
-
const
|
|
862
|
-
const
|
|
863
|
-
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
849
|
+
const wcsStart = ref.getAttr("wcsStart");
|
|
850
|
+
const wcsEnd = ref.getAttr("wcsEnd");
|
|
851
|
+
const screenStart = this._worldTransformer.worldToScreen(wcsStart);
|
|
852
|
+
const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
|
|
864
853
|
|
|
865
|
-
const shape = new KonvaCloud(null, ref);
|
|
854
|
+
const shape = new KonvaCloud(null, ref, this._worldTransformer);
|
|
866
855
|
const cloud: ICloud = {
|
|
867
856
|
id: shape.id(),
|
|
868
|
-
position:
|
|
869
|
-
width:
|
|
870
|
-
height:
|
|
857
|
+
position: wcsStart,
|
|
858
|
+
width: Math.abs(screenStart.x - screenEnd.x),
|
|
859
|
+
height: Math.abs(screenStart.y - screenEnd.y),
|
|
871
860
|
line_width: shape.getLineWidth(),
|
|
872
861
|
color: shape.getColor(),
|
|
873
862
|
};
|
|
@@ -908,13 +897,17 @@ export class KonvaMarkup implements IMarkup {
|
|
|
908
897
|
points.push({ x: linePoints[i], y: linePoints[i + 1] });
|
|
909
898
|
}
|
|
910
899
|
|
|
911
|
-
const konvaLine = new KonvaLine(
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
900
|
+
const konvaLine = new KonvaLine(
|
|
901
|
+
{
|
|
902
|
+
points,
|
|
903
|
+
type: type || this.lineType,
|
|
904
|
+
width: width || this.lineWidth,
|
|
905
|
+
color: color || this._markupColor.asHex(),
|
|
906
|
+
id,
|
|
907
|
+
},
|
|
908
|
+
null,
|
|
909
|
+
this._worldTransformer
|
|
910
|
+
);
|
|
918
911
|
|
|
919
912
|
this.addObject(konvaLine);
|
|
920
913
|
return konvaLine;
|
|
@@ -1033,14 +1026,18 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1033
1026
|
fontSize = textSize / (scale.y / size) / 34;
|
|
1034
1027
|
}
|
|
1035
1028
|
|
|
1036
|
-
const konvaText = new KonvaText(
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1029
|
+
const konvaText = new KonvaText(
|
|
1030
|
+
{
|
|
1031
|
+
position: { x: position.x, y: position.y },
|
|
1032
|
+
text,
|
|
1033
|
+
rotation: angle,
|
|
1034
|
+
fontSize: fontSize || this.fontSize,
|
|
1035
|
+
color: color || this._markupColor.asHex(),
|
|
1036
|
+
id,
|
|
1037
|
+
},
|
|
1038
|
+
null,
|
|
1039
|
+
this._worldTransformer
|
|
1040
|
+
);
|
|
1044
1041
|
|
|
1045
1042
|
this.addObject(konvaText);
|
|
1046
1043
|
return konvaText;
|
|
@@ -1048,6 +1045,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1048
1045
|
|
|
1049
1046
|
private addRectangle(
|
|
1050
1047
|
position: Konva.Vector2d,
|
|
1048
|
+
position2: Konva.Vector2d,
|
|
1051
1049
|
width: number,
|
|
1052
1050
|
height: number,
|
|
1053
1051
|
lineWidth?: number,
|
|
@@ -1056,61 +1054,70 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1056
1054
|
): KonvaRectangle | void {
|
|
1057
1055
|
if (!position) return;
|
|
1058
1056
|
|
|
1059
|
-
const konvaRectangle = new KonvaRectangle(
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1057
|
+
const konvaRectangle = new KonvaRectangle(
|
|
1058
|
+
{
|
|
1059
|
+
position,
|
|
1060
|
+
position2,
|
|
1061
|
+
width,
|
|
1062
|
+
height,
|
|
1063
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1064
|
+
color: color || this._markupColor.asHex(),
|
|
1065
|
+
id,
|
|
1066
|
+
},
|
|
1067
|
+
null,
|
|
1068
|
+
this._worldTransformer
|
|
1069
|
+
);
|
|
1067
1070
|
|
|
1068
1071
|
this.addObject(konvaRectangle);
|
|
1069
1072
|
return konvaRectangle;
|
|
1070
1073
|
}
|
|
1071
1074
|
|
|
1072
1075
|
private addEllipse(
|
|
1073
|
-
position:
|
|
1074
|
-
radius:
|
|
1076
|
+
position: Konva.Vector2d,
|
|
1077
|
+
radius: Konva.Vector2d,
|
|
1075
1078
|
lineWidth?: number,
|
|
1076
1079
|
color?: string,
|
|
1077
1080
|
id?: string
|
|
1078
1081
|
): KonvaEllipse | void {
|
|
1079
1082
|
if (!position) return;
|
|
1080
1083
|
|
|
1081
|
-
const konvaEllipse = new KonvaEllipse(
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1084
|
+
const konvaEllipse = new KonvaEllipse(
|
|
1085
|
+
{
|
|
1086
|
+
position,
|
|
1087
|
+
radius,
|
|
1088
|
+
lineWidth,
|
|
1089
|
+
color: color || this._markupColor.asHex(),
|
|
1090
|
+
id,
|
|
1091
|
+
},
|
|
1092
|
+
null,
|
|
1093
|
+
this._worldTransformer
|
|
1094
|
+
);
|
|
1088
1095
|
|
|
1089
1096
|
this.addObject(konvaEllipse);
|
|
1090
1097
|
return konvaEllipse;
|
|
1091
1098
|
}
|
|
1092
1099
|
|
|
1093
|
-
private addArrow(
|
|
1094
|
-
start: { x: number; y: number },
|
|
1095
|
-
end: { x: number; y: number },
|
|
1096
|
-
color?: string,
|
|
1097
|
-
id?: string
|
|
1098
|
-
): KonvaArrow | void {
|
|
1100
|
+
private addArrow(start: Konva.Vector2d, end: Konva.Vector2d, color?: string, id?: string): KonvaArrow | void {
|
|
1099
1101
|
if (!start || !end) return;
|
|
1100
1102
|
|
|
1101
|
-
const konvaArrow = new KonvaArrow(
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1103
|
+
const konvaArrow = new KonvaArrow(
|
|
1104
|
+
{
|
|
1105
|
+
start,
|
|
1106
|
+
end,
|
|
1107
|
+
color: color || this._markupColor.asHex(),
|
|
1108
|
+
id,
|
|
1109
|
+
},
|
|
1110
|
+
null,
|
|
1111
|
+
this._worldTransformer
|
|
1112
|
+
);
|
|
1107
1113
|
|
|
1108
1114
|
this.addObject(konvaArrow);
|
|
1109
1115
|
return konvaArrow;
|
|
1110
1116
|
}
|
|
1111
1117
|
|
|
1112
1118
|
private addCloud(
|
|
1113
|
-
position:
|
|
1119
|
+
position: Konva.Vector2d,
|
|
1120
|
+
position2: Konva.Vector2d,
|
|
1114
1121
|
width: number,
|
|
1115
1122
|
height: number,
|
|
1116
1123
|
lineWidth?: number,
|
|
@@ -1119,21 +1126,26 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1119
1126
|
): KonvaCloud | void {
|
|
1120
1127
|
if (!position || !width || !height) return;
|
|
1121
1128
|
|
|
1122
|
-
const konvaCloud = new KonvaCloud(
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1129
|
+
const konvaCloud = new KonvaCloud(
|
|
1130
|
+
{
|
|
1131
|
+
position,
|
|
1132
|
+
position2,
|
|
1133
|
+
width,
|
|
1134
|
+
height,
|
|
1135
|
+
color: color || this._markupColor.asHex(),
|
|
1136
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1137
|
+
id,
|
|
1138
|
+
},
|
|
1139
|
+
null,
|
|
1140
|
+
this._worldTransformer
|
|
1141
|
+
);
|
|
1130
1142
|
|
|
1131
1143
|
this.addObject(konvaCloud);
|
|
1132
1144
|
return konvaCloud;
|
|
1133
1145
|
}
|
|
1134
1146
|
|
|
1135
1147
|
private addImage(
|
|
1136
|
-
position:
|
|
1148
|
+
position: Konva.Vector2d,
|
|
1137
1149
|
src: string,
|
|
1138
1150
|
width?: number,
|
|
1139
1151
|
height?: number,
|
|
@@ -1147,15 +1159,19 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1147
1159
|
this.clearSelected();
|
|
1148
1160
|
this.removeImageInput();
|
|
1149
1161
|
|
|
1150
|
-
const konvaImage = new KonvaImage(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1162
|
+
const konvaImage = new KonvaImage(
|
|
1163
|
+
{
|
|
1164
|
+
position,
|
|
1165
|
+
src,
|
|
1166
|
+
width,
|
|
1167
|
+
height,
|
|
1168
|
+
maxWidth: this._konvaStage.width() - position.x,
|
|
1169
|
+
maxHeight: this._konvaStage.height() - position.y,
|
|
1170
|
+
id,
|
|
1171
|
+
},
|
|
1172
|
+
null,
|
|
1173
|
+
this._worldTransformer
|
|
1174
|
+
);
|
|
1159
1175
|
|
|
1160
1176
|
this.addObject(konvaImage);
|
|
1161
1177
|
return konvaImage;
|