@inweb/markup 25.8.1 → 25.8.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/dist/markup.js +132 -198
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +139 -193
- package/dist/markup.module.js.map +1 -1
- package/lib/markup/Konva/KonvaMarkup.d.ts +0 -2
- package/lib/markup/WorldTransform.d.ts +2 -1
- package/package.json +3 -3
- package/src/markup/Konva/KonvaMarkup.ts +173 -227
- package/src/markup/WorldTransform.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inweb/markup",
|
|
3
|
-
"version": "25.8.
|
|
3
|
+
"version": "25.8.3",
|
|
4
4
|
"description": "JavaScript 2D markups",
|
|
5
5
|
"homepage": "https://cloud.opendesign.com/docs/index.html",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"docs": "typedoc"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@inweb/eventemitter2": "~25.8.
|
|
30
|
-
"@inweb/viewer-core": "~25.8.
|
|
29
|
+
"@inweb/eventemitter2": "~25.8.3",
|
|
30
|
+
"@inweb/viewer-core": "~25.8.3"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"canvas": "^2.11.2",
|
|
@@ -23,12 +23,22 @@
|
|
|
23
23
|
|
|
24
24
|
import Konva from "konva";
|
|
25
25
|
import { IEventEmitter } from "@inweb/eventemitter2";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
ChangeActiveDraggerEvent,
|
|
28
|
+
IArrow,
|
|
29
|
+
ICloud,
|
|
30
|
+
IEllipse,
|
|
31
|
+
IImage,
|
|
32
|
+
ILine,
|
|
33
|
+
IRectangle,
|
|
34
|
+
IText,
|
|
35
|
+
IViewpoint,
|
|
36
|
+
PanEvent,
|
|
37
|
+
} from "@inweb/viewer-core";
|
|
27
38
|
|
|
28
39
|
import { IMarkup, MarkupMode } from "../IMarkup";
|
|
29
40
|
import { IWorldTransform } from "../IWorldTransform";
|
|
30
41
|
import { IMarkupObject } from "../IMarkupObject";
|
|
31
|
-
import { IMarkupColorable } from "../IMarkupColorable";
|
|
32
42
|
import { MarkupLineType } from "../IMarkupLine";
|
|
33
43
|
import { MarkupColor } from "./MarkupColor";
|
|
34
44
|
import { WorldTransform } from "../WorldTransform";
|
|
@@ -235,49 +245,73 @@ export class KonvaMarkup implements IMarkup {
|
|
|
235
245
|
|
|
236
246
|
colorizeAllMarkup(r: number, g: number, b: number): void {
|
|
237
247
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
238
|
-
this.getObjects().
|
|
239
|
-
const colorable = obj as unknown as IMarkupColorable;
|
|
240
|
-
if (colorable && colorable.setColor) colorable.setColor(hexColor);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
this._konvaLayer.draw();
|
|
248
|
+
this.getObjects().filter((obj: any) => obj.setColor?.(hexColor));
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
colorizeSelectedMarkups(r: number, g: number, b: number): void {
|
|
247
252
|
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
248
|
-
this.getSelectedObjects().
|
|
249
|
-
const colorable = obj as unknown as IMarkupColorable;
|
|
250
|
-
if (colorable && colorable.setColor) colorable.setColor(hexColor);
|
|
251
|
-
});
|
|
253
|
+
this.getSelectedObjects().filter((obj: any) => obj.setColor?.(hexColor));
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
setViewpoint(viewpoint: IViewpoint): void {
|
|
255
|
-
const markupColor = viewpoint.custom_fields
|
|
257
|
+
const markupColor = viewpoint.custom_fields?.markup_color || { r: 255, g: 0, b: 0 };
|
|
256
258
|
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
257
259
|
|
|
258
|
-
|
|
260
|
+
viewpoint.lines?.forEach((line: ILine) => {
|
|
261
|
+
const linePoints = [];
|
|
262
|
+
line.points.forEach((point) => {
|
|
263
|
+
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
264
|
+
linePoints.push(screenPoint.x);
|
|
265
|
+
linePoints.push(screenPoint.y);
|
|
266
|
+
});
|
|
267
|
+
this.addLine(linePoints, line.color, line.type as MarkupLineType, line.width, line.id);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
viewpoint.texts?.forEach((text: IText) => {
|
|
271
|
+
const screenPoint = this._worldTransformer.worldToScreen(text.position);
|
|
272
|
+
this.addText(text.text, screenPoint, text.angle, text.color, text.text_size, text.font_size, text.id);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
viewpoint.rectangles?.forEach((rect: IRectangle) => {
|
|
276
|
+
const screenPoint = this._worldTransformer.worldToScreen(rect.position);
|
|
277
|
+
this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
viewpoint.ellipses?.forEach((ellipse: IEllipse) => {
|
|
281
|
+
const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
|
|
282
|
+
this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
viewpoint.arrows?.forEach((arrow: IArrow) => {
|
|
286
|
+
const startPoint = this._worldTransformer.worldToScreen(arrow.start);
|
|
287
|
+
const endPoint = this._worldTransformer.worldToScreen(arrow.end);
|
|
288
|
+
this.addArrow(startPoint, endPoint, arrow.color, arrow.id);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
viewpoint.clouds?.forEach((cloud: ICloud) => {
|
|
292
|
+
const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
|
|
293
|
+
this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
viewpoint.images?.forEach((image: IImage) => {
|
|
297
|
+
const screenPoint = this._worldTransformer.worldToScreen(image.position);
|
|
298
|
+
this.addImage(screenPoint, image.src, image.width, image.height, image.id);
|
|
299
|
+
});
|
|
259
300
|
}
|
|
260
301
|
|
|
261
302
|
getViewpoint(): IViewpoint {
|
|
262
|
-
const viewpoint: IViewpoint = {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
viewpoint.
|
|
273
|
-
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
viewpoint.custom_fields = {
|
|
277
|
-
markup_color: this.getMarkupColor(),
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
this.fillViewpointShapes(viewpoint);
|
|
303
|
+
const viewpoint: IViewpoint = {};
|
|
304
|
+
|
|
305
|
+
viewpoint.lines = this.getMarkupLines();
|
|
306
|
+
viewpoint.texts = this.getMarkupTexts();
|
|
307
|
+
viewpoint.arrows = this.getMarkupArrows();
|
|
308
|
+
viewpoint.clouds = this.getMarkupClouds();
|
|
309
|
+
viewpoint.ellipses = this.getMarkupEllipses();
|
|
310
|
+
viewpoint.images = this.getMarkupImages();
|
|
311
|
+
viewpoint.rectangles = this.getMarkupRectangles();
|
|
312
|
+
|
|
313
|
+
viewpoint.custom_fields = { markup_color: this.getMarkupColor() };
|
|
314
|
+
viewpoint.snapshot = { data: this.combineMarkupWithDrawing() };
|
|
281
315
|
|
|
282
316
|
viewpoint.description = new Date().toDateString();
|
|
283
317
|
return viewpoint;
|
|
@@ -339,57 +373,6 @@ export class KonvaMarkup implements IMarkup {
|
|
|
339
373
|
this._konvaTransformer.nodes([]);
|
|
340
374
|
}
|
|
341
375
|
|
|
342
|
-
private fillViewpointShapes(viewpoint) {
|
|
343
|
-
const markupLines = this.getMarkupLines();
|
|
344
|
-
if (markupLines && markupLines.length > 0) {
|
|
345
|
-
markupLines?.forEach((line) => {
|
|
346
|
-
viewpoint.lines.push(line);
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const markupTexts = this.getMarkupTexts();
|
|
351
|
-
if (markupTexts && markupTexts.length > 0) {
|
|
352
|
-
markupTexts?.forEach((text) => {
|
|
353
|
-
viewpoint.texts.push(text);
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const markupRectangles = this.getMarkupRectangles();
|
|
358
|
-
if (markupRectangles && markupRectangles.length > 0) {
|
|
359
|
-
markupRectangles?.forEach((rectangle) => {
|
|
360
|
-
viewpoint.rectangles.push(rectangle);
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const markupEllipses = this.getMarkupEllipses();
|
|
365
|
-
if (markupEllipses && markupEllipses.length > 0) {
|
|
366
|
-
markupEllipses?.forEach((ellipse) => {
|
|
367
|
-
viewpoint.ellipses.push(ellipse);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const markupArrows = this.getMarkupArrows();
|
|
372
|
-
if (markupArrows && markupArrows.length > 0) {
|
|
373
|
-
markupArrows?.forEach((arrow) => {
|
|
374
|
-
viewpoint.arrows.push(arrow);
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const markupImages = this.getMarkupImages();
|
|
379
|
-
if (markupImages && markupImages.length > 0) {
|
|
380
|
-
markupImages?.forEach((image) => {
|
|
381
|
-
viewpoint.images.push(image);
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const markupClouds = this.getMarkupClouds();
|
|
386
|
-
if (markupClouds && markupClouds.length > 0) {
|
|
387
|
-
markupClouds?.forEach((cloud) => {
|
|
388
|
-
viewpoint.clouds.push(cloud);
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
376
|
private addObject(object: IMarkupObject): void {
|
|
394
377
|
this._konvaLayer.add(object.ref());
|
|
395
378
|
}
|
|
@@ -640,13 +623,15 @@ export class KonvaMarkup implements IMarkup {
|
|
|
640
623
|
this._konvaStage = undefined;
|
|
641
624
|
}
|
|
642
625
|
|
|
643
|
-
private getMarkupLines() {
|
|
626
|
+
private getMarkupLines(): Array<ILine> {
|
|
644
627
|
const lines = [];
|
|
645
|
-
|
|
646
|
-
|
|
628
|
+
|
|
629
|
+
this.konvaLayerFind("Line").forEach((ref) => {
|
|
630
|
+
const linePoints = ref.points();
|
|
647
631
|
if (!linePoints) return;
|
|
632
|
+
|
|
648
633
|
const worldPoints = [];
|
|
649
|
-
const absoluteTransform =
|
|
634
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
650
635
|
for (let i = 0; i < linePoints.length; i += 2) {
|
|
651
636
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
652
637
|
// https://stackoverflow.com/a/57641487 - check answer's comments
|
|
@@ -656,33 +641,33 @@ export class KonvaMarkup implements IMarkup {
|
|
|
656
641
|
worldPoints.push(worldPoint);
|
|
657
642
|
}
|
|
658
643
|
|
|
659
|
-
const konvaLine = new KonvaLine(null,
|
|
660
|
-
|
|
644
|
+
const konvaLine = new KonvaLine(null, ref);
|
|
645
|
+
const line: ILine = {
|
|
661
646
|
id: konvaLine.id(),
|
|
662
647
|
points: worldPoints,
|
|
663
648
|
color: konvaLine.getColor() || "#ff0000",
|
|
664
649
|
type: konvaLine.getLineType() || this.lineType,
|
|
665
650
|
width: konvaLine.getLineWidth() || this.lineWidth,
|
|
666
|
-
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
lines.push(line);
|
|
667
654
|
});
|
|
668
655
|
|
|
669
656
|
return lines;
|
|
670
657
|
}
|
|
671
658
|
|
|
672
|
-
private getMarkupTexts() {
|
|
659
|
+
private getMarkupTexts(): Array<IText> {
|
|
673
660
|
const texts = [];
|
|
674
661
|
|
|
675
662
|
const textSize = 0.02;
|
|
676
663
|
const textScale = this._worldTransformer.getScale();
|
|
677
664
|
|
|
678
|
-
this.konvaLayerFind("Text").forEach((
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
const position = { x: text.x(), y: text.y() };
|
|
665
|
+
this.konvaLayerFind("Text").forEach((ref) => {
|
|
666
|
+
const position = { x: ref.x(), y: ref.y() };
|
|
682
667
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
683
668
|
|
|
684
|
-
const shape = new KonvaText(null,
|
|
685
|
-
|
|
669
|
+
const shape = new KonvaText(null, ref);
|
|
670
|
+
const text: IText = {
|
|
686
671
|
id: shape.id(),
|
|
687
672
|
position: worldPoint,
|
|
688
673
|
text: shape.getText(),
|
|
@@ -690,156 +675,129 @@ export class KonvaMarkup implements IMarkup {
|
|
|
690
675
|
angle: shape.getRotation(),
|
|
691
676
|
color: shape.getColor(),
|
|
692
677
|
font_size: shape.getFontSize(),
|
|
693
|
-
}
|
|
678
|
+
};
|
|
679
|
+
|
|
680
|
+
texts.push(text);
|
|
694
681
|
});
|
|
695
682
|
|
|
696
683
|
return texts;
|
|
697
684
|
}
|
|
698
685
|
|
|
699
|
-
private getMarkupRectangles() {
|
|
686
|
+
private getMarkupRectangles(): Array<IRectangle> {
|
|
700
687
|
const rectangles = [];
|
|
701
|
-
|
|
702
|
-
|
|
688
|
+
|
|
689
|
+
this.konvaLayerFind("Rectangle").forEach((ref) => {
|
|
690
|
+
const position = ref.position();
|
|
703
691
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
704
692
|
|
|
705
|
-
const shape = new KonvaRectangle(null,
|
|
706
|
-
|
|
693
|
+
const shape = new KonvaRectangle(null, ref);
|
|
694
|
+
const rectangle: IRectangle = {
|
|
707
695
|
id: shape.id(),
|
|
708
696
|
position: worldPoint,
|
|
709
697
|
width: shape.getWidth(),
|
|
710
698
|
height: shape.getHeigth(),
|
|
711
699
|
line_width: shape.getLineWidth(),
|
|
712
700
|
color: shape.getColor(),
|
|
713
|
-
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
rectangles.push(rectangle);
|
|
714
704
|
});
|
|
715
705
|
|
|
716
706
|
return rectangles;
|
|
717
707
|
}
|
|
718
708
|
|
|
719
|
-
private getMarkupEllipses() {
|
|
709
|
+
private getMarkupEllipses(): Array<IEllipse> {
|
|
720
710
|
const ellipses = [];
|
|
721
|
-
|
|
722
|
-
|
|
711
|
+
|
|
712
|
+
this.konvaLayerFind("Ellipse").forEach((ref) => {
|
|
713
|
+
const position = ref.position();
|
|
723
714
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
724
715
|
|
|
725
|
-
const shape = new KonvaEllipse(null,
|
|
726
|
-
|
|
716
|
+
const shape = new KonvaEllipse(null, ref);
|
|
717
|
+
const ellipse: IEllipse = {
|
|
727
718
|
id: shape.id(),
|
|
728
719
|
position: worldPoint,
|
|
729
|
-
radius: { x:
|
|
720
|
+
radius: { x: ref.getRadiusX(), y: ref.getRadiusY() },
|
|
730
721
|
line_width: shape.getLineWidth(),
|
|
731
722
|
color: shape.getColor(),
|
|
732
|
-
}
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
ellipses.push(ellipse);
|
|
733
726
|
});
|
|
734
727
|
|
|
735
728
|
return ellipses;
|
|
736
729
|
}
|
|
737
730
|
|
|
738
|
-
private getMarkupArrows() {
|
|
731
|
+
private getMarkupArrows(): Array<IArrow> {
|
|
739
732
|
const arrows = [];
|
|
740
|
-
|
|
733
|
+
|
|
734
|
+
this.konvaLayerFind("Arrow").forEach((ref) => {
|
|
741
735
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
742
|
-
const absoluteTransform =
|
|
736
|
+
const absoluteTransform = ref.getAbsoluteTransform();
|
|
743
737
|
|
|
744
|
-
const atStartPoint = absoluteTransform.point({ x:
|
|
738
|
+
const atStartPoint = absoluteTransform.point({ x: ref.points()[0], y: ref.points()[1] });
|
|
745
739
|
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
746
740
|
|
|
747
|
-
const atEndPoint = absoluteTransform.point({ x:
|
|
741
|
+
const atEndPoint = absoluteTransform.point({ x: ref.points()[2], y: ref.points()[3] });
|
|
748
742
|
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
749
743
|
|
|
750
|
-
const shape = new KonvaArrow(null,
|
|
751
|
-
|
|
744
|
+
const shape = new KonvaArrow(null, ref);
|
|
745
|
+
const arrow: IArrow = {
|
|
752
746
|
id: shape.id(),
|
|
753
747
|
start: worldStartPoint,
|
|
754
748
|
end: worldEndPoint,
|
|
755
749
|
color: shape.getColor(),
|
|
756
|
-
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
arrows.push(arrow);
|
|
757
753
|
});
|
|
758
754
|
|
|
759
755
|
return arrows;
|
|
760
756
|
}
|
|
761
757
|
|
|
762
|
-
private getMarkupImages() {
|
|
758
|
+
private getMarkupImages(): Array<IImage> {
|
|
763
759
|
const images = [];
|
|
764
|
-
|
|
765
|
-
|
|
760
|
+
|
|
761
|
+
this.konvaLayerFind("Image").forEach((ref) => {
|
|
762
|
+
const position = ref.position();
|
|
766
763
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
767
764
|
|
|
768
|
-
const shape = new KonvaImage(null,
|
|
769
|
-
|
|
765
|
+
const shape = new KonvaImage(null, ref);
|
|
766
|
+
const image: IImage = {
|
|
770
767
|
id: shape.id(),
|
|
771
768
|
position: worldPoint,
|
|
772
769
|
src: shape.getSrc(),
|
|
773
770
|
width: shape.getWidth(),
|
|
774
771
|
height: shape.getHeight(),
|
|
775
|
-
}
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
images.push(image);
|
|
776
775
|
});
|
|
777
776
|
|
|
778
777
|
return images;
|
|
779
778
|
}
|
|
780
779
|
|
|
781
|
-
private getMarkupClouds() {
|
|
780
|
+
private getMarkupClouds(): Array<ICloud> {
|
|
782
781
|
const clouds = [];
|
|
783
|
-
|
|
784
|
-
|
|
782
|
+
|
|
783
|
+
this.konvaLayerFind("Cloud").forEach((ref) => {
|
|
784
|
+
const position = ref.position();
|
|
785
785
|
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
786
786
|
|
|
787
|
-
const shape = new KonvaCloud(null,
|
|
788
|
-
|
|
787
|
+
const shape = new KonvaCloud(null, ref);
|
|
788
|
+
const cloud: ICloud = {
|
|
789
789
|
id: shape.id(),
|
|
790
790
|
position: worldPoint,
|
|
791
791
|
width: shape.getWidth(),
|
|
792
792
|
height: shape.getHeigth(),
|
|
793
793
|
line_width: shape.getLineWidth(),
|
|
794
794
|
color: shape.getColor(),
|
|
795
|
-
}
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
return clouds;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
private loadMarkup(viewpoint: IViewpoint) {
|
|
802
|
-
viewpoint.lines?.forEach((vpLine) => {
|
|
803
|
-
const linePoints = [];
|
|
804
|
-
vpLine.points.forEach((point) => {
|
|
805
|
-
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
806
|
-
linePoints.push(screenPoint.x);
|
|
807
|
-
linePoints.push(screenPoint.y);
|
|
808
|
-
});
|
|
809
|
-
|
|
810
|
-
this.addLine(linePoints, vpLine.color, vpLine.type as MarkupLineType, vpLine.width, vpLine.id);
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
viewpoint.texts?.forEach((vpText) => {
|
|
814
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
|
|
815
|
-
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
viewpoint.rectangles?.forEach((vpRect) => {
|
|
819
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
|
|
820
|
-
this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
|
|
821
|
-
});
|
|
822
|
-
|
|
823
|
-
viewpoint.ellipses?.forEach((vpEllipse) => {
|
|
824
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
|
|
825
|
-
this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
viewpoint.arrows?.forEach((vpArrow) => {
|
|
829
|
-
const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
|
|
830
|
-
const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
|
|
831
|
-
this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
|
|
832
|
-
});
|
|
795
|
+
};
|
|
833
796
|
|
|
834
|
-
|
|
835
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
|
|
836
|
-
this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
|
|
797
|
+
clouds.push(cloud);
|
|
837
798
|
});
|
|
838
799
|
|
|
839
|
-
|
|
840
|
-
const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
|
|
841
|
-
this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
842
|
-
});
|
|
800
|
+
return clouds;
|
|
843
801
|
}
|
|
844
802
|
|
|
845
803
|
private combineMarkupWithDrawing() {
|
|
@@ -878,8 +836,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
878
836
|
id,
|
|
879
837
|
});
|
|
880
838
|
|
|
881
|
-
|
|
882
|
-
this._konvaLayer.add(obj);
|
|
839
|
+
this._konvaLayer.add(konvaLine.ref());
|
|
883
840
|
return konvaLine;
|
|
884
841
|
}
|
|
885
842
|
|
|
@@ -976,6 +933,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
976
933
|
fontSize?: number,
|
|
977
934
|
id?: string
|
|
978
935
|
): KonvaText | void {
|
|
936
|
+
if (!specifiedText) return;
|
|
937
|
+
|
|
979
938
|
const trNodes = this._konvaTransformer.nodes();
|
|
980
939
|
if (trNodes.length > 0) {
|
|
981
940
|
// in case of edit - remove old Konva.Text object
|
|
@@ -985,28 +944,25 @@ export class KonvaMarkup implements IMarkup {
|
|
|
985
944
|
|
|
986
945
|
this.removeTextInput();
|
|
987
946
|
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
fontSize = textSize / (scale.y / size) / 34;
|
|
996
|
-
}
|
|
947
|
+
// in case we have old viewpoint without font_size
|
|
948
|
+
const tolerance = 1.0e-6;
|
|
949
|
+
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
950
|
+
const size = 0.02;
|
|
951
|
+
const scale = this._worldTransformer.getScale();
|
|
952
|
+
fontSize = textSize / (scale.y / size) / 34;
|
|
953
|
+
}
|
|
997
954
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
955
|
+
const konvaText = new KonvaText({
|
|
956
|
+
position: { x: position.x, y: position.y },
|
|
957
|
+
text: specifiedText,
|
|
958
|
+
rotation: angle,
|
|
959
|
+
fontSize: fontSize || this.fontSize,
|
|
960
|
+
color: color || this._markupColor.HexColor,
|
|
961
|
+
id,
|
|
962
|
+
});
|
|
1006
963
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
}
|
|
964
|
+
this._konvaLayer.add(konvaText.ref());
|
|
965
|
+
return konvaText;
|
|
1010
966
|
}
|
|
1011
967
|
|
|
1012
968
|
private addRectangle(
|
|
@@ -1028,8 +984,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1028
984
|
id,
|
|
1029
985
|
});
|
|
1030
986
|
|
|
1031
|
-
|
|
1032
|
-
this._konvaLayer.add(obj);
|
|
987
|
+
this._konvaLayer.add(konvaRectangle.ref());
|
|
1033
988
|
return konvaRectangle;
|
|
1034
989
|
}
|
|
1035
990
|
|
|
@@ -1050,8 +1005,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1050
1005
|
id,
|
|
1051
1006
|
});
|
|
1052
1007
|
|
|
1053
|
-
|
|
1054
|
-
this._konvaLayer.add(obj);
|
|
1008
|
+
this._konvaLayer.add(konvaEllipse.ref());
|
|
1055
1009
|
return konvaEllipse;
|
|
1056
1010
|
}
|
|
1057
1011
|
|
|
@@ -1070,8 +1024,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1070
1024
|
id,
|
|
1071
1025
|
});
|
|
1072
1026
|
|
|
1073
|
-
|
|
1074
|
-
this._konvaLayer.add(obj);
|
|
1027
|
+
this._konvaLayer.add(konvaArrow.ref());
|
|
1075
1028
|
return konvaArrow;
|
|
1076
1029
|
}
|
|
1077
1030
|
|
|
@@ -1094,8 +1047,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1094
1047
|
id,
|
|
1095
1048
|
});
|
|
1096
1049
|
|
|
1097
|
-
|
|
1098
|
-
this._konvaLayer.add(obj);
|
|
1050
|
+
this._konvaLayer.add(konvaCloud.ref());
|
|
1099
1051
|
return konvaCloud;
|
|
1100
1052
|
}
|
|
1101
1053
|
|
|
@@ -1106,32 +1058,26 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1106
1058
|
height?: number,
|
|
1107
1059
|
id?: string
|
|
1108
1060
|
): KonvaImage | void {
|
|
1109
|
-
if (!position) return;
|
|
1061
|
+
if (!position || !src) return;
|
|
1110
1062
|
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
src,
|
|
1117
|
-
width,
|
|
1118
|
-
height,
|
|
1119
|
-
id,
|
|
1120
|
-
});
|
|
1121
|
-
|
|
1122
|
-
const obj = konvaImage.ref();
|
|
1123
|
-
this._konvaLayer.add(obj);
|
|
1124
|
-
|
|
1125
|
-
const trNodes = this._konvaTransformer.nodes();
|
|
1126
|
-
if (trNodes.length > 0) {
|
|
1127
|
-
// in case of edit - remove old Image placeholder object
|
|
1128
|
-
trNodes[0].destroy();
|
|
1129
|
-
this._konvaTransformer.nodes([]);
|
|
1130
|
-
}
|
|
1063
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1064
|
+
if (trNodes.length > 0) {
|
|
1065
|
+
// in case of edit - remove old Image placeholder object
|
|
1066
|
+
trNodes[0].destroy();
|
|
1067
|
+
this._konvaTransformer.nodes([]);
|
|
1131
1068
|
}
|
|
1132
1069
|
|
|
1133
1070
|
this.removeImageInput();
|
|
1134
1071
|
|
|
1072
|
+
const konvaImage = new KonvaImage({
|
|
1073
|
+
position,
|
|
1074
|
+
src,
|
|
1075
|
+
width,
|
|
1076
|
+
height,
|
|
1077
|
+
id,
|
|
1078
|
+
});
|
|
1079
|
+
|
|
1080
|
+
this._konvaLayer.add(konvaImage.ref());
|
|
1135
1081
|
return konvaImage;
|
|
1136
1082
|
}
|
|
1137
1083
|
}
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
import { IWorldTransform } from "./IWorldTransform";
|
|
25
|
+
|
|
26
|
+
export class WorldTransform implements IWorldTransform {
|
|
25
27
|
screenToWorld(position: { x: number; y: number }): { x: number; y: number; z: number } {
|
|
26
28
|
return { x: position.x, y: position.y, z: 0 };
|
|
27
29
|
}
|