@inweb/viewer-visualize 25.5.4 → 25.6.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.
@@ -15,6 +15,7 @@ export declare enum MarkupType {
15
15
  * "Text" markup objects are supported.
16
16
  */
17
17
  export declare enum MarkupMode {
18
+ SelectMarkup = "SelectMarkup",
18
19
  Line = "Line",
19
20
  Text = "Text",
20
21
  Rectangle = "Rectangle",
@@ -28,9 +29,17 @@ export declare enum MarkupMode {
28
29
  */
29
30
  export interface IMarkup {
30
31
  /**
31
- * Width of the markup object line
32
+ * Width of the markup object line. Default is 4.
32
33
  */
33
34
  lineWidth: number;
35
+ /**
36
+ * Type of the Line markup object. Available types: "solid", "dot", "dash". Default is "solid".
37
+ */
38
+ lineType: string;
39
+ /**
40
+ * Font size of the markup text. Default is 34.
41
+ */
42
+ fontSize: number;
34
43
  /**
35
44
  * Start method to init Markup support for the Viewer instance.
36
45
  *
@@ -1,4 +1,4 @@
1
- import { ChangeActiveDraggerEvent, IViewpoint, PanEvent } from "@inweb/viewer-core";
1
+ import { ChangeActiveDraggerEvent, IViewpoint, LineType, PanEvent } from "@inweb/viewer-core";
2
2
  import { IMarkup } from "../../IMarkup";
3
3
  import { Viewer } from "../../../Viewer";
4
4
  import { OdBaseDragger } from "../../../Draggers/Common/OdBaseDragger";
@@ -23,6 +23,8 @@ export declare class KonvaMarkup implements IMarkup {
23
23
  private _zIndex;
24
24
  private readonly _markupContainerName;
25
25
  lineWidth: number;
26
+ lineType: LineType;
27
+ fontSize: number;
26
28
  initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents?: string[]): void;
27
29
  dispose(): void;
28
30
  changeActiveDragger: (event: ChangeActiveDraggerEvent) => void;
@@ -11,6 +11,8 @@ export declare class VisualizeMarkup implements IMarkup {
11
11
  b: number;
12
12
  };
13
13
  lineWidth: number;
14
+ lineType: "solid";
15
+ fontSize: number;
14
16
  initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents: string[]): void;
15
17
  dispose(): void;
16
18
  getDraggers(): Map<string, typeof OdBaseDragger>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "25.5.4",
3
+ "version": "25.6.1",
4
4
  "description": "3D CAD and BIM data Viewer powered by Visualize",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -29,9 +29,9 @@
29
29
  "ts-docs": "typedoc"
30
30
  },
31
31
  "dependencies": {
32
- "@inweb/client": "~25.4.10",
33
- "@inweb/eventemitter2": "~25.4.10",
34
- "@inweb/viewer-core": "~25.4.10"
32
+ "@inweb/client": "~25.6.1",
33
+ "@inweb/eventemitter2": "~25.6.1",
34
+ "@inweb/viewer-core": "~25.6.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "canvas": "^2.11.2",
@@ -59,7 +59,7 @@ export class KonvaArrow implements IMarkupArrow, IMarkupColorable {
59
59
  this._ref.on("transform", (e) => {
60
60
  const attrs = e.target.attrs;
61
61
 
62
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
62
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
63
63
  });
64
64
 
65
65
  this._ref.id(this._ref._id.toString());
@@ -95,25 +95,28 @@ export class KonvaCloud implements IMarkupCloud, IMarkupColorable {
95
95
  this._ref.on("transform", (e) => {
96
96
  const attrs = e.target.attrs;
97
97
 
98
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
98
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
99
99
 
100
- const newWidth = this._ref.width() * attrs.scaleX;
101
- const newHeight = this._ref.height() * attrs.scaleY;
100
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
101
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
102
+
103
+ let newWidth = this._ref.width();
104
+ if (scaleByX) newWidth *= attrs.scaleX;
105
+ let newHeight = this._ref.height();
106
+ if (scaleByY) newHeight *= attrs.scaleY;
102
107
 
103
108
  const minWidth = 100;
104
109
  const minHeight = 100;
105
110
 
106
- if (newWidth < minWidth || newHeight < minHeight) {
107
- this._ref.scale({ x: 1, y: 1 });
108
- return;
109
- }
111
+ if (newWidth < minWidth) newWidth = minWidth;
112
+ if (newHeight < minHeight) newHeight = minHeight;
110
113
 
111
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
112
- this.setWidth(newWidth);
114
+ if (scaleByX) {
115
+ this._ref.width(newWidth);
113
116
  }
114
117
 
115
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
116
- this.setHeight(newHeight);
118
+ if (scaleByY) {
119
+ this._ref.height(newHeight);
117
120
  }
118
121
 
119
122
  this._ref.scale({ x: 1, y: 1 });
@@ -39,17 +39,30 @@ export class KonvaEllipse implements IMarkupEllipse, IMarkupColorable {
39
39
  this._ref.on("transform", (e) => {
40
40
  const attrs = e.target.attrs;
41
41
 
42
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
43
-
44
- const newRadiusX = this._ref.radiusX() * attrs.scaleX;
45
- const newRadiusY = this._ref.radiusY() * attrs.scaleY;
46
-
47
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
48
- this.setRadiusX(newRadiusX);
49
- }
50
-
51
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
52
- this.setRadiusY(newRadiusY);
42
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
43
+
44
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
45
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
46
+
47
+ let newRadiusX = this._ref.radiusX();
48
+ if (scaleByX) newRadiusX *= attrs.scaleX;
49
+ let newRadiusY = this._ref.radiusY();
50
+ if (scaleByY) newRadiusY *= attrs.scaleY;
51
+
52
+ const minRadiusX = 25;
53
+ const minRadiusY = 25;
54
+
55
+ if (newRadiusX < minRadiusX) newRadiusX = minRadiusX;
56
+ if (newRadiusY < minRadiusY) newRadiusY = minRadiusY;
57
+
58
+ if (e.evt.ctrlKey || e.evt.shiftKey) {
59
+ if (scaleByX) {
60
+ this._ref.radius({ x: newRadiusX, y: newRadiusX });
61
+ } else {
62
+ this._ref.radius({ x: newRadiusY, y: newRadiusY });
63
+ }
64
+ } else {
65
+ this._ref.radius({ x: newRadiusX, y: newRadiusY });
53
66
  }
54
67
 
55
68
  this._ref.scale({ x: 1, y: 1 });
@@ -43,17 +43,31 @@ export class KonvaImage implements IMarkupImage {
43
43
  this._ref.on("transform", (e) => {
44
44
  const attrs = e.target.attrs;
45
45
 
46
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
47
-
48
- const newWidth = this._ref.width() * attrs.scaleX;
49
- const newHeight = this._ref.height() * attrs.scaleY;
50
-
51
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
52
- this.setWidth(newWidth);
53
- }
54
-
55
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
56
- this.setHeight(newHeight);
46
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
47
+
48
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
49
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
50
+
51
+ let newWidth = this._ref.width();
52
+ if (scaleByX) newWidth *= attrs.scaleX;
53
+ let newHeight = this._ref.height();
54
+ if (scaleByY) newHeight *= attrs.scaleY;
55
+
56
+ if (e.evt.ctrlKey || e.evt.shiftKey) {
57
+ if (scaleByX) {
58
+ this._ref.width(newWidth);
59
+ this._ref.height(newWidth * this._ratio);
60
+ } else {
61
+ this._ref.width(newHeight / this._ratio);
62
+ this._ref.height(newHeight);
63
+ }
64
+ } else {
65
+ if (scaleByX) {
66
+ this._ref.width(newWidth);
67
+ }
68
+ if (scaleByY) {
69
+ this._ref.height(newHeight);
70
+ }
57
71
  }
58
72
 
59
73
  this._ref.scale({ x: 1, y: 1 });
@@ -41,7 +41,7 @@ export class KonvaLine implements IMarkupLine, IMarkupColorable {
41
41
  this._ref.on("transform", (e) => {
42
42
  const attrs = e.target.attrs;
43
43
 
44
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
44
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
45
45
  });
46
46
 
47
47
  this._ref.id(this._ref._id.toString());
@@ -40,17 +40,28 @@ export class KonvaRectangle implements IMarkupRectangle, IMarkupColorable {
40
40
  this._ref.on("transform", (e) => {
41
41
  const attrs = e.target.attrs;
42
42
 
43
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
43
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
44
44
 
45
- const newWidth = this._ref.width() * attrs.scaleX;
46
- const newHeight = this._ref.height() * attrs.scaleY;
45
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
46
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
47
47
 
48
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
49
- this.setWidth(newWidth);
48
+ let newWidth = this._ref.width();
49
+ if (scaleByX) newWidth *= attrs.scaleX;
50
+ let newHeight = this._ref.height();
51
+ if (scaleByY) newHeight *= attrs.scaleY;
52
+
53
+ const minWidth = 50;
54
+ const minHeight = 50;
55
+
56
+ if (newWidth < minWidth) newWidth = minWidth;
57
+ if (newHeight < minHeight) newHeight = minHeight;
58
+
59
+ if (scaleByX) {
60
+ this._ref.width(newWidth);
50
61
  }
51
62
 
52
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
53
- this.setHeight(newHeight);
63
+ if (scaleByY) {
64
+ this._ref.height(newHeight);
54
65
  }
55
66
 
56
67
  this._ref.scale({ x: 1, y: 1 });
@@ -41,16 +41,26 @@ export class KonvaText implements IMarkupText, IMarkupColorable {
41
41
  this._ref.on("transform", (e) => {
42
42
  const attrs = e.target.attrs;
43
43
 
44
- if (attrs.rotation !== this.getRotation()) this.setRotation(attrs.rotation);
44
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
45
45
 
46
- const newWidth = this._ref.width() * attrs.scaleX;
47
- const newHeight = this._ref.height() * attrs.scaleY;
46
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
47
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
48
48
 
49
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
49
+ let newWidth = this._ref.width();
50
+ if (scaleByX) newWidth *= attrs.scaleX;
51
+ let newHeight = this._ref.height();
52
+ if (scaleByY) newHeight *= attrs.scaleY;
53
+
54
+ const minWidth = 50;
55
+
56
+ if (newWidth < minWidth) newWidth = minWidth;
57
+ if (newHeight < Math.round(this.getFontSize())) newHeight = Math.round(this.getFontSize());
58
+
59
+ if (scaleByX) {
50
60
  this._ref.width(newWidth);
51
61
  }
52
62
 
53
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
63
+ if (scaleByY) {
54
64
  this._ref.height(newHeight);
55
65
  }
56
66
 
@@ -41,6 +41,7 @@ export enum MarkupType {
41
41
  * "Text" markup objects are supported.
42
42
  */
43
43
  export enum MarkupMode {
44
+ SelectMarkup = "SelectMarkup",
44
45
  Line = "Line",
45
46
  Text = "Text",
46
47
  Rectangle = "Rectangle",
@@ -55,10 +56,20 @@ export enum MarkupMode {
55
56
  */
56
57
  export interface IMarkup {
57
58
  /**
58
- * Width of the markup object line
59
+ * Width of the markup object line. Default is 4.
59
60
  */
60
61
  lineWidth: number;
61
62
 
63
+ /**
64
+ * Type of the Line markup object. Available types: "solid", "dot", "dash". Default is "solid".
65
+ */
66
+ lineType: string;
67
+
68
+ /**
69
+ * Font size of the markup text. Default is 34.
70
+ */
71
+ fontSize: number;
72
+
62
73
  /**
63
74
  * Start method to init Markup support for the Viewer instance.
64
75
  *
@@ -52,6 +52,13 @@ class KonvaShape {
52
52
 
53
53
  // move to separate class and create factory with enum?
54
54
  const MarkupMode2Konva = new Map<MarkupMode, KonvaShape>([
55
+ [
56
+ MarkupMode.SelectMarkup,
57
+ {
58
+ name: "SelectMarkup",
59
+ initializer: () => {},
60
+ },
61
+ ],
55
62
  [
56
63
  MarkupMode.Line,
57
64
  {
@@ -140,6 +147,8 @@ export class KonvaMarkup implements IMarkup {
140
147
  private readonly _markupContainerName = "markupContainer";
141
148
 
142
149
  public lineWidth = 4;
150
+ public lineType: LineType = "solid";
151
+ public fontSize = 34;
143
152
 
144
153
  initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents: string[] = []): void {
145
154
  if (!Konva)
@@ -261,8 +270,8 @@ export class KonvaMarkup implements IMarkup {
261
270
  const hex = new MarkupColor(r, g, b).HexColor;
262
271
  Object.values(MarkupMode).forEach((mode) => {
263
272
  this.konvaLayerFind(mode).forEach((x) => {
264
- const konvaObj = MarkupMode2Konva.get(mode).initializer(x);
265
- if (konvaObj.setColor) konvaObj.setColor(hex);
273
+ const konvaObj = MarkupMode2Konva.get(mode)?.initializer(x);
274
+ if (konvaObj && konvaObj.setColor) konvaObj.setColor(hex);
266
275
  });
267
276
  });
268
277
 
@@ -500,6 +509,7 @@ export class KonvaMarkup implements IMarkup {
500
509
  const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x) => x.parent instanceof Konva.Layer);
501
510
  return konvaShapes;
502
511
  }
512
+ return [];
503
513
  }
504
514
 
505
515
  private initializeKonva(): any {
@@ -516,6 +526,8 @@ export class KonvaMarkup implements IMarkup {
516
526
 
517
527
  const transformer = new Konva.Transformer({
518
528
  shouldOverdrawWholeArea: false,
529
+ keepRatio: false,
530
+ flipEnabled: false,
519
531
  });
520
532
 
521
533
  this._konvaTransformer = transformer;
@@ -656,7 +668,7 @@ export class KonvaMarkup implements IMarkup {
656
668
  return;
657
669
  }
658
670
 
659
- if (this._markupMode === MarkupMode.Text) {
671
+ if (this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.SelectMarkup) {
660
672
  if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
661
673
  if (this._textInputRef && this._textInputRef.value)
662
674
  this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
@@ -674,7 +686,7 @@ export class KonvaMarkup implements IMarkup {
674
686
  }
675
687
  }
676
688
 
677
- if (this._markupMode === MarkupMode.Image) {
689
+ if (this._markupMode === MarkupMode.Image || this._markupMode === MarkupMode.SelectMarkup) {
678
690
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
679
691
  if (this._imageInputRef && this._imageInputRef.value)
680
692
  this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0);
@@ -765,9 +777,9 @@ export class KonvaMarkup implements IMarkup {
765
777
  lines.push({
766
778
  id: konvaLine.id(),
767
779
  points: worldPoints.map((p) => this.getPoint3dFromArray(p)),
768
- color: konvaLine.getColor() || "ff0000",
769
- type: konvaLine.getLineType() || "solid",
770
- width: konvaLine.getLineWidth() || 3,
780
+ color: konvaLine.getColor() || "#ff0000",
781
+ type: konvaLine.getLineType() || this.lineType,
782
+ width: konvaLine.getLineWidth() || this.lineWidth,
771
783
  });
772
784
  });
773
785
 
@@ -1055,7 +1067,7 @@ export class KonvaMarkup implements IMarkup {
1055
1067
 
1056
1068
  const konvaLine = new KonvaLine({
1057
1069
  points,
1058
- type: type || "solid",
1070
+ type: type || this.lineType,
1059
1071
  width: width || this.lineWidth,
1060
1072
  color: color || this._markupColor.HexColor,
1061
1073
  id,
@@ -1180,7 +1192,7 @@ export class KonvaMarkup implements IMarkup {
1180
1192
  position: { x: position.x, y: position.y },
1181
1193
  text: specifiedText,
1182
1194
  rotation: angle,
1183
- fontSize,
1195
+ fontSize: fontSize || this.fontSize,
1184
1196
  color: color || this._markupColor.HexColor,
1185
1197
  id,
1186
1198
  });
@@ -11,7 +11,9 @@ export class VisualizeMarkup implements IMarkup {
11
11
  private _viewer: Viewer;
12
12
  protected _markupColor = { r: 255, g: 0, b: 0 };
13
13
 
14
- public lineWidth = 0;
14
+ public lineWidth = 4;
15
+ public lineType: "solid";
16
+ public fontSize = 34;
15
17
 
16
18
  initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents: string[]): void {
17
19
  this._viewer = viewer;