@labelbee/lb-annotation 1.8.0 → 1.8.1-alpha.0

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.
Files changed (88) hide show
  1. package/dist/index.js +9 -9
  2. package/dist/types/core/toolOperation/ViewOperation.d.ts +31 -0
  3. package/dist/types/utils/MathUtils.d.ts +3 -0
  4. package/dist/types/utils/tool/DrawUtils.d.ts +14 -13
  5. package/es/.DS_Store +0 -0
  6. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +1 -0
  7. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +1 -0
  8. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -0
  9. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +1 -0
  10. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +2 -0
  11. package/es/_virtual/filterBoxWorker.js +1 -0
  12. package/es/_virtual/highlightWorker.js +1 -0
  13. package/es/_virtual/worker.js +6 -0
  14. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
  15. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
  16. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
  17. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
  18. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
  19. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
  20. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
  21. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
  22. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
  23. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
  24. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
  25. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
  26. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
  27. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
  28. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
  29. package/es/constant/annotation.js +68 -0
  30. package/es/constant/annotationTask.js +25 -0
  31. package/es/constant/defaultConfig.js +260 -0
  32. package/es/constant/keyCode.js +36 -0
  33. package/es/constant/style.js +67 -0
  34. package/es/constant/tool.js +181 -0
  35. package/es/core/index.js +134 -0
  36. package/es/core/pointCloud/OrbitControls.js +1 -0
  37. package/es/core/pointCloud/PCDLoader.js +2 -0
  38. package/es/core/pointCloud/annotation.js +1 -0
  39. package/es/core/pointCloud/cache.js +1 -0
  40. package/es/core/pointCloud/index.js +11 -0
  41. package/es/core/scheduler.js +1 -0
  42. package/es/core/toolOperation/LineToolOperation.js +1369 -0
  43. package/es/core/toolOperation/TextToolOperation.js +129 -0
  44. package/es/core/toolOperation/ViewOperation.js +414 -0
  45. package/es/core/toolOperation/basicToolOperation.js +796 -0
  46. package/es/core/toolOperation/checkOperation.js +206 -0
  47. package/es/core/toolOperation/eventListener.js +35 -0
  48. package/es/core/toolOperation/measureOperation.js +39 -0
  49. package/es/core/toolOperation/pointCloud2dOperation.js +1 -0
  50. package/es/core/toolOperation/pointOperation.js +603 -0
  51. package/es/core/toolOperation/polygonOperation.js +1160 -0
  52. package/es/core/toolOperation/rectOperation.js +1166 -0
  53. package/es/core/toolOperation/segmentByRect.js +1 -0
  54. package/es/core/toolOperation/tagOperation.js +215 -0
  55. package/es/core/toolOperation/textAttributeClass.js +201 -0
  56. package/es/index.js +13 -13
  57. package/es/locales/constants.js +21 -0
  58. package/es/locales/en_US/message.js +22 -0
  59. package/es/locales/index.js +17 -0
  60. package/es/locales/zh_CN/message.js +22 -0
  61. package/es/newCore/CanvasScheduler.js +1 -0
  62. package/es/utils/ActionsHistory.js +78 -0
  63. package/es/utils/ImgUtils.js +20 -0
  64. package/es/utils/MathUtils.js +339 -0
  65. package/es/utils/VectorUtils.js +23 -0
  66. package/es/utils/tool/AttributeUtils.js +196 -0
  67. package/es/utils/tool/AxisUtils.js +254 -0
  68. package/es/utils/tool/CanvasUtils.js +60 -0
  69. package/es/utils/tool/CommonToolUtils.js +201 -0
  70. package/es/utils/tool/CurrentOperation.js +35 -0
  71. package/es/utils/tool/DblClickEventListener.js +100 -0
  72. package/es/utils/tool/DrawUtils.js +424 -0
  73. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -0
  74. package/es/utils/tool/ImgPosUtils.js +56 -0
  75. package/es/utils/tool/LineToolUtils.js +255 -0
  76. package/es/utils/tool/MarkerUtils.js +9 -0
  77. package/es/utils/tool/PolygonUtils.js +453 -0
  78. package/es/utils/tool/RectUtils.js +153 -0
  79. package/es/utils/tool/RenderDomClass.js +68 -0
  80. package/es/utils/tool/RenderDomUtils.js +29 -0
  81. package/es/utils/tool/StyleUtils.js +29 -0
  82. package/es/utils/tool/TagUtils.js +127 -0
  83. package/es/utils/tool/UnitUtils.js +10 -0
  84. package/es/utils/tool/ZoomUtils.js +70 -0
  85. package/es/utils/tool/polygonTool.js +126 -0
  86. package/es/utils/uuid.js +24 -0
  87. package/package.json +2 -3
  88. package/LICENSE +0 -203
@@ -0,0 +1,453 @@
1
+ import { polygon, difference, union } from '@turf/turf';
2
+ import { ERotateDirection } from '../../constant/annotation.js';
3
+ import CommonToolUtils from './CommonToolUtils.js';
4
+ import { ELineTypes, SEGMENT_NUMBER } from '../../constant/tool.js';
5
+ import AxisUtils from './AxisUtils.js';
6
+ import MathUtils from '../MathUtils.js';
7
+ import LineToolUtils from './LineToolUtils.js';
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ class PolygonUtils {
26
+ static getHoverPolygonID(checkPoint, polygonPoints, scope = 3, lineType = ELineTypes.Line) {
27
+ let hoverPolygonID = "";
28
+ let minSize = Infinity;
29
+ const axisList = AxisUtils.axisArea(checkPoint, scope);
30
+ polygonPoints.forEach((p) => {
31
+ if (p.pointList) {
32
+ axisList.forEach((v) => {
33
+ const size = this.calcPolygonSize(p.pointList);
34
+ if (this.isInPolygon(v, p.pointList, lineType) && size < minSize) {
35
+ hoverPolygonID = p.id;
36
+ minSize = size;
37
+ }
38
+ });
39
+ }
40
+ });
41
+ return hoverPolygonID;
42
+ }
43
+ static calcPolygonSize(pointList = []) {
44
+ if ((pointList == null ? void 0 : pointList.length) <= 2) {
45
+ return 0;
46
+ }
47
+ const len = pointList.length;
48
+ const size = pointList.reduce((acc, cur, index, src) => {
49
+ const nextVal = src[(index + 1) % len];
50
+ return acc + cur.x * nextVal.y - nextVal.x * cur.y;
51
+ }, 0);
52
+ return Math.abs(size) / 2;
53
+ }
54
+ static isInPolygon(checkPoint, polygonPoints, lineType = ELineTypes.Line) {
55
+ let counter = 0;
56
+ let i;
57
+ let xinters;
58
+ let p1;
59
+ let p2;
60
+ polygonPoints = [...polygonPoints];
61
+ if (lineType === ELineTypes.Curve) {
62
+ polygonPoints = this.createSmoothCurvePoints(polygonPoints.reduce((acc, cur) => {
63
+ return [...acc, cur.x, cur.y];
64
+ }, []), 0.5, true, 20);
65
+ }
66
+ [p1] = polygonPoints;
67
+ const pointCount = polygonPoints.length;
68
+ for (i = 1; i <= pointCount; i++) {
69
+ p2 = polygonPoints[i % pointCount];
70
+ if (checkPoint.x > Math.min(p1.x, p2.x) && checkPoint.x <= Math.max(p1.x, p2.x)) {
71
+ if (checkPoint.y <= Math.max(p1.y, p2.y)) {
72
+ if (p1.x !== p2.x) {
73
+ xinters = (checkPoint.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
74
+ if (p1.y === p2.y || checkPoint.y <= xinters) {
75
+ counter++;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ p1 = p2;
81
+ }
82
+ if (counter % 2 === 0) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ static createSmoothCurvePointsFromPointList(pointList, numberOfSegments = SEGMENT_NUMBER) {
88
+ const newPoints = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
89
+ return [...acc, cur.x, cur.y];
90
+ }, []), 0.5, false, numberOfSegments);
91
+ return newPoints.map((p, i) => {
92
+ var _a;
93
+ const pos = i / (SEGMENT_NUMBER + 1);
94
+ const v = Math.floor(pos);
95
+ const data = (_a = pointList[v]) != null ? _a : {};
96
+ if (v === pos) {
97
+ return __spreadValues(__spreadValues({}, data), p);
98
+ }
99
+ return __spreadValues({
100
+ specialEdge: data.specialEdge
101
+ }, p);
102
+ });
103
+ }
104
+ static createSmoothCurvePoints(points, tension = 0.5, closed = false, numberOfSegments = SEGMENT_NUMBER) {
105
+ if (points.length < 4) {
106
+ return points;
107
+ }
108
+ const result = [];
109
+ const ps = points.slice(0);
110
+ let x;
111
+ let y;
112
+ let t1x;
113
+ let t2x;
114
+ let t1y;
115
+ let t2y;
116
+ let c1;
117
+ let c2;
118
+ let c3;
119
+ let c4;
120
+ let st;
121
+ let t;
122
+ let i;
123
+ if (closed) {
124
+ ps.unshift(points[points.length - 1]);
125
+ ps.unshift(points[points.length - 2]);
126
+ ps.unshift(points[points.length - 1]);
127
+ ps.unshift(points[points.length - 2]);
128
+ ps.push(points[0]);
129
+ ps.push(points[1]);
130
+ } else {
131
+ ps.unshift(points[1]);
132
+ ps.unshift(points[0]);
133
+ ps.push(points[points.length - 2]);
134
+ ps.push(points[points.length - 1]);
135
+ }
136
+ for (i = 2; i < ps.length - 4; i += 2) {
137
+ t1x = (ps[i + 2] - ps[i - 2]) * tension;
138
+ t2x = (ps[i + 4] - ps[i - 0]) * tension;
139
+ t1y = (ps[i + 3] - ps[i - 1]) * tension;
140
+ t2y = (ps[i + 5] - ps[i + 1]) * tension;
141
+ for (t = 0; t <= numberOfSegments; t++) {
142
+ st = t / numberOfSegments;
143
+ c1 = 2 * Math.pow(st, 3) - 3 * Math.pow(st, 2) + 1;
144
+ c2 = -(2 * Math.pow(st, 3)) + 3 * Math.pow(st, 2);
145
+ c3 = Math.pow(st, 3) - 2 * Math.pow(st, 2) + st;
146
+ c4 = Math.pow(st, 3) - Math.pow(st, 2);
147
+ x = c1 * ps[i] + c2 * ps[i + 2] + c3 * t1x + c4 * t2x;
148
+ y = c1 * ps[i + 1] + c2 * ps[i + 3] + c3 * t1y + c4 * t2y;
149
+ result.push(x);
150
+ result.push(y);
151
+ }
152
+ }
153
+ const formatResult = [];
154
+ for (let j = 0; j < result.length - 1; j += 2) {
155
+ formatResult.push({
156
+ x: result[j],
157
+ y: result[j + 1]
158
+ });
159
+ }
160
+ if (closed) {
161
+ for (let m = 0; m < numberOfSegments + 1; m++) {
162
+ const d = formatResult.shift();
163
+ formatResult.push(d);
164
+ }
165
+ }
166
+ return formatResult;
167
+ }
168
+ static getPolygonByID(polygonList, id) {
169
+ return polygonList.find((p) => p.id === id);
170
+ }
171
+ static getHoverEdgeIndex(checkPoint, pointList, lineType = ELineTypes.Line, scope = 3) {
172
+ let points = [...pointList];
173
+ if (lineType === ELineTypes.Curve) {
174
+ points = this.createSmoothCurvePoints(pointList.reduce((acc, cur) => {
175
+ return [...acc, cur.x, cur.y];
176
+ }, []), 0.5, true, SEGMENT_NUMBER);
177
+ } else if (lineType === ELineTypes.Line) {
178
+ points.push(points[0]);
179
+ }
180
+ let edgeIndex = -1;
181
+ let minLength = scope;
182
+ for (let i = 0; i < points.length - 1; i++) {
183
+ const {length} = MathUtils.getFootOfPerpendicular(checkPoint, points[i], points[i + 1]);
184
+ if (length < minLength) {
185
+ edgeIndex = i;
186
+ minLength = length;
187
+ }
188
+ }
189
+ if (edgeIndex === -1) {
190
+ return -1;
191
+ }
192
+ if (lineType === ELineTypes.Curve) {
193
+ return Math.floor(edgeIndex / SEGMENT_NUMBER);
194
+ }
195
+ return edgeIndex;
196
+ }
197
+ static getClosestPoint(coordinate, polygonList, lineType = ELineTypes.Line, range = 3, option) {
198
+ var _a;
199
+ let hasClosed = false;
200
+ const isClose = (_a = option == null ? void 0 : option.isClose) != null ? _a : true;
201
+ let closestPolygonID = "";
202
+ let closestEdgeIndex = -1;
203
+ let min = Infinity;
204
+ let dropFoot = coordinate;
205
+ const numberOfSegments = 20;
206
+ let isCloseNode = false;
207
+ polygonList.forEach((v) => {
208
+ if (isCloseNode) {
209
+ return;
210
+ }
211
+ if (!v.pointList) {
212
+ return;
213
+ }
214
+ switch (lineType) {
215
+ case ELineTypes.Line:
216
+ {
217
+ const allLine = CommonToolUtils.findAllLine(v.pointList, isClose);
218
+ allLine.forEach((line, lineIndex) => {
219
+ if (isCloseNode) {
220
+ return;
221
+ }
222
+ let {length, footPoint} = MathUtils.getFootOfPerpendicular(coordinate, line.point1, line.point2);
223
+ const twoPointDistance1 = MathUtils.getLineLength(line.point1, coordinate);
224
+ const twoPointDistance2 = MathUtils.getLineLength(line.point2, coordinate);
225
+ if (twoPointDistance1 < range * 2) {
226
+ footPoint = line.point1;
227
+ length = twoPointDistance1;
228
+ isCloseNode = true;
229
+ }
230
+ if (twoPointDistance2 < range * 2) {
231
+ footPoint = line.point2;
232
+ length = twoPointDistance2;
233
+ isCloseNode = true;
234
+ }
235
+ if (length < min && length < range) {
236
+ closestPolygonID = v.id;
237
+ closestEdgeIndex = lineIndex;
238
+ min = length;
239
+ dropFoot = footPoint;
240
+ hasClosed = true;
241
+ }
242
+ });
243
+ }
244
+ break;
245
+ case ELineTypes.Curve:
246
+ {
247
+ const points = this.createSmoothCurvePoints(v.pointList.reduce((acc, cur) => {
248
+ return [...acc, cur.x, cur.y];
249
+ }, []), 0.5, isClose, numberOfSegments);
250
+ for (let i = 0; i < points.length - 1; i++) {
251
+ const {length, footPoint} = MathUtils.getFootOfPerpendicular(coordinate, points[i], points[i + 1]);
252
+ if (length < min && length < range) {
253
+ closestPolygonID = v.id;
254
+ closestEdgeIndex = Math.floor(i / (numberOfSegments + 1));
255
+ min = length;
256
+ dropFoot = footPoint;
257
+ hasClosed = true;
258
+ }
259
+ }
260
+ }
261
+ break;
262
+ }
263
+ });
264
+ return {dropFoot, closestEdgeIndex, closestPolygonID, hasClosed};
265
+ }
266
+ static isPointListInPolygon(pointList, polygonPoints, lineType = ELineTypes.Line) {
267
+ return pointList.every((v) => this.isInPolygon(v, polygonPoints, lineType));
268
+ }
269
+ static isPointListOutSidePolygon(pointList, polygonPoints, lineType = ELineTypes.Line) {
270
+ return pointList.some((v) => !this.isInPolygon(v, polygonPoints, lineType));
271
+ }
272
+ static getPolygonArea(pointList) {
273
+ let total = 0;
274
+ for (let i = 0, l = pointList.length; i < l; i++) {
275
+ const addX = pointList[i].x;
276
+ const addY = pointList[i === pointList.length - 1 ? 0 : i + 1].y;
277
+ const subX = pointList[i === pointList.length - 1 ? 0 : i + 1].x;
278
+ const subY = pointList[i].y;
279
+ total += addX * addY * 0.5;
280
+ total -= subX * subY * 0.5;
281
+ }
282
+ return Math.abs(total);
283
+ }
284
+ static updatePolygonByRotate(direction, angle = 1, pointList) {
285
+ let rotate = 1;
286
+ if (direction === ERotateDirection.Anticlockwise) {
287
+ rotate = -1;
288
+ }
289
+ rotate *= angle;
290
+ return MathUtils.rotateRectPointList(rotate, pointList);
291
+ }
292
+ static deletePolygonLastPoint(acc, cur, index, array) {
293
+ if (index === array.length - 1) {
294
+ return acc;
295
+ }
296
+ return [
297
+ ...acc,
298
+ {
299
+ x: cur[0],
300
+ y: cur[1]
301
+ }
302
+ ];
303
+ }
304
+ static concatBeginAndEnd(array) {
305
+ if (array.length < 1) {
306
+ return array;
307
+ }
308
+ return [...array, array[0]];
309
+ }
310
+ static segmentPolygonByPolygon(pointList, polygonList) {
311
+ var _a, _b;
312
+ try {
313
+ let selectedPolygon = polygon([[...PolygonUtils.concatBeginAndEnd(pointList.map((v) => [v.x, v.y]))]]);
314
+ polygonList.forEach((v) => {
315
+ const backgroundPolygon = polygon([[...PolygonUtils.concatBeginAndEnd(v.pointList.map((p) => [p.x, p.y]))]]);
316
+ const diff = difference(selectedPolygon, backgroundPolygon);
317
+ if (diff) {
318
+ selectedPolygon = diff;
319
+ }
320
+ });
321
+ const resultList = (_b = (_a = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a.coordinates.map((p) => {
322
+ var _a2;
323
+ if (((_a2 = selectedPolygon == null ? void 0 : selectedPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
324
+ return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
325
+ }
326
+ return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
327
+ })) != null ? _b : [];
328
+ return resultList.reduce((acc, pointLists) => {
329
+ const len = pointLists.length;
330
+ const newPointList = pointLists.filter((point, i) => {
331
+ const nextIndex = (i + 1) % len;
332
+ if (AxisUtils.getIsInScope(point, pointLists[nextIndex], 1)) {
333
+ return false;
334
+ }
335
+ return true;
336
+ });
337
+ if (newPointList.length < 3) {
338
+ return acc;
339
+ }
340
+ return [...acc, newPointList];
341
+ }, []);
342
+ } catch (error) {
343
+ console.error(error);
344
+ }
345
+ }
346
+ static getPolygonPointList(selectedPolygonID, polygonList) {
347
+ const p = polygonList.find((v) => v.id === selectedPolygonID);
348
+ if (p && p.pointList && p.pointList.length > 0) {
349
+ return p.pointList;
350
+ }
351
+ return [];
352
+ }
353
+ static getWrapPolygonIndex(pointList, polygonList) {
354
+ return polygonList.findIndex((p) => PolygonUtils.isPointListInPolygon(pointList, p.pointList));
355
+ }
356
+ static clipPolygonFromWrapPolygon(pointList, wrapPointList) {
357
+ const wrapDirection = PolygonUtils.isPolygonClosewise(wrapPointList);
358
+ const selectedDirection = PolygonUtils.isPolygonClosewise(pointList);
359
+ const linkIndex = PolygonUtils.getClosePointDistanceFromPolygon(pointList[0], wrapPointList);
360
+ const linkPoint = wrapPointList[linkIndex];
361
+ let newPointList = [
362
+ ...wrapPointList.slice(0, linkIndex),
363
+ linkPoint,
364
+ ...pointList,
365
+ pointList[0],
366
+ ...wrapPointList.slice(linkIndex, wrapPointList.length)
367
+ ];
368
+ if (wrapDirection === selectedDirection) {
369
+ newPointList = [
370
+ ...wrapPointList.slice(0, linkIndex),
371
+ linkPoint,
372
+ pointList[0],
373
+ ...pointList.reverse(),
374
+ ...wrapPointList.slice(linkIndex, wrapPointList.length)
375
+ ];
376
+ }
377
+ return newPointList;
378
+ }
379
+ static isPolygonClosewise(p) {
380
+ const n = p.length;
381
+ let i;
382
+ let j;
383
+ let k;
384
+ let count = 0;
385
+ let z;
386
+ if (n < 3) {
387
+ return 0;
388
+ }
389
+ for (i = 0; i < n; i++) {
390
+ j = (i + 1) % n;
391
+ k = (i + 2) % n;
392
+ z = (p[j].x - p[i].x) * (p[k].y - p[j].y);
393
+ z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
394
+ if (z < 0) {
395
+ count--;
396
+ } else if (z > 0) {
397
+ count++;
398
+ }
399
+ }
400
+ if (count > 0) {
401
+ return 1;
402
+ }
403
+ if (count < 0) {
404
+ return -1;
405
+ }
406
+ return 0;
407
+ }
408
+ static getClosePointDistanceFromPolygon(point, pointList) {
409
+ let minLen = Number.MAX_SAFE_INTEGER;
410
+ let index = -1;
411
+ pointList.forEach((p, i) => {
412
+ const distance = LineToolUtils.calcDistance(point, p);
413
+ if (distance < minLen) {
414
+ minLen = distance;
415
+ index = i;
416
+ }
417
+ });
418
+ return index;
419
+ }
420
+ static combinePolygonWithPolygon(selectedPolygon, combinedPolygon) {
421
+ var _a, _b;
422
+ try {
423
+ const turfSelectedPolygon = polygon([
424
+ [...PolygonUtils.concatBeginAndEnd(selectedPolygon.pointList.map((v) => [v.x, v.y]))]
425
+ ]);
426
+ const turfCombinedPolygon = polygon([
427
+ [...PolygonUtils.concatBeginAndEnd(combinedPolygon.pointList.map((v) => [v.x, v.y]))]
428
+ ]);
429
+ const unionPolygon = union(turfSelectedPolygon, turfCombinedPolygon);
430
+ const unionList = [];
431
+ const newPolygon = selectedPolygon;
432
+ if (((_b = (_a = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a.coordinates) == null ? void 0 : _b.length) === 1) {
433
+ unionList.push(combinedPolygon.id);
434
+ const pointList = unionPolygon == null ? void 0 : unionPolygon.geometry.coordinates.map((p) => {
435
+ var _a2;
436
+ if (((_a2 = unionPolygon == null ? void 0 : unionPolygon.geometry) == null ? void 0 : _a2.type) === "MultiPolygon") {
437
+ return p[0].reduce(PolygonUtils.deletePolygonLastPoint, []);
438
+ }
439
+ return p.reduce(PolygonUtils.deletePolygonLastPoint, []);
440
+ })[0];
441
+ newPolygon.pointList = pointList;
442
+ }
443
+ return {
444
+ newPolygon,
445
+ unionList
446
+ };
447
+ } catch (e) {
448
+ console.error(e);
449
+ }
450
+ }
451
+ }
452
+
453
+ export { PolygonUtils as default };
@@ -0,0 +1,153 @@
1
+ import AxisUtils from './AxisUtils.js';
2
+ import CommonToolUtils from './CommonToolUtils.js';
3
+ import { isInPolygon } from './polygonTool.js';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ class RectUtils {
25
+ static composeResult(result, currentStep, resultList, stepList, basicImgInfo) {
26
+ try {
27
+ const data = JSON.parse(result);
28
+ const currentStepInfo = CommonToolUtils.getCurrentStepInfo(currentStep, stepList);
29
+ const {dataSourceStep} = currentStepInfo;
30
+ const stepName = `step_${currentStepInfo.step}`;
31
+ Object.assign(data, basicImgInfo);
32
+ if (data[stepName]) {
33
+ const info = data[stepName];
34
+ if (info.result) {
35
+ info.result = resultList;
36
+ return JSON.stringify(data);
37
+ }
38
+ return JSON.stringify(__spreadProps(__spreadValues({}, data), {
39
+ [stepName]: __spreadProps(__spreadValues({}, data[stepName]), {
40
+ result: resultList
41
+ })
42
+ }));
43
+ }
44
+ return JSON.stringify(__spreadProps(__spreadValues({}, data), {
45
+ [stepName]: {
46
+ dataSourceStep,
47
+ toolName: currentStepInfo.tool,
48
+ result: resultList
49
+ }
50
+ }));
51
+ } catch (e) {
52
+ return result;
53
+ }
54
+ }
55
+ static changeCoordinateByRotate(rect, rotate, imgSize) {
56
+ const {x, y, width, height} = rect;
57
+ const leftTopCoordinate = AxisUtils.changeCoordinateByRotate({x, y}, rotate, imgSize);
58
+ switch (rotate % 360) {
59
+ case 90:
60
+ return __spreadProps(__spreadValues({}, rect), {
61
+ x: leftTopCoordinate.x - height,
62
+ y: leftTopCoordinate.y,
63
+ width: height,
64
+ height: width
65
+ });
66
+ case 180:
67
+ return __spreadProps(__spreadValues({}, rect), {
68
+ x: leftTopCoordinate.x - width,
69
+ y: leftTopCoordinate.y - height
70
+ });
71
+ case 270:
72
+ return __spreadProps(__spreadValues({}, rect), {
73
+ x: leftTopCoordinate.x,
74
+ y: leftTopCoordinate.y - width,
75
+ width: height,
76
+ height: width
77
+ });
78
+ default:
79
+ return rect;
80
+ }
81
+ }
82
+ static translateRect2Points(rect) {
83
+ const {x, y, width, height} = rect;
84
+ return [
85
+ {
86
+ x,
87
+ y
88
+ },
89
+ {
90
+ x: x + width,
91
+ y
92
+ },
93
+ {
94
+ x: x + width,
95
+ y: y + height
96
+ },
97
+ {
98
+ x,
99
+ y: y + height
100
+ }
101
+ ];
102
+ }
103
+ static translatePoints2Rect(points, basicRect) {
104
+ if (points.length !== 4) {
105
+ return;
106
+ }
107
+ const {x, y} = points[0];
108
+ const width = points[1].x - points[0].x;
109
+ const height = points[2].y - points[1].y;
110
+ return __spreadProps(__spreadValues({}, basicRect), {
111
+ x,
112
+ y,
113
+ width,
114
+ height
115
+ });
116
+ }
117
+ static getRectPointList(rect, zoom = 1) {
118
+ return [
119
+ {x: rect.x * zoom, y: rect.y * zoom},
120
+ {x: (rect.x + rect.width) * zoom, y: rect.y * zoom},
121
+ {x: (rect.x + rect.width) * zoom, y: (rect.y + rect.height) * zoom},
122
+ {x: rect.x * zoom, y: (rect.y + rect.height) * zoom}
123
+ ];
124
+ }
125
+ static getRectEdgeList(rect, zoom = 1) {
126
+ const pointList = this.getRectPointList(rect, zoom);
127
+ const len = pointList.length;
128
+ return pointList.map((v, i) => {
129
+ return {
130
+ begin: v,
131
+ end: pointList[(i + 1) % len]
132
+ };
133
+ });
134
+ }
135
+ static isInRect(coordinate, rect, scope = 0, zoom = 1) {
136
+ return coordinate.x >= rect.x * zoom - scope && coordinate.x <= (rect.x + rect.width) * zoom + scope && coordinate.y >= rect.y * zoom - scope && coordinate.y <= (rect.y + rect.height) * zoom + scope;
137
+ }
138
+ static getRectUnderZoom(rect, zoom = 1) {
139
+ const {x, y, width, height} = rect;
140
+ return __spreadProps(__spreadValues({}, rect), {
141
+ x: x * zoom,
142
+ y: y * zoom,
143
+ width: width * zoom,
144
+ height: height * zoom
145
+ });
146
+ }
147
+ static isRectNotInPolygon(rect, polygonPointList) {
148
+ const rectPointList = this.getRectPointList(rect);
149
+ return rectPointList.some((p) => !isInPolygon(p, polygonPointList));
150
+ }
151
+ }
152
+
153
+ export { RectUtils as default };
@@ -0,0 +1,68 @@
1
+ import DrawUtils from './DrawUtils.js';
2
+ import StyleUtils from './StyleUtils.js';
3
+
4
+ class RenderDomClass {
5
+ constructor(props) {
6
+ this._domMap = new Map();
7
+ this._container = props.container;
8
+ this._height = props.height;
9
+ }
10
+ wheelChange(e) {
11
+ e.stopPropagation();
12
+ }
13
+ clearTag(id) {
14
+ const parentNode = this._container;
15
+ const oldDom = window.self.document.getElementById(id);
16
+ if (oldDom && parentNode && parentNode.contains(oldDom)) {
17
+ oldDom.removeEventListener("wheel", this.wheelChange);
18
+ parentNode == null ? void 0 : parentNode.removeChild(oldDom);
19
+ }
20
+ }
21
+ render(annotations) {
22
+ const oldKeys = Array.from(this._domMap.keys());
23
+ const newKeys = annotations.map((v) => v.id);
24
+ annotations.forEach((v) => {
25
+ const {text, textMaxWidth, color = "white", background = "rgba(0, 0, 0, 0.6)", style} = v;
26
+ if (this._domMap.has(v.id)) {
27
+ const dom = this._domMap.get(v.id);
28
+ if (dom) {
29
+ dom.innerHTML = text;
30
+ }
31
+ } else {
32
+ const dom = DrawUtils.drawTagByDom(this._container, text, v.id);
33
+ if (dom) {
34
+ dom.setAttribute("style", `
35
+ position: absolute;
36
+ top: 0;
37
+ right: 0;
38
+ z-index: 20;
39
+ padding: 8px 20px;
40
+ font-size: 15px;
41
+ max-width: ${textMaxWidth}px;
42
+ color: ${color};
43
+ text-align: left;
44
+ line-height: 32px;
45
+ word-break: break-all;
46
+ white-space: pre-wrap;
47
+ background: ${background};
48
+ opacity: 0.9;
49
+ max-height: ${this._height * 0.8}px;
50
+ overflow-y: scroll;
51
+ clear: both;
52
+ ${StyleUtils.getStyle2String(style)}
53
+ `);
54
+ dom.addEventListener("wheel", this.wheelChange);
55
+ this._domMap.set(v.id, dom);
56
+ }
57
+ }
58
+ });
59
+ oldKeys.forEach((key) => {
60
+ if (newKeys.indexOf(key) === -1) {
61
+ this.clearTag(key);
62
+ this._domMap.delete(key);
63
+ }
64
+ });
65
+ }
66
+ }
67
+
68
+ export { RenderDomClass as default };
@@ -0,0 +1,29 @@
1
+ import Locale from '../../locales/index.js';
2
+ import { EMessage } from '../../locales/constants.js';
3
+
4
+ class RenderDomUtils {
5
+ static renderInvalidPage(container, size, lang) {
6
+ const invalidDOM = document.createElement("div");
7
+ invalidDOM.setAttribute("style", `
8
+ position: absolute;
9
+ left: 0px;
10
+ top: 0px;
11
+ width: ${size.width}px;
12
+ height: ${size.height}px;
13
+ background: rgba(255, 87, 34, 1);
14
+ overflow: hidden;
15
+ color: white;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ font-size: 30px;
20
+ opacity: 0.7;
21
+ z-index: 30;
22
+ `);
23
+ invalidDOM.innerHTML = Locale.getMessagesByLocale(EMessage.InvalidImage, lang);
24
+ container.appendChild(invalidDOM);
25
+ return invalidDOM;
26
+ }
27
+ }
28
+
29
+ export { RenderDomUtils as default };