@rytass/wms-map-react-components 0.1.10 → 0.3.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.
- package/CHANGELOG.md +181 -0
- package/README.md +30 -0
- package/components/breadcrumb/breadcrumb-edit-modal.cjs +92 -0
- package/components/breadcrumb/breadcrumb-edit-modal.d.cts +9 -0
- package/components/breadcrumb/breadcrumb-edit-modal.module.scss.cjs +5 -0
- package/components/breadcrumb/breadcrumb.cjs +171 -0
- package/components/breadcrumb/breadcrumb.d.cts +11 -0
- package/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/components/breadcrumb/breadcrumb.module.scss.cjs +5 -0
- package/components/canvas/react-flow-canvas.cjs +327 -0
- package/components/canvas/react-flow-canvas.d.cts +40 -0
- package/components/canvas/react-flow-canvas.d.ts +3 -1
- package/components/canvas/react-flow-canvas.js +7 -1
- package/components/canvas/react-flow-canvas.module.scss.cjs +5 -0
- package/components/modal/wms-map-content.cjs +835 -0
- package/components/modal/wms-map-content.d.cts +4 -0
- package/components/modal/wms-map-content.d.ts +1 -1
- package/components/modal/wms-map-content.js +30 -3
- package/components/modal/wms-map-modal-container.cjs +132 -0
- package/components/modal/wms-map-modal-container.d.cts +5 -0
- package/components/modal/wms-map-modal-container.d.ts +2 -2
- package/components/modal/wms-map-modal-container.js +6 -4
- package/components/modal/wms-map-modal-container.module.scss.cjs +5 -0
- package/components/nodes/base-node.d.cts +12 -0
- package/components/nodes/base-node.d.ts +1 -1
- package/components/nodes/image-node.cjs +234 -0
- package/components/nodes/image-node.d.cts +17 -0
- package/components/nodes/image-node.d.ts +1 -1
- package/components/nodes/image-node.js +0 -2
- package/components/nodes/image-node.module.scss.cjs +5 -0
- package/components/nodes/path-node.cjs +554 -0
- package/components/nodes/path-node.d.cts +19 -0
- package/components/nodes/path-node.d.ts +1 -1
- package/components/nodes/path-node.js +6 -5
- package/components/nodes/path-node.module.scss.cjs +5 -0
- package/components/nodes/rectangle-node.cjs +240 -0
- package/components/nodes/rectangle-node.d.cts +11 -0
- package/components/nodes/rectangle-node.d.ts +1 -1
- package/components/nodes/rectangle-node.js +6 -5
- package/components/nodes/rectangle-node.module.scss.cjs +5 -0
- package/components/preview/wms-map-preview.cjs +201 -0
- package/components/preview/wms-map-preview.d.cts +11 -0
- package/components/preview/wms-map-preview.d.ts +11 -0
- package/components/preview/wms-map-preview.js +199 -0
- package/components/ui/context-menu.cjs +171 -0
- package/components/ui/context-menu.d.cts +25 -0
- package/components/ui/context-menu.module.scss.cjs +5 -0
- package/components/ui/toolbar.cjs +286 -0
- package/components/ui/toolbar.d.cts +23 -0
- package/components/ui/toolbar.d.ts +1 -1
- package/components/ui/toolbar.module.scss.cjs +5 -0
- package/components/ui/view-mode-toolbar.cjs +44 -0
- package/components/ui/view-mode-toolbar.d.cts +9 -0
- package/components/ui/view-mode-toolbar.d.ts +1 -1
- package/components/ui/view-mode-toolbar.module.scss.cjs +5 -0
- package/constants/index.cjs +54 -0
- package/constants/index.d.cts +45 -0
- package/constants/index.d.ts +2 -2
- package/constants/text-mappings.cjs +46 -0
- package/constants/text-mappings.d.cts +181 -0
- package/hooks/use-context-menu.cjs +231 -0
- package/hooks/use-context-menu.d.cts +37 -0
- package/hooks/use-context-menu.d.ts +1 -1
- package/hooks/use-direct-state-history.cjs +217 -0
- package/hooks/use-direct-state-history.d.cts +58 -0
- package/hooks/use-direct-state-history.d.ts +2 -2
- package/hooks/use-fit-view-when-ready.cjs +74 -0
- package/hooks/use-fit-view-when-ready.d.cts +18 -0
- package/hooks/use-fit-view-when-ready.d.ts +18 -0
- package/hooks/use-fit-view-when-ready.js +72 -0
- package/hooks/use-pen-drawing.cjs +366 -0
- package/hooks/use-pen-drawing.d.cts +30 -0
- package/hooks/use-pen-drawing.d.ts +1 -1
- package/hooks/use-rectangle-drawing.cjs +139 -0
- package/hooks/use-rectangle-drawing.d.cts +19 -0
- package/hooks/use-rectangle-drawing.d.ts +1 -1
- package/hooks/use-text-editing.cjs +156 -0
- package/hooks/use-text-editing.d.cts +19 -0
- package/icons/index.cjs +233 -0
- package/icons/index.d.cts +16 -0
- package/index.cjs +28 -0
- package/index.d.cts +6 -0
- package/index.d.ts +6 -5
- package/index.js +1 -0
- package/package.json +68 -3
- package/types/callback.types.d.cts +7 -0
- package/types/callback.types.d.ts +1 -1
- package/types/canvas.types.d.cts +35 -0
- package/types/canvas.types.d.ts +1 -1
- package/types/component-props.types.d.cts +76 -0
- package/types/component-props.types.d.ts +33 -2
- package/types/history.types.d.cts +24 -0
- package/types/history.types.d.ts +2 -2
- package/types/index.d.cts +5 -0
- package/types/index.d.ts +5 -5
- package/types/react-flow.types.d.cts +30 -0
- package/typings.cjs +44 -0
- package/typings.d.cts +136 -0
- package/utils/api-data-transform.cjs +221 -0
- package/utils/api-data-transform.d.cts +33 -0
- package/utils/api-data-transform.d.ts +1 -1
- package/utils/color-utils.cjs +58 -0
- package/utils/color-utils.d.cts +17 -0
- package/utils/debug-logger.cjs +45 -0
- package/utils/debug-logger.d.cts +33 -0
- package/utils/fit-trigger.cjs +41 -0
- package/utils/fit-trigger.d.cts +37 -0
- package/utils/fit-trigger.d.ts +37 -0
- package/utils/fit-trigger.js +36 -0
- package/utils/map-data-transform.cjs +360 -0
- package/utils/map-data-transform.d.cts +18 -0
- package/utils/map-data-transform.d.ts +1 -1
- package/utils/node-operations.cjs +88 -0
- package/utils/node-operations.d.cts +26 -0
- package/utils/node-utils.cjs +40 -0
- package/utils/node-utils.d.cts +10 -0
- package/utils/preview-highlight.cjs +38 -0
- package/utils/preview-highlight.d.cts +12 -0
- package/utils/preview-highlight.d.ts +12 -0
- package/utils/preview-highlight.js +34 -0
- package/index.cjs.css +0 -1
- package/index.cjs.js +0 -5128
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typings = require('../typings.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 轉換 React Flow 節點資料為 Map 資料格式
|
|
7
|
+
*/ const transformNodesToMapData = (nodes)=>{
|
|
8
|
+
const backgrounds = [];
|
|
9
|
+
const ranges = [];
|
|
10
|
+
nodes.forEach((node)=>{
|
|
11
|
+
switch(node.type){
|
|
12
|
+
case 'imageNode':
|
|
13
|
+
{
|
|
14
|
+
// ImageNode 轉換為 MapBackground
|
|
15
|
+
const imageData = node.data;
|
|
16
|
+
const background = {
|
|
17
|
+
id: node.id,
|
|
18
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
19
|
+
x: node.position.x,
|
|
20
|
+
y: node.position.y,
|
|
21
|
+
width: imageData.width || 300,
|
|
22
|
+
height: imageData.height || 200
|
|
23
|
+
};
|
|
24
|
+
backgrounds.push(background);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'rectangleNode':
|
|
28
|
+
{
|
|
29
|
+
// RectangleNode 轉換為 MapRectangleRange
|
|
30
|
+
const rectData = node.data;
|
|
31
|
+
const rectangleRange = {
|
|
32
|
+
id: rectData.label || node.id,
|
|
33
|
+
type: typings.MapRangeType.RECTANGLE,
|
|
34
|
+
color: rectData.color || '#0000FF',
|
|
35
|
+
x: node.position.x,
|
|
36
|
+
y: node.position.y,
|
|
37
|
+
width: rectData.width || 100,
|
|
38
|
+
height: rectData.height || 100
|
|
39
|
+
};
|
|
40
|
+
ranges.push(rectangleRange);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'pathNode':
|
|
44
|
+
{
|
|
45
|
+
// PathNode 轉換為 MapPolygonRange
|
|
46
|
+
const pathData = node.data;
|
|
47
|
+
const originSourcePointX = Math.min(...pathData.points.map((p)=>p.x));
|
|
48
|
+
const originSourcePointY = Math.min(...pathData.points.map((p)=>p.y));
|
|
49
|
+
const deltaX = node.position.x - originSourcePointX;
|
|
50
|
+
const deltaY = node.position.y - originSourcePointY;
|
|
51
|
+
// 將 node.position 偏移量加到每個 point 上,因為拖曳整個 node 時只更新 position 不更新 data.points
|
|
52
|
+
const absolutePoints = (pathData.points || []).map((p)=>({
|
|
53
|
+
x: p.x + deltaX,
|
|
54
|
+
y: p.y + deltaY
|
|
55
|
+
}));
|
|
56
|
+
const polygonRange = {
|
|
57
|
+
id: pathData.label || node.id,
|
|
58
|
+
type: typings.MapRangeType.POLYGON,
|
|
59
|
+
color: pathData.color || '#0000FF',
|
|
60
|
+
points: absolutePoints
|
|
61
|
+
};
|
|
62
|
+
ranges.push(polygonRange);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
default:
|
|
66
|
+
// 忽略未知的節點類型
|
|
67
|
+
console.warn(`Unknown node type: ${node.type}`, node);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// 生成 Map 物件
|
|
72
|
+
const mapData = {
|
|
73
|
+
id: `map-${Date.now()}`,
|
|
74
|
+
backgrounds,
|
|
75
|
+
ranges
|
|
76
|
+
};
|
|
77
|
+
return mapData;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* 轉換 React Flow 節點為點擊資訊格式
|
|
81
|
+
*/ const transformNodeToClickInfo = (node)=>{
|
|
82
|
+
const baseInfo = {
|
|
83
|
+
id: node.id,
|
|
84
|
+
type: node.type,
|
|
85
|
+
position: node.position,
|
|
86
|
+
zIndex: node.zIndex,
|
|
87
|
+
selected: node.selected
|
|
88
|
+
};
|
|
89
|
+
switch(node.type){
|
|
90
|
+
case 'imageNode':
|
|
91
|
+
{
|
|
92
|
+
const imageData = node.data;
|
|
93
|
+
const mapBackground = {
|
|
94
|
+
id: node.id,
|
|
95
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
96
|
+
x: node.position.x,
|
|
97
|
+
y: node.position.y,
|
|
98
|
+
width: imageData.width || 300,
|
|
99
|
+
height: imageData.height || 200
|
|
100
|
+
};
|
|
101
|
+
const clickInfo = {
|
|
102
|
+
...baseInfo,
|
|
103
|
+
type: 'imageNode',
|
|
104
|
+
imageData: {
|
|
105
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
106
|
+
size: {
|
|
107
|
+
width: imageData.width || 0,
|
|
108
|
+
height: imageData.height || 0
|
|
109
|
+
},
|
|
110
|
+
originalSize: {
|
|
111
|
+
width: imageData.originalWidth || 0,
|
|
112
|
+
height: imageData.originalHeight || 0
|
|
113
|
+
},
|
|
114
|
+
imageUrl: imageData.imageUrl
|
|
115
|
+
},
|
|
116
|
+
mapBackground
|
|
117
|
+
};
|
|
118
|
+
return clickInfo;
|
|
119
|
+
}
|
|
120
|
+
case 'rectangleNode':
|
|
121
|
+
{
|
|
122
|
+
const rectData = node.data;
|
|
123
|
+
const mapRectangleRange = {
|
|
124
|
+
id: rectData.label || node.id,
|
|
125
|
+
type: typings.MapRangeType.RECTANGLE,
|
|
126
|
+
color: rectData.color || '#0000FF',
|
|
127
|
+
x: node.position.x,
|
|
128
|
+
y: node.position.y,
|
|
129
|
+
width: rectData.width || 100,
|
|
130
|
+
height: rectData.height || 100
|
|
131
|
+
};
|
|
132
|
+
const clickInfo = {
|
|
133
|
+
...baseInfo,
|
|
134
|
+
type: 'rectangleNode',
|
|
135
|
+
rectangleData: {
|
|
136
|
+
color: rectData.color || '#0000FF',
|
|
137
|
+
size: {
|
|
138
|
+
width: rectData.width || 100,
|
|
139
|
+
height: rectData.height || 100
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
mapRectangleRange
|
|
143
|
+
};
|
|
144
|
+
return clickInfo;
|
|
145
|
+
}
|
|
146
|
+
case 'pathNode':
|
|
147
|
+
{
|
|
148
|
+
const pathData = node.data;
|
|
149
|
+
const originSourcePointX = Math.min(...pathData.points.map((p)=>p.x));
|
|
150
|
+
const originSourcePointY = Math.min(...pathData.points.map((p)=>p.y));
|
|
151
|
+
const deltaX = node.position.x - originSourcePointX;
|
|
152
|
+
const deltaY = node.position.y - originSourcePointY;
|
|
153
|
+
const absolutePoints = (pathData.points || []).map((p)=>({
|
|
154
|
+
x: p.x + deltaX,
|
|
155
|
+
y: p.y + deltaY
|
|
156
|
+
}));
|
|
157
|
+
const mapPolygonRange = {
|
|
158
|
+
id: pathData.label || node.id,
|
|
159
|
+
type: typings.MapRangeType.POLYGON,
|
|
160
|
+
color: pathData.color || '#0000FF',
|
|
161
|
+
points: absolutePoints
|
|
162
|
+
};
|
|
163
|
+
const absoluteBounds = absolutePoints.length > 0 ? {
|
|
164
|
+
minX: Math.min(...absolutePoints.map((p)=>p.x)),
|
|
165
|
+
minY: Math.min(...absolutePoints.map((p)=>p.y)),
|
|
166
|
+
maxX: Math.max(...absolutePoints.map((p)=>p.x)),
|
|
167
|
+
maxY: Math.max(...absolutePoints.map((p)=>p.y))
|
|
168
|
+
} : null;
|
|
169
|
+
const clickInfo = {
|
|
170
|
+
...baseInfo,
|
|
171
|
+
type: 'pathNode',
|
|
172
|
+
pathData: {
|
|
173
|
+
color: pathData.color || '#0000FF',
|
|
174
|
+
strokeWidth: pathData.strokeWidth || 2,
|
|
175
|
+
pointCount: absolutePoints.length,
|
|
176
|
+
points: absolutePoints,
|
|
177
|
+
bounds: absoluteBounds
|
|
178
|
+
},
|
|
179
|
+
mapPolygonRange
|
|
180
|
+
};
|
|
181
|
+
return clickInfo;
|
|
182
|
+
}
|
|
183
|
+
default:
|
|
184
|
+
console.warn(`未知的節點類型: ${node.type}`);
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* 格式化輸出單個節點的詳細資訊
|
|
190
|
+
*/ const logNodeData = (node)=>{
|
|
191
|
+
console.group(`🎯 圖形點擊資訊 - ${node.type}`);
|
|
192
|
+
console.log('📋 基本資訊:', {
|
|
193
|
+
id: node.id,
|
|
194
|
+
type: node.type,
|
|
195
|
+
position: node.position,
|
|
196
|
+
zIndex: node.zIndex,
|
|
197
|
+
selected: node.selected
|
|
198
|
+
});
|
|
199
|
+
switch(node.type){
|
|
200
|
+
case 'imageNode':
|
|
201
|
+
{
|
|
202
|
+
const imageData = node.data;
|
|
203
|
+
console.log('🖼️ 背景圖片資訊:', {
|
|
204
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
205
|
+
position: {
|
|
206
|
+
x: node.position.x,
|
|
207
|
+
y: node.position.y
|
|
208
|
+
},
|
|
209
|
+
size: {
|
|
210
|
+
width: imageData.width,
|
|
211
|
+
height: imageData.height
|
|
212
|
+
},
|
|
213
|
+
originalSize: {
|
|
214
|
+
width: imageData.originalWidth,
|
|
215
|
+
height: imageData.originalHeight
|
|
216
|
+
},
|
|
217
|
+
imageUrl: imageData.imageUrl?.slice(0, 50) + '...'
|
|
218
|
+
});
|
|
219
|
+
// 轉換格式(對應儲存時的格式)
|
|
220
|
+
const background = {
|
|
221
|
+
id: node.id,
|
|
222
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
223
|
+
x: node.position.x,
|
|
224
|
+
y: node.position.y,
|
|
225
|
+
width: imageData.width || 300,
|
|
226
|
+
height: imageData.height || 200
|
|
227
|
+
};
|
|
228
|
+
console.log('💾 儲存格式 (MapBackground):', background);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case 'rectangleNode':
|
|
232
|
+
{
|
|
233
|
+
const rectData = node.data;
|
|
234
|
+
console.log('📐 矩形資訊:', {
|
|
235
|
+
color: rectData.color,
|
|
236
|
+
position: {
|
|
237
|
+
x: node.position.x,
|
|
238
|
+
y: node.position.y
|
|
239
|
+
},
|
|
240
|
+
size: {
|
|
241
|
+
width: rectData.width || 100,
|
|
242
|
+
height: rectData.height || 100
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
// 轉換格式(對應儲存時的格式)
|
|
246
|
+
const rectangleRange = {
|
|
247
|
+
id: node.id,
|
|
248
|
+
type: typings.MapRangeType.RECTANGLE,
|
|
249
|
+
color: rectData.color || '#0000FF',
|
|
250
|
+
x: node.position.x,
|
|
251
|
+
y: node.position.y,
|
|
252
|
+
width: rectData.width || 100,
|
|
253
|
+
height: rectData.height || 100
|
|
254
|
+
};
|
|
255
|
+
console.log('💾 儲存格式 (MapRectangleRange):', rectangleRange);
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'pathNode':
|
|
259
|
+
{
|
|
260
|
+
const pathData = node.data;
|
|
261
|
+
const originSourcePointX = Math.min(...pathData.points.map((p)=>p.x));
|
|
262
|
+
const originSourcePointY = Math.min(...pathData.points.map((p)=>p.y));
|
|
263
|
+
const deltaX = node.position.x - originSourcePointX;
|
|
264
|
+
const deltaY = node.position.y - originSourcePointY;
|
|
265
|
+
// 轉換格式(對應儲存時的格式)— 加上 node.position 偏移
|
|
266
|
+
const absoluteLogPoints = (pathData.points || []).map((p)=>({
|
|
267
|
+
x: p.x + deltaX,
|
|
268
|
+
y: p.y + deltaY
|
|
269
|
+
}));
|
|
270
|
+
console.log('🔗 路徑資訊:', {
|
|
271
|
+
color: pathData.color,
|
|
272
|
+
strokeWidth: pathData.strokeWidth,
|
|
273
|
+
pointCount: pathData.points?.length || 0,
|
|
274
|
+
points: pathData.points,
|
|
275
|
+
// 計算路徑邊界
|
|
276
|
+
bounds: absoluteLogPoints?.length > 0 ? {
|
|
277
|
+
minX: Math.min(...absoluteLogPoints.map((p)=>p.x)),
|
|
278
|
+
minY: Math.min(...absoluteLogPoints.map((p)=>p.y)),
|
|
279
|
+
maxX: Math.max(...absoluteLogPoints.map((p)=>p.x)),
|
|
280
|
+
maxY: Math.max(...absoluteLogPoints.map((p)=>p.y))
|
|
281
|
+
} : null
|
|
282
|
+
});
|
|
283
|
+
const polygonRange = {
|
|
284
|
+
id: node.id,
|
|
285
|
+
type: typings.MapRangeType.POLYGON,
|
|
286
|
+
color: pathData.color || '#0000FF',
|
|
287
|
+
points: absoluteLogPoints
|
|
288
|
+
};
|
|
289
|
+
console.log('💾 儲存格式 (MapPolygonRange):', polygonRange);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
default:
|
|
293
|
+
console.warn(`未知的節點類型: ${node.type}`);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
console.log('🔢 完整節點資料:', node);
|
|
297
|
+
console.groupEnd();
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* 格式化輸出 Map 資料到 console,包含詳細資訊
|
|
301
|
+
*/ const logMapData = (mapData)=>{
|
|
302
|
+
console.group('🗺️ WMS Map Data Export');
|
|
303
|
+
console.log('📋 Map Overview:', {
|
|
304
|
+
id: mapData.id,
|
|
305
|
+
backgroundCount: mapData.backgrounds.length,
|
|
306
|
+
rangeCount: mapData.ranges.length
|
|
307
|
+
});
|
|
308
|
+
if (mapData.backgrounds.length > 0) {
|
|
309
|
+
console.group('🖼️ Background Images');
|
|
310
|
+
mapData.backgrounds.forEach((bg, index)=>{
|
|
311
|
+
console.log(`Background ${index + 1}:`, {
|
|
312
|
+
id: bg.id,
|
|
313
|
+
filename: bg.filename,
|
|
314
|
+
position: {
|
|
315
|
+
x: bg.x,
|
|
316
|
+
y: bg.y
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
console.groupEnd();
|
|
321
|
+
}
|
|
322
|
+
if (mapData.ranges.length > 0) {
|
|
323
|
+
console.group('📐 Ranges');
|
|
324
|
+
mapData.ranges.forEach((range, index)=>{
|
|
325
|
+
if (range.type === typings.MapRangeType.RECTANGLE) {
|
|
326
|
+
const rect = range;
|
|
327
|
+
console.log(`Rectangle ${index + 1}:`, {
|
|
328
|
+
id: rect.id,
|
|
329
|
+
type: rect.type,
|
|
330
|
+
color: rect.color,
|
|
331
|
+
position: {
|
|
332
|
+
x: rect.x,
|
|
333
|
+
y: rect.y
|
|
334
|
+
},
|
|
335
|
+
size: {
|
|
336
|
+
width: rect.width,
|
|
337
|
+
height: rect.height
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
} else if (range.type === typings.MapRangeType.POLYGON) {
|
|
341
|
+
const poly = range;
|
|
342
|
+
console.log(`Polygon ${index + 1}:`, {
|
|
343
|
+
id: poly.id,
|
|
344
|
+
type: poly.type,
|
|
345
|
+
color: poly.color,
|
|
346
|
+
pointCount: poly.points.length,
|
|
347
|
+
points: poly.points
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
console.groupEnd();
|
|
352
|
+
}
|
|
353
|
+
console.log('📄 Complete Map Data:', mapData);
|
|
354
|
+
console.groupEnd();
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
exports.logMapData = logMapData;
|
|
358
|
+
exports.logNodeData = logNodeData;
|
|
359
|
+
exports.transformNodeToClickInfo = transformNodeToClickInfo;
|
|
360
|
+
exports.transformNodesToMapData = transformNodesToMapData;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Node } from '@xyflow/react';
|
|
2
|
+
import { Map, WMSNodeClickInfo } from '../typings.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* 轉換 React Flow 節點資料為 Map 資料格式
|
|
5
|
+
*/
|
|
6
|
+
export declare const transformNodesToMapData: (nodes: Node[]) => Map;
|
|
7
|
+
/**
|
|
8
|
+
* 轉換 React Flow 節點為點擊資訊格式
|
|
9
|
+
*/
|
|
10
|
+
export declare const transformNodeToClickInfo: (node: Node) => WMSNodeClickInfo | null;
|
|
11
|
+
/**
|
|
12
|
+
* 格式化輸出單個節點的詳細資訊
|
|
13
|
+
*/
|
|
14
|
+
export declare const logNodeData: (node: Node) => void;
|
|
15
|
+
/**
|
|
16
|
+
* 格式化輸出 Map 資料到 console,包含詳細資訊
|
|
17
|
+
*/
|
|
18
|
+
export declare const logMapData: (mapData: Map) => void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calculate offset position for copied node
|
|
5
|
+
*/ const calculateCopyOffset = (width, height, offsetPercentage = 0.25)=>{
|
|
6
|
+
return {
|
|
7
|
+
offsetX: width * offsetPercentage,
|
|
8
|
+
offsetY: height * offsetPercentage
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Create a copy of a rectangle node
|
|
13
|
+
*/ const createRectangleCopy = (options)=>{
|
|
14
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
15
|
+
const { offsetX, offsetY } = calculateCopyOffset(data.width, data.height, offsetPercentage);
|
|
16
|
+
return {
|
|
17
|
+
id: `rectangle-${Date.now()}`,
|
|
18
|
+
type: 'rectangleNode',
|
|
19
|
+
position: {
|
|
20
|
+
x: currentNode.position.x + offsetX,
|
|
21
|
+
y: currentNode.position.y + offsetY
|
|
22
|
+
},
|
|
23
|
+
data: {
|
|
24
|
+
width: data.width,
|
|
25
|
+
height: data.height,
|
|
26
|
+
color: data.color,
|
|
27
|
+
label: data.label
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create a copy of a path node
|
|
33
|
+
*/ const createPathCopy = (options)=>{
|
|
34
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
35
|
+
// Calculate path bounds
|
|
36
|
+
const xs = data.points.map((p)=>p.x);
|
|
37
|
+
const ys = data.points.map((p)=>p.y);
|
|
38
|
+
const bounds = {
|
|
39
|
+
minX: Math.min(...xs),
|
|
40
|
+
minY: Math.min(...ys),
|
|
41
|
+
maxX: Math.max(...xs),
|
|
42
|
+
maxY: Math.max(...ys)
|
|
43
|
+
};
|
|
44
|
+
const pathWidth = Math.max(bounds.maxX - bounds.minX, 10);
|
|
45
|
+
const pathHeight = Math.max(bounds.maxY - bounds.minY, 10);
|
|
46
|
+
const { offsetX, offsetY } = calculateCopyOffset(pathWidth, pathHeight, offsetPercentage);
|
|
47
|
+
return {
|
|
48
|
+
id: `path-${Date.now()}`,
|
|
49
|
+
type: 'pathNode',
|
|
50
|
+
position: {
|
|
51
|
+
x: currentNode.position.x + offsetX,
|
|
52
|
+
y: currentNode.position.y + offsetY
|
|
53
|
+
},
|
|
54
|
+
data: {
|
|
55
|
+
points: data.points,
|
|
56
|
+
color: data.color,
|
|
57
|
+
strokeWidth: data.strokeWidth,
|
|
58
|
+
label: data.label
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Create a copy of an image node
|
|
64
|
+
*/ const createImageCopy = (options)=>{
|
|
65
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
66
|
+
const { offsetX, offsetY } = calculateCopyOffset(data.width, data.height, offsetPercentage);
|
|
67
|
+
return {
|
|
68
|
+
id: `image-${Date.now()}`,
|
|
69
|
+
type: 'imageNode',
|
|
70
|
+
position: {
|
|
71
|
+
x: currentNode.position.x + offsetX,
|
|
72
|
+
y: currentNode.position.y + offsetY
|
|
73
|
+
},
|
|
74
|
+
data: {
|
|
75
|
+
imageUrl: data.imageUrl,
|
|
76
|
+
width: data.width,
|
|
77
|
+
height: data.height,
|
|
78
|
+
fileName: data.fileName,
|
|
79
|
+
originalWidth: data.originalWidth,
|
|
80
|
+
originalHeight: data.originalHeight
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
exports.calculateCopyOffset = calculateCopyOffset;
|
|
86
|
+
exports.createImageCopy = createImageCopy;
|
|
87
|
+
exports.createPathCopy = createPathCopy;
|
|
88
|
+
exports.createRectangleCopy = createRectangleCopy;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Node } from '@xyflow/react';
|
|
2
|
+
export interface CopyNodeOptions {
|
|
3
|
+
currentNode: Node;
|
|
4
|
+
offsetPercentage?: number;
|
|
5
|
+
nodeType: 'rectangleNode' | 'pathNode' | 'imageNode';
|
|
6
|
+
data: any;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Calculate offset position for copied node
|
|
10
|
+
*/
|
|
11
|
+
export declare const calculateCopyOffset: (width: number, height: number, offsetPercentage?: number) => {
|
|
12
|
+
offsetX: number;
|
|
13
|
+
offsetY: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Create a copy of a rectangle node
|
|
17
|
+
*/
|
|
18
|
+
export declare const createRectangleCopy: (options: CopyNodeOptions) => Node;
|
|
19
|
+
/**
|
|
20
|
+
* Create a copy of a path node
|
|
21
|
+
*/
|
|
22
|
+
export declare const createPathCopy: (options: CopyNodeOptions) => Node;
|
|
23
|
+
/**
|
|
24
|
+
* Create a copy of an image node
|
|
25
|
+
*/
|
|
26
|
+
export declare const createImageCopy: (options: CopyNodeOptions) => Node;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const calculateImageSize = (originalWidth, originalHeight, maxSize = 500)=>{
|
|
4
|
+
const needsResize = originalWidth > maxSize || originalHeight > maxSize;
|
|
5
|
+
if (!needsResize) {
|
|
6
|
+
return {
|
|
7
|
+
width: Math.round(originalWidth),
|
|
8
|
+
height: Math.round(originalHeight)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const ratio = Math.min(maxSize / originalWidth, maxSize / originalHeight);
|
|
12
|
+
return {
|
|
13
|
+
width: Math.round(originalWidth * ratio),
|
|
14
|
+
height: Math.round(originalHeight * ratio)
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const calculateStaggeredPosition = (index, baseX = 100, baseY = 100, viewportX, viewportY, viewportZoom)=>{
|
|
18
|
+
// If viewport information is provided, calculate position within current viewport
|
|
19
|
+
if (viewportX !== undefined && viewportY !== undefined && viewportZoom !== undefined) {
|
|
20
|
+
// Convert viewport coordinates to canvas coordinates
|
|
21
|
+
// The viewport shows the center of the view, so we need to offset from the center
|
|
22
|
+
const centerX = -viewportX / viewportZoom + window.innerWidth / 2 / viewportZoom;
|
|
23
|
+
const centerY = -viewportY / viewportZoom + window.innerHeight / 2 / viewportZoom;
|
|
24
|
+
// Position images slightly offset from center
|
|
25
|
+
const offsetX = centerX - 200 + index * 30; // Start 200px left of center
|
|
26
|
+
const offsetY = centerY - 100 + index * 20; // Start 100px above center
|
|
27
|
+
return {
|
|
28
|
+
x: offsetX,
|
|
29
|
+
y: offsetY
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Fallback to original fixed positioning
|
|
33
|
+
return {
|
|
34
|
+
x: baseX + index * 30,
|
|
35
|
+
y: baseY + index * 20
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.calculateImageSize = calculateImageSize;
|
|
40
|
+
exports.calculateStaggeredPosition = calculateStaggeredPosition;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Node } from '@xyflow/react';
|
|
2
|
+
export declare const updateNodeData: <T extends Record<string, unknown>>(nodes: Node[], nodeId: string, updates: Partial<T>) => Node[];
|
|
3
|
+
export declare const calculateImageSize: (originalWidth: number, originalHeight: number, maxSize?: number) => {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const calculateStaggeredPosition: (index: number, baseX?: number, baseY?: number, viewportX?: number, viewportY?: number, viewportZoom?: number) => {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** 只有範圍節點(矩形、路徑)會被高亮或淡化;背景圖片節點永遠不動。 */ const RANGE_NODE_TYPES = new Set([
|
|
4
|
+
'rectangleNode',
|
|
5
|
+
'pathNode'
|
|
6
|
+
]);
|
|
7
|
+
/** 被淡化(非高亮)範圍的透明度。 */ const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
8
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */ const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
9
|
+
/**
|
|
10
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
11
|
+
*
|
|
12
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
13
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
14
|
+
*/ const applyPreviewHighlight = (nodes, highlightIds, dimOthers = true)=>{
|
|
15
|
+
if (!highlightIds || highlightIds.length === 0) {
|
|
16
|
+
return nodes;
|
|
17
|
+
}
|
|
18
|
+
const highlighted = new Set(highlightIds);
|
|
19
|
+
return nodes.map((node)=>{
|
|
20
|
+
if (!RANGE_NODE_TYPES.has(node.type)) {
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
const isHighlighted = highlighted.has(node.id);
|
|
24
|
+
const isDimmed = dimOthers && !isHighlighted;
|
|
25
|
+
return {
|
|
26
|
+
...node,
|
|
27
|
+
data: {
|
|
28
|
+
...node.data,
|
|
29
|
+
previewHighlighted: isHighlighted,
|
|
30
|
+
previewDimmed: isDimmed
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.PREVIEW_DIMMED_OPACITY = PREVIEW_DIMMED_OPACITY;
|
|
37
|
+
exports.PREVIEW_HIGHLIGHT_STROKE_WIDTH = PREVIEW_HIGHLIGHT_STROKE_WIDTH;
|
|
38
|
+
exports.applyPreviewHighlight = applyPreviewHighlight;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.cjs';
|
|
2
|
+
/** 被淡化(非高亮)範圍的透明度。 */
|
|
3
|
+
export declare const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
4
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */
|
|
5
|
+
export declare const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
6
|
+
/**
|
|
7
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
8
|
+
*
|
|
9
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
10
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
11
|
+
*/
|
|
12
|
+
export declare const applyPreviewHighlight: (nodes: FlowNode[], highlightIds: readonly string[] | undefined, dimOthers?: boolean) => FlowNode[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlowNode } from '../types/react-flow.types.js';
|
|
2
|
+
/** 被淡化(非高亮)範圍的透明度。 */
|
|
3
|
+
export declare const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
4
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */
|
|
5
|
+
export declare const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
6
|
+
/**
|
|
7
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
8
|
+
*
|
|
9
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
10
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
11
|
+
*/
|
|
12
|
+
export declare const applyPreviewHighlight: (nodes: FlowNode[], highlightIds: readonly string[] | undefined, dimOthers?: boolean) => FlowNode[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** 只有範圍節點(矩形、路徑)會被高亮或淡化;背景圖片節點永遠不動。 */ const RANGE_NODE_TYPES = new Set([
|
|
2
|
+
'rectangleNode',
|
|
3
|
+
'pathNode'
|
|
4
|
+
]);
|
|
5
|
+
/** 被淡化(非高亮)範圍的透明度。 */ const PREVIEW_DIMMED_OPACITY = 0.2;
|
|
6
|
+
/** 被高亮範圍的邊框/線寬(一般為 2px)。 */ const PREVIEW_HIGHLIGHT_STROKE_WIDTH = 4;
|
|
7
|
+
/**
|
|
8
|
+
* 依 highlightIds 為範圍節點標記 previewHighlighted / previewDimmed。
|
|
9
|
+
*
|
|
10
|
+
* - 未提供或為空陣列時不做任何標記(回傳原陣列),避免整張圖被淡化。
|
|
11
|
+
* - dimOthers 為 false 時只標記高亮,其餘範圍維持原樣。
|
|
12
|
+
*/ const applyPreviewHighlight = (nodes, highlightIds, dimOthers = true)=>{
|
|
13
|
+
if (!highlightIds || highlightIds.length === 0) {
|
|
14
|
+
return nodes;
|
|
15
|
+
}
|
|
16
|
+
const highlighted = new Set(highlightIds);
|
|
17
|
+
return nodes.map((node)=>{
|
|
18
|
+
if (!RANGE_NODE_TYPES.has(node.type)) {
|
|
19
|
+
return node;
|
|
20
|
+
}
|
|
21
|
+
const isHighlighted = highlighted.has(node.id);
|
|
22
|
+
const isDimmed = dimOthers && !isHighlighted;
|
|
23
|
+
return {
|
|
24
|
+
...node,
|
|
25
|
+
data: {
|
|
26
|
+
...node.data,
|
|
27
|
+
previewHighlighted: isHighlighted,
|
|
28
|
+
previewDimmed: isDimmed
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { PREVIEW_DIMMED_OPACITY, PREVIEW_HIGHLIGHT_STROKE_WIDTH, applyPreviewHighlight };
|