@inweb/viewer-visualize 25.7.10 → 25.8.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.
|
@@ -734,6 +734,29 @@ class MarkupColor {
|
|
|
734
734
|
}
|
|
735
735
|
}
|
|
736
736
|
|
|
737
|
+
class WorldTransform {
|
|
738
|
+
screenToWorld(position) {
|
|
739
|
+
return {
|
|
740
|
+
x: position.x,
|
|
741
|
+
y: position.y,
|
|
742
|
+
z: 0
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
worldToScreen(position) {
|
|
746
|
+
return {
|
|
747
|
+
x: position.x,
|
|
748
|
+
y: position.y
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
getScale() {
|
|
752
|
+
return {
|
|
753
|
+
x: 1,
|
|
754
|
+
y: 1,
|
|
755
|
+
z: 1
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
737
760
|
const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
|
|
738
761
|
|
|
739
762
|
class KonvaLine {
|
|
@@ -1571,31 +1594,37 @@ const MarkupMode2Konva = {
|
|
|
1571
1594
|
},
|
|
1572
1595
|
Line: {
|
|
1573
1596
|
name: "Line",
|
|
1574
|
-
initializer: ref => new KonvaLine(
|
|
1597
|
+
initializer: (ref, params = null) => new KonvaLine(params, ref),
|
|
1598
|
+
zIndex: 1
|
|
1575
1599
|
},
|
|
1576
1600
|
Text: {
|
|
1577
1601
|
name: "Text",
|
|
1578
|
-
initializer: ref => new KonvaText(
|
|
1602
|
+
initializer: (ref, params = null) => new KonvaText(params, ref)
|
|
1579
1603
|
},
|
|
1580
1604
|
Rectangle: {
|
|
1581
1605
|
name: "Rect",
|
|
1582
|
-
initializer: ref => new KonvaRectangle(
|
|
1606
|
+
initializer: (ref, params = null) => new KonvaRectangle(params, ref),
|
|
1607
|
+
zIndex: 1
|
|
1583
1608
|
},
|
|
1584
1609
|
Ellipse: {
|
|
1585
1610
|
name: "Ellipse",
|
|
1586
|
-
initializer: ref => new KonvaEllipse(
|
|
1611
|
+
initializer: (ref, params = null) => new KonvaEllipse(params, ref),
|
|
1612
|
+
zIndex: 1
|
|
1587
1613
|
},
|
|
1588
1614
|
Arrow: {
|
|
1589
1615
|
name: "Arrow",
|
|
1590
|
-
initializer: ref => new KonvaArrow(
|
|
1616
|
+
initializer: (ref, params = null) => new KonvaArrow(params, ref),
|
|
1617
|
+
zIndex: 1
|
|
1591
1618
|
},
|
|
1592
1619
|
Image: {
|
|
1593
1620
|
name: "Image",
|
|
1594
|
-
initializer: ref => new KonvaImage(
|
|
1621
|
+
initializer: (ref, params = null) => new KonvaImage(params, ref),
|
|
1622
|
+
zIndex: 0
|
|
1595
1623
|
},
|
|
1596
1624
|
Cloud: {
|
|
1597
1625
|
name: "Cloud",
|
|
1598
|
-
initializer: ref => new KonvaCloud(null, ref)
|
|
1626
|
+
initializer: ref => new KonvaCloud(null, ref),
|
|
1627
|
+
zIndex: 1
|
|
1599
1628
|
}
|
|
1600
1629
|
};
|
|
1601
1630
|
|
|
@@ -1626,10 +1655,10 @@ class KonvaMarkup {
|
|
|
1626
1655
|
this.pan = event => {
|
|
1627
1656
|
const dX = event.dX / window.devicePixelRatio;
|
|
1628
1657
|
const dY = event.dY / window.devicePixelRatio;
|
|
1629
|
-
|
|
1658
|
+
this.getObjects().forEach((obj => obj.ref().move({
|
|
1630
1659
|
x: dX,
|
|
1631
1660
|
y: dY
|
|
1632
|
-
})))
|
|
1661
|
+
})));
|
|
1633
1662
|
};
|
|
1634
1663
|
this.redirectToViewer = event => {
|
|
1635
1664
|
if (this._viewer) this._viewer.emit(event);
|
|
@@ -1638,7 +1667,7 @@ class KonvaMarkup {
|
|
|
1638
1667
|
initialize(container, pointerEvents, viewer, worldTransformer) {
|
|
1639
1668
|
if (!Konva) throw new Error('Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
|
|
1640
1669
|
this._viewer = viewer;
|
|
1641
|
-
this._worldTransformer = worldTransformer;
|
|
1670
|
+
this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
|
|
1642
1671
|
this._container = container;
|
|
1643
1672
|
this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
|
|
1644
1673
|
this._markupContainer = document.createElement("div");
|
|
@@ -1682,8 +1711,8 @@ class KonvaMarkup {
|
|
|
1682
1711
|
clearOverlay() {
|
|
1683
1712
|
this.removeTextInput();
|
|
1684
1713
|
this.removeImageInput();
|
|
1685
|
-
this.
|
|
1686
|
-
|
|
1714
|
+
this.clearSelected();
|
|
1715
|
+
this.getObjects().forEach((obj => obj.ref().destroy()));
|
|
1687
1716
|
}
|
|
1688
1717
|
getMarkupColor() {
|
|
1689
1718
|
return this._markupColor.RGB;
|
|
@@ -1691,23 +1720,19 @@ class KonvaMarkup {
|
|
|
1691
1720
|
setMarkupColor(r, g, b) {
|
|
1692
1721
|
this._markupColor.setColor(r, g, b);
|
|
1693
1722
|
}
|
|
1694
|
-
colorizeAllMarkup(r
|
|
1695
|
-
const
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const konvaObj = konvaShape.initializer(ref);
|
|
1700
|
-
if (konvaObj.setColor) konvaObj.setColor(hex);
|
|
1701
|
-
}));
|
|
1723
|
+
colorizeAllMarkup(r, g, b) {
|
|
1724
|
+
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
1725
|
+
this.getObjects().forEach((obj => {
|
|
1726
|
+
const colorable = obj;
|
|
1727
|
+
if (colorable && colorable.setColor) colorable.setColor(hexColor);
|
|
1702
1728
|
}));
|
|
1703
1729
|
this._konvaLayer.draw();
|
|
1704
1730
|
}
|
|
1705
1731
|
colorizeSelectedMarkups(r, g, b) {
|
|
1732
|
+
const hexColor = new MarkupColor(r, g, b).HexColor;
|
|
1706
1733
|
this.getSelectedObjects().forEach((obj => {
|
|
1707
1734
|
const colorable = obj;
|
|
1708
|
-
if (colorable && colorable.setColor)
|
|
1709
|
-
colorable.setColor(new MarkupColor(r, g, b).HexColor);
|
|
1710
|
-
}
|
|
1735
|
+
if (colorable && colorable.setColor) colorable.setColor(hexColor);
|
|
1711
1736
|
}));
|
|
1712
1737
|
}
|
|
1713
1738
|
setViewpoint(viewpoint) {
|
|
@@ -1750,110 +1775,29 @@ class KonvaMarkup {
|
|
|
1750
1775
|
return this;
|
|
1751
1776
|
}
|
|
1752
1777
|
createObject(type, params) {
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
object = new KonvaLine(params);
|
|
1758
|
-
zIndex = 1;
|
|
1759
|
-
break;
|
|
1760
|
-
|
|
1761
|
-
case "text":
|
|
1762
|
-
object = new KonvaText(params);
|
|
1763
|
-
break;
|
|
1764
|
-
|
|
1765
|
-
case "rectangle":
|
|
1766
|
-
object = new KonvaRectangle(params);
|
|
1767
|
-
zIndex = 1;
|
|
1768
|
-
break;
|
|
1769
|
-
|
|
1770
|
-
case "ellipse":
|
|
1771
|
-
object = new KonvaEllipse(params);
|
|
1772
|
-
zIndex = 1;
|
|
1773
|
-
break;
|
|
1774
|
-
|
|
1775
|
-
case "arrow":
|
|
1776
|
-
object = new KonvaArrow(params);
|
|
1777
|
-
break;
|
|
1778
|
-
|
|
1779
|
-
case "image":
|
|
1780
|
-
object = new KonvaImage(params);
|
|
1781
|
-
zIndex = 0;
|
|
1782
|
-
break;
|
|
1783
|
-
|
|
1784
|
-
case "cloud":
|
|
1785
|
-
object = new KonvaCloud(params);
|
|
1786
|
-
zIndex = 1;
|
|
1787
|
-
break;
|
|
1788
|
-
|
|
1789
|
-
default:
|
|
1790
|
-
throw new Error("Markup CreateObject - unsupported type has been detected.");
|
|
1791
|
-
}
|
|
1778
|
+
var _a;
|
|
1779
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
1780
|
+
if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
|
|
1781
|
+
const object = konvaShape.initializer(null, params);
|
|
1792
1782
|
this.addObject(object);
|
|
1793
|
-
object.setZIndex(zIndex);
|
|
1783
|
+
object.setZIndex((_a = konvaShape.zIndex) !== null && _a !== void 0 ? _a : this._zIndex);
|
|
1794
1784
|
this._zIndex++;
|
|
1795
1785
|
return object;
|
|
1796
1786
|
}
|
|
1797
1787
|
getObjects() {
|
|
1798
1788
|
const objects = [];
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
this.konvaLayerFind("Text").forEach((text => {
|
|
1803
|
-
objects.push(new KonvaText(null, text));
|
|
1804
|
-
}));
|
|
1805
|
-
this.konvaLayerFind("Rectangle").forEach((rectangle => {
|
|
1806
|
-
objects.push(new KonvaRectangle(null, rectangle));
|
|
1807
|
-
}));
|
|
1808
|
-
this.konvaLayerFind("Ellipse").forEach((ellipse => {
|
|
1809
|
-
objects.push(new KonvaEllipse(null, ellipse));
|
|
1810
|
-
}));
|
|
1811
|
-
this.konvaLayerFind("Arrow").forEach((arrow => {
|
|
1812
|
-
objects.push(new KonvaArrow(null, arrow));
|
|
1813
|
-
}));
|
|
1814
|
-
this.konvaLayerFind("Image").forEach((image => {
|
|
1815
|
-
objects.push(new KonvaImage(null, image));
|
|
1816
|
-
}));
|
|
1817
|
-
this.konvaLayerFind("Cloud").forEach((cloud => {
|
|
1818
|
-
objects.push(new KonvaCloud(null, cloud));
|
|
1789
|
+
Object.keys(MarkupMode2Konva).forEach((type => {
|
|
1790
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
1791
|
+
this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
|
|
1819
1792
|
}));
|
|
1820
1793
|
return objects;
|
|
1821
1794
|
}
|
|
1822
1795
|
getSelectedObjects() {
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
objects.push(new KonvaLine(null, obj));
|
|
1829
|
-
break;
|
|
1830
|
-
|
|
1831
|
-
case "Text":
|
|
1832
|
-
objects.push(new KonvaText(null, obj));
|
|
1833
|
-
break;
|
|
1834
|
-
|
|
1835
|
-
case "Rect":
|
|
1836
|
-
objects.push(new KonvaRectangle(null, obj));
|
|
1837
|
-
break;
|
|
1838
|
-
|
|
1839
|
-
case "Ellipse":
|
|
1840
|
-
objects.push(new KonvaEllipse(null, obj));
|
|
1841
|
-
break;
|
|
1842
|
-
|
|
1843
|
-
case "Arrow":
|
|
1844
|
-
objects.push(new KonvaArrow(null, obj));
|
|
1845
|
-
break;
|
|
1846
|
-
|
|
1847
|
-
case "Image":
|
|
1848
|
-
objects.push(new KonvaImage(null, obj));
|
|
1849
|
-
break;
|
|
1850
|
-
|
|
1851
|
-
case "Cloud":
|
|
1852
|
-
objects.push(new KonvaCloud(null, obj));
|
|
1853
|
-
break;
|
|
1854
|
-
}
|
|
1855
|
-
}));
|
|
1856
|
-
return objects;
|
|
1796
|
+
return this._konvaTransformer.nodes().map((ref => {
|
|
1797
|
+
const name = ref.className;
|
|
1798
|
+
const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
|
|
1799
|
+
return konvaShape ? konvaShape.initializer(ref) : null;
|
|
1800
|
+
})).filter((x => x));
|
|
1857
1801
|
}
|
|
1858
1802
|
selectObjects(objects) {
|
|
1859
1803
|
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
@@ -1862,13 +1806,6 @@ class KonvaMarkup {
|
|
|
1862
1806
|
clearSelected() {
|
|
1863
1807
|
this._konvaTransformer.nodes([]);
|
|
1864
1808
|
}
|
|
1865
|
-
getPoint3dFromArray(array) {
|
|
1866
|
-
return {
|
|
1867
|
-
x: array[0],
|
|
1868
|
-
y: array[1],
|
|
1869
|
-
z: array[2]
|
|
1870
|
-
};
|
|
1871
|
-
}
|
|
1872
1809
|
fillViewpointShapes(viewpoint) {
|
|
1873
1810
|
const markupLines = this.getMarkupLines();
|
|
1874
1811
|
if (markupLines && markupLines.length > 0) {
|
|
@@ -1916,8 +1853,8 @@ class KonvaMarkup {
|
|
|
1916
1853
|
addObject(object) {
|
|
1917
1854
|
this._konvaLayer.add(object.ref());
|
|
1918
1855
|
}
|
|
1919
|
-
konvaLayerFind(
|
|
1920
|
-
const konvaShape = MarkupMode2Konva[
|
|
1856
|
+
konvaLayerFind(type) {
|
|
1857
|
+
const konvaShape = MarkupMode2Konva[type];
|
|
1921
1858
|
if (konvaShape && konvaShape.initializer) {
|
|
1922
1859
|
return this._konvaLayer.find(konvaShape.name).filter((ref => ref.parent === this._konvaLayer));
|
|
1923
1860
|
}
|
|
@@ -2159,7 +2096,7 @@ class KonvaMarkup {
|
|
|
2159
2096
|
const konvaLine = new KonvaLine(null, line);
|
|
2160
2097
|
lines.push({
|
|
2161
2098
|
id: konvaLine.id(),
|
|
2162
|
-
points: worldPoints
|
|
2099
|
+
points: worldPoints,
|
|
2163
2100
|
color: konvaLine.getColor() || "#ff0000",
|
|
2164
2101
|
type: konvaLine.getLineType() || this.lineType,
|
|
2165
2102
|
width: konvaLine.getLineWidth() || this.lineWidth
|
|
@@ -2173,14 +2110,15 @@ class KonvaMarkup {
|
|
|
2173
2110
|
const textScale = this._worldTransformer.getScale();
|
|
2174
2111
|
this.konvaLayerFind("Text").forEach((text => {
|
|
2175
2112
|
if (!text) return;
|
|
2176
|
-
const position =
|
|
2113
|
+
const position = {
|
|
2177
2114
|
x: text.x(),
|
|
2178
2115
|
y: text.y()
|
|
2179
|
-
}
|
|
2116
|
+
};
|
|
2117
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
2180
2118
|
const shape = new KonvaText(null, text);
|
|
2181
2119
|
texts.push({
|
|
2182
2120
|
id: shape.id(),
|
|
2183
|
-
position:
|
|
2121
|
+
position: worldPoint,
|
|
2184
2122
|
text: shape.getText(),
|
|
2185
2123
|
text_size: textSize * textScale.y,
|
|
2186
2124
|
angle: shape.getRotation(),
|
|
@@ -2198,7 +2136,7 @@ class KonvaMarkup {
|
|
|
2198
2136
|
const shape = new KonvaRectangle(null, rect);
|
|
2199
2137
|
rectangles.push({
|
|
2200
2138
|
id: shape.id(),
|
|
2201
|
-
position:
|
|
2139
|
+
position: worldPoint,
|
|
2202
2140
|
width: shape.getWidth(),
|
|
2203
2141
|
height: shape.getHeigth(),
|
|
2204
2142
|
line_width: shape.getLineWidth(),
|
|
@@ -2215,7 +2153,7 @@ class KonvaMarkup {
|
|
|
2215
2153
|
const shape = new KonvaEllipse(null, ellipse);
|
|
2216
2154
|
ellipses.push({
|
|
2217
2155
|
id: shape.id(),
|
|
2218
|
-
position:
|
|
2156
|
+
position: worldPoint,
|
|
2219
2157
|
radius: {
|
|
2220
2158
|
x: ellipse.getRadiusX(),
|
|
2221
2159
|
y: ellipse.getRadiusY()
|
|
@@ -2243,8 +2181,8 @@ class KonvaMarkup {
|
|
|
2243
2181
|
const shape = new KonvaArrow(null, arrow);
|
|
2244
2182
|
arrows.push({
|
|
2245
2183
|
id: shape.id(),
|
|
2246
|
-
start:
|
|
2247
|
-
end:
|
|
2184
|
+
start: worldStartPoint,
|
|
2185
|
+
end: worldEndPoint,
|
|
2248
2186
|
color: shape.getColor()
|
|
2249
2187
|
});
|
|
2250
2188
|
}));
|
|
@@ -2258,7 +2196,7 @@ class KonvaMarkup {
|
|
|
2258
2196
|
const shape = new KonvaImage(null, image);
|
|
2259
2197
|
images.push({
|
|
2260
2198
|
id: shape.id(),
|
|
2261
|
-
position:
|
|
2199
|
+
position: worldPoint,
|
|
2262
2200
|
src: shape.getSrc(),
|
|
2263
2201
|
width: shape.getWidth(),
|
|
2264
2202
|
height: shape.getHeight()
|
|
@@ -2274,7 +2212,7 @@ class KonvaMarkup {
|
|
|
2274
2212
|
const shape = new KonvaCloud(null, cloud);
|
|
2275
2213
|
clouds.push({
|
|
2276
2214
|
id: shape.id(),
|
|
2277
|
-
position:
|
|
2215
|
+
position: worldPoint,
|
|
2278
2216
|
width: shape.getWidth(),
|
|
2279
2217
|
height: shape.getHeigth(),
|
|
2280
2218
|
line_width: shape.getLineWidth(),
|