@inweb/viewer-visualize 25.9.0 → 25.9.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/dist/viewer-visualize.js +170 -69
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +118 -53
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Viewer.d.ts +53 -17
- package/package.json +5 -5
- package/src/Viewer/Draggers/OdZoomDragger.ts +1 -1
- package/src/Viewer/Viewer.ts +52 -16
|
@@ -766,6 +766,29 @@ async function autoTransformAllModelsToCentralPoint(viewer, model) {
|
|
|
766
766
|
|
|
767
767
|
commands("VisualizeJS").registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint);
|
|
768
768
|
|
|
769
|
+
class WorldTransform {
|
|
770
|
+
screenToWorld(position) {
|
|
771
|
+
return {
|
|
772
|
+
x: position.x,
|
|
773
|
+
y: position.y,
|
|
774
|
+
z: 0
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
worldToScreen(position) {
|
|
778
|
+
return {
|
|
779
|
+
x: position.x,
|
|
780
|
+
y: position.y
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
getScale() {
|
|
784
|
+
return {
|
|
785
|
+
x: 1,
|
|
786
|
+
y: 1,
|
|
787
|
+
z: 1
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
769
792
|
class MarkupColor {
|
|
770
793
|
constructor(r, g, b) {
|
|
771
794
|
this.setColor(r, g, b);
|
|
@@ -795,29 +818,6 @@ class MarkupColor {
|
|
|
795
818
|
}
|
|
796
819
|
}
|
|
797
820
|
|
|
798
|
-
class WorldTransform {
|
|
799
|
-
screenToWorld(position) {
|
|
800
|
-
return {
|
|
801
|
-
x: position.x,
|
|
802
|
-
y: position.y,
|
|
803
|
-
z: 0
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
worldToScreen(position) {
|
|
807
|
-
return {
|
|
808
|
-
x: position.x,
|
|
809
|
-
y: position.y
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
getScale() {
|
|
813
|
-
return {
|
|
814
|
-
x: 1,
|
|
815
|
-
y: 1,
|
|
816
|
-
z: 1
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
|
|
821
821
|
const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
|
|
822
822
|
|
|
823
823
|
class KonvaLine {
|
|
@@ -1770,16 +1770,45 @@ class KonvaMarkup {
|
|
|
1770
1770
|
this._konvaStage.height(height);
|
|
1771
1771
|
};
|
|
1772
1772
|
this.pan = event => {
|
|
1773
|
-
const
|
|
1774
|
-
const
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1773
|
+
const pointer = this._konvaStage.getPointerPosition();
|
|
1774
|
+
const pointTo = {
|
|
1775
|
+
x: (pointer.x - this._konvaStage.x()) / this._konvaStage.scaleX(),
|
|
1776
|
+
y: (pointer.y - this._konvaStage.y()) / this._konvaStage.scaleX()
|
|
1777
|
+
};
|
|
1778
|
+
const newPos = {
|
|
1779
|
+
x: pointer.x - pointTo.x * this._konvaStage.scale().x + event.dX,
|
|
1780
|
+
y: pointer.y - pointTo.y * this._konvaStage.scale().x + event.dY
|
|
1781
|
+
};
|
|
1782
|
+
this._konvaStage.position(newPos);
|
|
1783
|
+
};
|
|
1784
|
+
this.zoomAt = event => {
|
|
1785
|
+
const oldScale = this._konvaStage.scaleX();
|
|
1786
|
+
const pointer = this._konvaStage.getPointerPosition();
|
|
1787
|
+
const mousePointTo = {
|
|
1788
|
+
x: (pointer.x - this._konvaStage.x()) / oldScale,
|
|
1789
|
+
y: (pointer.y - this._konvaStage.y()) / oldScale
|
|
1790
|
+
};
|
|
1791
|
+
let direction = event.data > 0 ? 1 : -1;
|
|
1792
|
+
const newScale = direction > 0 ? oldScale * event.data : oldScale / event.data;
|
|
1793
|
+
this._konvaStage.scale({
|
|
1794
|
+
x: newScale,
|
|
1795
|
+
y: newScale
|
|
1796
|
+
});
|
|
1797
|
+
const newPos = {
|
|
1798
|
+
x: pointer.x - mousePointTo.x * newScale,
|
|
1799
|
+
y: pointer.y - mousePointTo.y * newScale
|
|
1800
|
+
};
|
|
1801
|
+
this._konvaStage.position(newPos);
|
|
1779
1802
|
};
|
|
1780
1803
|
this.redirectToViewer = event => {
|
|
1781
1804
|
if (this._viewer) this._viewer.emit(event);
|
|
1782
1805
|
};
|
|
1806
|
+
this.getRelativePointPosition = (point, node) => {
|
|
1807
|
+
const transform = node.getAbsoluteTransform().copy();
|
|
1808
|
+
transform.invert();
|
|
1809
|
+
return transform.point(point);
|
|
1810
|
+
};
|
|
1811
|
+
this.getRelativePointerPosition = node => this.getRelativePointPosition(node.getStage().getPointerPosition(), node);
|
|
1783
1812
|
}
|
|
1784
1813
|
initialize(container, containerEvents, viewer, worldTransformer) {
|
|
1785
1814
|
if (!Konva) throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"><\/script> to your page?');
|
|
@@ -1803,11 +1832,13 @@ class KonvaMarkup {
|
|
|
1803
1832
|
this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
1804
1833
|
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1805
1834
|
this._viewer.addEventListener("pan", this.pan);
|
|
1835
|
+
this._viewer.addEventListener("zoomat", this.zoomAt);
|
|
1806
1836
|
}
|
|
1807
1837
|
}
|
|
1808
1838
|
dispose() {
|
|
1809
1839
|
var _a, _b;
|
|
1810
1840
|
if (this._viewer) {
|
|
1841
|
+
this._viewer.removeEventListener("zoomat", this.zoomAt);
|
|
1811
1842
|
this._viewer.removeEventListener("pan", this.pan);
|
|
1812
1843
|
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
1813
1844
|
this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
@@ -1854,6 +1885,14 @@ class KonvaMarkup {
|
|
|
1854
1885
|
this.clearSelected();
|
|
1855
1886
|
this.removeTextInput();
|
|
1856
1887
|
this.removeImageInput();
|
|
1888
|
+
this._konvaStage.scale({
|
|
1889
|
+
x: 1,
|
|
1890
|
+
y: 1
|
|
1891
|
+
});
|
|
1892
|
+
this._konvaStage.position({
|
|
1893
|
+
x: 0,
|
|
1894
|
+
y: 0
|
|
1895
|
+
});
|
|
1857
1896
|
const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
|
|
1858
1897
|
r: 255,
|
|
1859
1898
|
g: 0,
|
|
@@ -2000,7 +2039,7 @@ class KonvaMarkup {
|
|
|
2000
2039
|
transformer.nodes([]);
|
|
2001
2040
|
return;
|
|
2002
2041
|
}
|
|
2003
|
-
const pos =
|
|
2042
|
+
const pos = this.getRelativePointerPosition(stage);
|
|
2004
2043
|
mouseDownPos = pos;
|
|
2005
2044
|
isPaint = [ "Arrow", "Cloud", "Ellipse", "Line", "Rectangle" ].some((m => m === this._markupMode));
|
|
2006
2045
|
if (this._markupMode === "Line") {
|
|
@@ -2010,7 +2049,7 @@ class KonvaMarkup {
|
|
|
2010
2049
|
stage.on("mouseup touchend", (e => {
|
|
2011
2050
|
if (!this._markupIsActive) return;
|
|
2012
2051
|
if (isPaint) {
|
|
2013
|
-
const pos =
|
|
2052
|
+
const pos = this.getRelativePointerPosition(stage);
|
|
2014
2053
|
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
2015
2054
|
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
2016
2055
|
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
@@ -2054,7 +2093,7 @@ class KonvaMarkup {
|
|
|
2054
2093
|
if (!isPaint) {
|
|
2055
2094
|
return;
|
|
2056
2095
|
}
|
|
2057
|
-
const pos =
|
|
2096
|
+
const pos = this.getRelativePointerPosition(stage);
|
|
2058
2097
|
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
2059
2098
|
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
2060
2099
|
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
@@ -2110,7 +2149,7 @@ class KonvaMarkup {
|
|
|
2110
2149
|
if (e.target === stage) {
|
|
2111
2150
|
if (this._markupMode === "Text") {
|
|
2112
2151
|
if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
|
|
2113
|
-
const pos =
|
|
2152
|
+
const pos = this.getRelativePointerPosition(stage);
|
|
2114
2153
|
this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
|
|
2115
2154
|
}
|
|
2116
2155
|
} else if (this._markupMode === "Image") {
|
|
@@ -2118,7 +2157,7 @@ class KonvaMarkup {
|
|
|
2118
2157
|
x: this._imageInputPos.x,
|
|
2119
2158
|
y: this._imageInputPos.y
|
|
2120
2159
|
}, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
|
|
2121
|
-
const pos =
|
|
2160
|
+
const pos = this.getRelativePointerPosition(stage);
|
|
2122
2161
|
this.createImageInput(pos);
|
|
2123
2162
|
}
|
|
2124
2163
|
}
|
|
@@ -2223,11 +2262,13 @@ class KonvaMarkup {
|
|
|
2223
2262
|
this.konvaLayerFind("Text").forEach((ref => {
|
|
2224
2263
|
const textSize = .02;
|
|
2225
2264
|
const textScale = this._worldTransformer.getScale();
|
|
2226
|
-
const position =
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2265
|
+
const position = ref.position();
|
|
2266
|
+
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2267
|
+
const atPoint = stageAbsoluteTransform.point({
|
|
2268
|
+
x: position.x,
|
|
2269
|
+
y: position.y
|
|
2270
|
+
});
|
|
2271
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2231
2272
|
const shape = new KonvaText(null, ref);
|
|
2232
2273
|
const text = {
|
|
2233
2274
|
id: shape.id(),
|
|
@@ -2236,7 +2277,7 @@ class KonvaMarkup {
|
|
|
2236
2277
|
text_size: textSize * textScale.y,
|
|
2237
2278
|
angle: shape.getRotation(),
|
|
2238
2279
|
color: shape.getColor(),
|
|
2239
|
-
font_size: shape.getFontSize()
|
|
2280
|
+
font_size: shape.getFontSize() * stageAbsoluteTransform.getMatrix()[0]
|
|
2240
2281
|
};
|
|
2241
2282
|
texts.push(text);
|
|
2242
2283
|
}));
|
|
@@ -2246,13 +2287,19 @@ class KonvaMarkup {
|
|
|
2246
2287
|
const rectangles = [];
|
|
2247
2288
|
this.konvaLayerFind("Rectangle").forEach((ref => {
|
|
2248
2289
|
const position = ref.position();
|
|
2249
|
-
const
|
|
2290
|
+
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2291
|
+
const atPoint = stageAbsoluteTransform.point({
|
|
2292
|
+
x: position.x,
|
|
2293
|
+
y: position.y
|
|
2294
|
+
});
|
|
2295
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2296
|
+
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2250
2297
|
const shape = new KonvaRectangle(null, ref);
|
|
2251
2298
|
const rectangle = {
|
|
2252
2299
|
id: shape.id(),
|
|
2253
2300
|
position: worldPoint,
|
|
2254
|
-
width: shape.getWidth(),
|
|
2255
|
-
height: shape.getHeigth(),
|
|
2301
|
+
width: shape.getWidth() * scale,
|
|
2302
|
+
height: shape.getHeigth() * scale,
|
|
2256
2303
|
line_width: shape.getLineWidth(),
|
|
2257
2304
|
color: shape.getColor()
|
|
2258
2305
|
};
|
|
@@ -2264,14 +2311,20 @@ class KonvaMarkup {
|
|
|
2264
2311
|
const ellipses = [];
|
|
2265
2312
|
this.konvaLayerFind("Ellipse").forEach((ref => {
|
|
2266
2313
|
const position = ref.position();
|
|
2267
|
-
const
|
|
2314
|
+
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2315
|
+
const atPoint = stageAbsoluteTransform.point({
|
|
2316
|
+
x: position.x,
|
|
2317
|
+
y: position.y
|
|
2318
|
+
});
|
|
2319
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2320
|
+
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2268
2321
|
const shape = new KonvaEllipse(null, ref);
|
|
2269
2322
|
const ellipse = {
|
|
2270
2323
|
id: shape.id(),
|
|
2271
2324
|
position: worldPoint,
|
|
2272
2325
|
radius: {
|
|
2273
|
-
x: ref.getRadiusX(),
|
|
2274
|
-
y: ref.getRadiusY()
|
|
2326
|
+
x: ref.getRadiusX() * scale,
|
|
2327
|
+
y: ref.getRadiusY() * scale
|
|
2275
2328
|
},
|
|
2276
2329
|
line_width: shape.getLineWidth(),
|
|
2277
2330
|
color: shape.getColor()
|
|
@@ -2309,14 +2362,20 @@ class KonvaMarkup {
|
|
|
2309
2362
|
const images = [];
|
|
2310
2363
|
this.konvaLayerFind("Image").forEach((ref => {
|
|
2311
2364
|
const position = ref.position();
|
|
2312
|
-
const
|
|
2365
|
+
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2366
|
+
const atPoint = stageAbsoluteTransform.point({
|
|
2367
|
+
x: position.x,
|
|
2368
|
+
y: position.y
|
|
2369
|
+
});
|
|
2370
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2371
|
+
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2313
2372
|
const shape = new KonvaImage(null, ref);
|
|
2314
2373
|
const image = {
|
|
2315
2374
|
id: shape.id(),
|
|
2316
2375
|
position: worldPoint,
|
|
2317
2376
|
src: shape.getSrc(),
|
|
2318
|
-
width: shape.getWidth(),
|
|
2319
|
-
height: shape.getHeight()
|
|
2377
|
+
width: shape.getWidth() * scale,
|
|
2378
|
+
height: shape.getHeight() * scale
|
|
2320
2379
|
};
|
|
2321
2380
|
images.push(image);
|
|
2322
2381
|
}));
|
|
@@ -2326,13 +2385,19 @@ class KonvaMarkup {
|
|
|
2326
2385
|
const clouds = [];
|
|
2327
2386
|
this.konvaLayerFind("Cloud").forEach((ref => {
|
|
2328
2387
|
const position = ref.position();
|
|
2329
|
-
const
|
|
2388
|
+
const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
|
|
2389
|
+
const atPoint = stageAbsoluteTransform.point({
|
|
2390
|
+
x: position.x,
|
|
2391
|
+
y: position.y
|
|
2392
|
+
});
|
|
2393
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
2394
|
+
const scale = stageAbsoluteTransform.getMatrix()[0];
|
|
2330
2395
|
const shape = new KonvaCloud(null, ref);
|
|
2331
2396
|
const cloud = {
|
|
2332
2397
|
id: shape.id(),
|
|
2333
2398
|
position: worldPoint,
|
|
2334
|
-
width: shape.getWidth(),
|
|
2335
|
-
height: shape.getHeigth(),
|
|
2399
|
+
width: shape.getWidth() * scale,
|
|
2400
|
+
height: shape.getHeigth() * scale,
|
|
2336
2401
|
line_width: shape.getLineWidth(),
|
|
2337
2402
|
color: shape.getColor()
|
|
2338
2403
|
};
|
|
@@ -3937,7 +4002,7 @@ class OdZoomDragger extends OdBaseDragger {
|
|
|
3937
4002
|
this.beginInteractivity();
|
|
3938
4003
|
}
|
|
3939
4004
|
drag(x, y, dltX, dltY) {
|
|
3940
|
-
if (this.press && Math.abs(dltY)
|
|
4005
|
+
if (this.press && Math.abs(dltY) >= 1e-5) {
|
|
3941
4006
|
const ZOOM_SPEED = .025;
|
|
3942
4007
|
const zoomFactor = dltY > 0 ? 1 + ZOOM_SPEED : 1 - ZOOM_SPEED;
|
|
3943
4008
|
this._zoomAction.action(this.pressX, this.pressY, zoomFactor);
|