@rytass/wms-map-react-components 0.1.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.
- package/LICENSE +21 -0
- package/README.md +77 -0
- package/components/breadcrumb/breadcrumb-edit-modal.d.ts +9 -0
- package/components/breadcrumb/breadcrumb-edit-modal.js +92 -0
- package/components/breadcrumb/breadcrumb-edit-modal.module.scss.js +3 -0
- package/components/breadcrumb/breadcrumb.d.ts +8 -0
- package/components/breadcrumb/breadcrumb.js +167 -0
- package/components/breadcrumb/breadcrumb.module.scss.js +3 -0
- package/components/canvas/react-flow-canvas.d.ts +37 -0
- package/components/canvas/react-flow-canvas.js +317 -0
- package/components/canvas/react-flow-canvas.module.scss.js +3 -0
- package/components/modal/wms-map-content.d.ts +4 -0
- package/components/modal/wms-map-content.js +753 -0
- package/components/modal/wms-map-header.d.ts +6 -0
- package/components/modal/wms-map-header.js +19 -0
- package/components/modal/wms-map-header.module.scss.js +3 -0
- package/components/modal/wms-map-modal-container.d.ts +4 -0
- package/components/modal/wms-map-modal-container.js +95 -0
- package/components/modal/wms-map-modal-container.module.scss.js +3 -0
- package/components/nodes/base-node.d.ts +12 -0
- package/components/nodes/image-node.d.ts +17 -0
- package/components/nodes/image-node.js +233 -0
- package/components/nodes/image-node.module.scss.js +3 -0
- package/components/nodes/path-node.d.ts +19 -0
- package/components/nodes/path-node.js +550 -0
- package/components/nodes/path-node.module.scss.js +3 -0
- package/components/nodes/rectangle-node.d.ts +11 -0
- package/components/nodes/rectangle-node.js +236 -0
- package/components/nodes/rectangle-node.module.scss.js +3 -0
- package/components/ui/context-menu.d.ts +25 -0
- package/components/ui/context-menu.js +168 -0
- package/components/ui/context-menu.module.scss.js +3 -0
- package/components/ui/toolbar.d.ts +23 -0
- package/components/ui/toolbar.js +278 -0
- package/components/ui/toolbar.module.scss.js +3 -0
- package/components/ui/view-mode-toolbar.d.ts +9 -0
- package/components/ui/view-mode-toolbar.js +41 -0
- package/components/ui/view-mode-toolbar.module.scss.js +3 -0
- package/constants/index.d.ts +45 -0
- package/constants/index.js +37 -0
- package/constants/text-mappings.d.ts +181 -0
- package/constants/text-mappings.js +44 -0
- package/hooks/use-context-menu.d.ts +37 -0
- package/hooks/use-context-menu.js +228 -0
- package/hooks/use-direct-state-history.d.ts +58 -0
- package/hooks/use-direct-state-history.js +214 -0
- package/hooks/use-pen-drawing.d.ts +30 -0
- package/hooks/use-pen-drawing.js +363 -0
- package/hooks/use-rectangle-drawing.d.ts +19 -0
- package/hooks/use-rectangle-drawing.js +136 -0
- package/hooks/use-text-editing.d.ts +19 -0
- package/hooks/use-text-editing.js +153 -0
- package/icons/index.d.ts +15 -0
- package/icons/index.js +209 -0
- package/index.cjs.css +1 -0
- package/index.cjs.js +5033 -0
- package/index.css +1 -0
- package/index.d.ts +5 -0
- package/index.js +4 -0
- package/package.json +40 -0
- package/types/callback.types.d.ts +7 -0
- package/types/canvas.types.d.ts +35 -0
- package/types/component-props.types.d.ts +41 -0
- package/types/history.types.d.ts +24 -0
- package/types/index.d.ts +5 -0
- package/types/react-flow.types.d.ts +30 -0
- package/typings.d.ts +140 -0
- package/typings.js +37 -0
- package/utils/api-data-transform.d.ts +33 -0
- package/utils/api-data-transform.js +218 -0
- package/utils/color-utils.d.ts +17 -0
- package/utils/color-utils.js +55 -0
- package/utils/debug-logger.d.ts +33 -0
- package/utils/debug-logger.js +41 -0
- package/utils/map-data-transform.d.ts +18 -0
- package/utils/map-data-transform.js +342 -0
- package/utils/node-operations.d.ts +26 -0
- package/utils/node-operations.js +83 -0
- package/utils/node-utils.d.ts +10 -0
- package/utils/node-utils.js +37 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顏色亮度計算工具函數
|
|
3
|
+
* 用於在檢視模式下創建 hover 效果
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 提高顏色亮度
|
|
7
|
+
* @param color - 十六進制顏色字串 (例如: #ff0000)
|
|
8
|
+
* @param percentage - 亮度提高的百分比 (例如: 15 表示提高 15%)
|
|
9
|
+
* @returns 提高亮度後的十六進制顏色字串
|
|
10
|
+
*/
|
|
11
|
+
export declare function increaseBrightness(color: string, percentage: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* 創建 hover 效果顏色(亮度提高 15%)
|
|
14
|
+
* @param color - 原始顏色
|
|
15
|
+
* @returns hover 效果的顏色
|
|
16
|
+
*/
|
|
17
|
+
export declare function createHoverColor(color: string): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顏色亮度計算工具函數
|
|
3
|
+
* 用於在檢視模式下創建 hover 效果
|
|
4
|
+
*/ /**
|
|
5
|
+
* 將十六進制顏色轉換為 RGB
|
|
6
|
+
*/ function hexToRgb(hex) {
|
|
7
|
+
// 移除 # 符號
|
|
8
|
+
const cleanHex = hex.replace('#', '');
|
|
9
|
+
// 支援 3 位元和 6 位元的十六進制顏色
|
|
10
|
+
const shorthandRegex = /^([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
11
|
+
const fullHex = cleanHex.replace(shorthandRegex, (_m, r, g, b)=>r + r + g + g + b + b);
|
|
12
|
+
const result = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(fullHex);
|
|
13
|
+
return result ? {
|
|
14
|
+
r: parseInt(result[1], 16),
|
|
15
|
+
g: parseInt(result[2], 16),
|
|
16
|
+
b: parseInt(result[3], 16)
|
|
17
|
+
} : null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 將 RGB 轉換為十六進制顏色
|
|
21
|
+
*/ function rgbToHex(r, g, b) {
|
|
22
|
+
const toHex = (n)=>{
|
|
23
|
+
const hex = Math.round(Math.max(0, Math.min(255, n))).toString(16);
|
|
24
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
25
|
+
};
|
|
26
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 提高顏色亮度
|
|
30
|
+
* @param color - 十六進制顏色字串 (例如: #ff0000)
|
|
31
|
+
* @param percentage - 亮度提高的百分比 (例如: 15 表示提高 15%)
|
|
32
|
+
* @returns 提高亮度後的十六進制顏色字串
|
|
33
|
+
*/ function increaseBrightness(color, percentage) {
|
|
34
|
+
const rgb = hexToRgb(color);
|
|
35
|
+
if (!rgb) {
|
|
36
|
+
console.warn(`Invalid color format: ${color}`);
|
|
37
|
+
return color;
|
|
38
|
+
}
|
|
39
|
+
// 計算亮度增加的因子
|
|
40
|
+
const factor = 1 + percentage / 100;
|
|
41
|
+
// 應用亮度增加,但不能超過 255
|
|
42
|
+
const newR = Math.min(255, rgb.r * factor);
|
|
43
|
+
const newG = Math.min(255, rgb.g * factor);
|
|
44
|
+
const newB = Math.min(255, rgb.b * factor);
|
|
45
|
+
return rgbToHex(newR, newG, newB);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 創建 hover 效果顏色(亮度提高 15%)
|
|
49
|
+
* @param color - 原始顏色
|
|
50
|
+
* @returns hover 效果的顏色
|
|
51
|
+
*/ function createHoverColor(color) {
|
|
52
|
+
return increaseBrightness(color, 25);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { createHoverColor, increaseBrightness };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 簡化的 Debug Console 管理系統
|
|
3
|
+
* 只有開啟/關閉功能,可透過 WmsMapModal props 控制
|
|
4
|
+
* 使用命名空間避免污染全域範圍
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 設定 debug 模式 (僅限 WmsMapModal 範圍)
|
|
8
|
+
*/
|
|
9
|
+
export declare const setDebugMode: (enabled: boolean) => void;
|
|
10
|
+
/**
|
|
11
|
+
* 取得 debug 模式狀態 (僅限 WmsMapModal 範圍)
|
|
12
|
+
*/
|
|
13
|
+
export declare const getDebugMode: () => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 主要的 debug logger 函數
|
|
16
|
+
*/
|
|
17
|
+
export declare const debugLog: (message: string, ...args: (string | number | object)[]) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 成功 debug log
|
|
20
|
+
*/
|
|
21
|
+
export declare const debugSuccess: (message: string, ...args: (string | number | object)[]) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 錯誤 debug log
|
|
24
|
+
*/
|
|
25
|
+
export declare const debugError: (message: string, error?: unknown) => void;
|
|
26
|
+
/**
|
|
27
|
+
* 警告 debug log
|
|
28
|
+
*/
|
|
29
|
+
export declare const debugWarn: (message: string, ...args: (string | number | object)[]) => void;
|
|
30
|
+
/**
|
|
31
|
+
* 群組化的 debug log
|
|
32
|
+
*/
|
|
33
|
+
export declare const debugGroup: (groupName: string, callback: () => void) => void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 簡化的 Debug Console 管理系統
|
|
3
|
+
* 只有開啟/關閉功能,可透過 WmsMapModal props 控制
|
|
4
|
+
* 使用命名空間避免污染全域範圍
|
|
5
|
+
*/ // WmsMapModal 專用的 debug 命名空間
|
|
6
|
+
const WMS_DEBUG_NAMESPACE = '__WMS_MAP_DEBUG__';
|
|
7
|
+
// 取得 WmsMapModal 專用的 debug 狀態
|
|
8
|
+
const getWmsDebugState = ()=>{
|
|
9
|
+
return Boolean(window[WMS_DEBUG_NAMESPACE]);
|
|
10
|
+
};
|
|
11
|
+
// 設定 WmsMapModal 專用的 debug 狀態
|
|
12
|
+
const setWmsDebugState = (enabled)=>{
|
|
13
|
+
window[WMS_DEBUG_NAMESPACE] = enabled;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 設定 debug 模式 (僅限 WmsMapModal 範圍)
|
|
17
|
+
*/ const setDebugMode = (enabled)=>{
|
|
18
|
+
setWmsDebugState(enabled);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 主要的 debug logger 函數
|
|
22
|
+
*/ const debugLog = (message, ...args)=>{
|
|
23
|
+
if (!getWmsDebugState()) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
27
|
+
const prefix = `🔧 ${timestamp} [WMS]`;
|
|
28
|
+
console.log(prefix, message, ...args);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 成功 debug log
|
|
32
|
+
*/ const debugSuccess = (message, ...args)=>{
|
|
33
|
+
if (!getWmsDebugState()) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
37
|
+
const prefix = `✅ ${timestamp} [WMS]`;
|
|
38
|
+
console.log(prefix, message, ...args);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { debugLog, debugSuccess, setDebugMode };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Node } from '@xyflow/react';
|
|
2
|
+
import { Map, WMSNodeClickInfo } from '../typings';
|
|
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,342 @@
|
|
|
1
|
+
import { MapRangeType } from '../typings.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 轉換 React Flow 節點資料為 Map 資料格式
|
|
5
|
+
*/ const transformNodesToMapData = (nodes)=>{
|
|
6
|
+
const backgrounds = [];
|
|
7
|
+
const ranges = [];
|
|
8
|
+
nodes.forEach((node)=>{
|
|
9
|
+
switch(node.type){
|
|
10
|
+
case 'imageNode':
|
|
11
|
+
{
|
|
12
|
+
// ImageNode 轉換為 MapBackground
|
|
13
|
+
const imageData = node.data;
|
|
14
|
+
const background = {
|
|
15
|
+
id: node.id,
|
|
16
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
17
|
+
x: node.position.x,
|
|
18
|
+
y: node.position.y,
|
|
19
|
+
width: imageData.width || 300,
|
|
20
|
+
height: imageData.height || 200
|
|
21
|
+
};
|
|
22
|
+
backgrounds.push(background);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case 'rectangleNode':
|
|
26
|
+
{
|
|
27
|
+
// RectangleNode 轉換為 MapRectangleRange
|
|
28
|
+
const rectData = node.data;
|
|
29
|
+
const rectangleRange = {
|
|
30
|
+
id: node.id,
|
|
31
|
+
type: MapRangeType.RECTANGLE,
|
|
32
|
+
color: rectData.color || '#0000FF',
|
|
33
|
+
x: node.position.x,
|
|
34
|
+
y: node.position.y,
|
|
35
|
+
width: rectData.width || 100,
|
|
36
|
+
height: rectData.height || 100,
|
|
37
|
+
text: rectData.label
|
|
38
|
+
};
|
|
39
|
+
ranges.push(rectangleRange);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case 'pathNode':
|
|
43
|
+
{
|
|
44
|
+
// PathNode 轉換為 MapPolygonRange
|
|
45
|
+
const pathData = node.data;
|
|
46
|
+
const polygonRange = {
|
|
47
|
+
id: node.id,
|
|
48
|
+
type: MapRangeType.POLYGON,
|
|
49
|
+
color: pathData.color || '#0000FF',
|
|
50
|
+
points: pathData.points || [],
|
|
51
|
+
text: pathData.label
|
|
52
|
+
};
|
|
53
|
+
ranges.push(polygonRange);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
default:
|
|
57
|
+
// 忽略未知的節點類型
|
|
58
|
+
console.warn(`Unknown node type: ${node.type}`, node);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// 生成 Map 物件
|
|
63
|
+
const mapData = {
|
|
64
|
+
id: `map-${Date.now()}`,
|
|
65
|
+
backgrounds,
|
|
66
|
+
ranges
|
|
67
|
+
};
|
|
68
|
+
return mapData;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 轉換 React Flow 節點為點擊資訊格式
|
|
72
|
+
*/ const transformNodeToClickInfo = (node)=>{
|
|
73
|
+
const baseInfo = {
|
|
74
|
+
id: node.id,
|
|
75
|
+
type: node.type,
|
|
76
|
+
position: node.position,
|
|
77
|
+
zIndex: node.zIndex,
|
|
78
|
+
selected: node.selected
|
|
79
|
+
};
|
|
80
|
+
switch(node.type){
|
|
81
|
+
case 'imageNode':
|
|
82
|
+
{
|
|
83
|
+
const imageData = node.data;
|
|
84
|
+
const mapBackground = {
|
|
85
|
+
id: node.id,
|
|
86
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
87
|
+
x: node.position.x,
|
|
88
|
+
y: node.position.y,
|
|
89
|
+
width: imageData.width || 300,
|
|
90
|
+
height: imageData.height || 200
|
|
91
|
+
};
|
|
92
|
+
const clickInfo = {
|
|
93
|
+
...baseInfo,
|
|
94
|
+
type: 'imageNode',
|
|
95
|
+
imageData: {
|
|
96
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
97
|
+
size: {
|
|
98
|
+
width: imageData.width || 0,
|
|
99
|
+
height: imageData.height || 0
|
|
100
|
+
},
|
|
101
|
+
originalSize: {
|
|
102
|
+
width: imageData.originalWidth || 0,
|
|
103
|
+
height: imageData.originalHeight || 0
|
|
104
|
+
},
|
|
105
|
+
imageUrl: imageData.imageUrl
|
|
106
|
+
},
|
|
107
|
+
mapBackground
|
|
108
|
+
};
|
|
109
|
+
return clickInfo;
|
|
110
|
+
}
|
|
111
|
+
case 'rectangleNode':
|
|
112
|
+
{
|
|
113
|
+
const rectData = node.data;
|
|
114
|
+
const mapRectangleRange = {
|
|
115
|
+
id: node.id,
|
|
116
|
+
type: MapRangeType.RECTANGLE,
|
|
117
|
+
color: rectData.color || '#0000FF',
|
|
118
|
+
x: node.position.x,
|
|
119
|
+
y: node.position.y,
|
|
120
|
+
width: rectData.width || 100,
|
|
121
|
+
height: rectData.height || 100,
|
|
122
|
+
text: rectData.label
|
|
123
|
+
};
|
|
124
|
+
const clickInfo = {
|
|
125
|
+
...baseInfo,
|
|
126
|
+
type: 'rectangleNode',
|
|
127
|
+
rectangleData: {
|
|
128
|
+
color: rectData.color || '#0000FF',
|
|
129
|
+
size: {
|
|
130
|
+
width: rectData.width || 100,
|
|
131
|
+
height: rectData.height || 100
|
|
132
|
+
},
|
|
133
|
+
text: rectData.label
|
|
134
|
+
},
|
|
135
|
+
mapRectangleRange
|
|
136
|
+
};
|
|
137
|
+
return clickInfo;
|
|
138
|
+
}
|
|
139
|
+
case 'pathNode':
|
|
140
|
+
{
|
|
141
|
+
const pathData = node.data;
|
|
142
|
+
const bounds = pathData.points?.length > 0 ? {
|
|
143
|
+
minX: Math.min(...pathData.points.map((p)=>p.x)),
|
|
144
|
+
minY: Math.min(...pathData.points.map((p)=>p.y)),
|
|
145
|
+
maxX: Math.max(...pathData.points.map((p)=>p.x)),
|
|
146
|
+
maxY: Math.max(...pathData.points.map((p)=>p.y))
|
|
147
|
+
} : null;
|
|
148
|
+
const mapPolygonRange = {
|
|
149
|
+
id: node.id,
|
|
150
|
+
type: MapRangeType.POLYGON,
|
|
151
|
+
color: pathData.color || '#0000FF',
|
|
152
|
+
points: pathData.points || [],
|
|
153
|
+
text: pathData.label
|
|
154
|
+
};
|
|
155
|
+
const clickInfo = {
|
|
156
|
+
...baseInfo,
|
|
157
|
+
type: 'pathNode',
|
|
158
|
+
pathData: {
|
|
159
|
+
color: pathData.color || '#0000FF',
|
|
160
|
+
strokeWidth: pathData.strokeWidth || 2,
|
|
161
|
+
pointCount: pathData.points?.length || 0,
|
|
162
|
+
points: pathData.points || [],
|
|
163
|
+
bounds,
|
|
164
|
+
text: pathData.label
|
|
165
|
+
},
|
|
166
|
+
mapPolygonRange
|
|
167
|
+
};
|
|
168
|
+
return clickInfo;
|
|
169
|
+
}
|
|
170
|
+
default:
|
|
171
|
+
console.warn(`未知的節點類型: ${node.type}`);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* 格式化輸出單個節點的詳細資訊
|
|
177
|
+
*/ const logNodeData = (node)=>{
|
|
178
|
+
console.group(`🎯 圖形點擊資訊 - ${node.type}`);
|
|
179
|
+
console.log('📋 基本資訊:', {
|
|
180
|
+
id: node.id,
|
|
181
|
+
type: node.type,
|
|
182
|
+
position: node.position,
|
|
183
|
+
zIndex: node.zIndex,
|
|
184
|
+
selected: node.selected
|
|
185
|
+
});
|
|
186
|
+
switch(node.type){
|
|
187
|
+
case 'imageNode':
|
|
188
|
+
{
|
|
189
|
+
const imageData = node.data;
|
|
190
|
+
console.log('🖼️ 背景圖片資訊:', {
|
|
191
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
192
|
+
position: {
|
|
193
|
+
x: node.position.x,
|
|
194
|
+
y: node.position.y
|
|
195
|
+
},
|
|
196
|
+
size: {
|
|
197
|
+
width: imageData.width,
|
|
198
|
+
height: imageData.height
|
|
199
|
+
},
|
|
200
|
+
originalSize: {
|
|
201
|
+
width: imageData.originalWidth,
|
|
202
|
+
height: imageData.originalHeight
|
|
203
|
+
},
|
|
204
|
+
imageUrl: imageData.imageUrl?.slice(0, 50) + '...'
|
|
205
|
+
});
|
|
206
|
+
// 轉換格式(對應儲存時的格式)
|
|
207
|
+
const background = {
|
|
208
|
+
id: node.id,
|
|
209
|
+
filename: imageData.fileName || 'unknown.jpg',
|
|
210
|
+
x: node.position.x,
|
|
211
|
+
y: node.position.y,
|
|
212
|
+
width: imageData.width || 300,
|
|
213
|
+
height: imageData.height || 200
|
|
214
|
+
};
|
|
215
|
+
console.log('💾 儲存格式 (MapBackground):', background);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case 'rectangleNode':
|
|
219
|
+
{
|
|
220
|
+
const rectData = node.data;
|
|
221
|
+
console.log('📐 矩形資訊:', {
|
|
222
|
+
color: rectData.color,
|
|
223
|
+
position: {
|
|
224
|
+
x: node.position.x,
|
|
225
|
+
y: node.position.y
|
|
226
|
+
},
|
|
227
|
+
size: {
|
|
228
|
+
width: rectData.width || 100,
|
|
229
|
+
height: rectData.height || 100
|
|
230
|
+
},
|
|
231
|
+
text: rectData.label
|
|
232
|
+
});
|
|
233
|
+
// 轉換格式(對應儲存時的格式)
|
|
234
|
+
const rectangleRange = {
|
|
235
|
+
id: node.id,
|
|
236
|
+
type: MapRangeType.RECTANGLE,
|
|
237
|
+
color: rectData.color || '#0000FF',
|
|
238
|
+
x: node.position.x,
|
|
239
|
+
y: node.position.y,
|
|
240
|
+
width: rectData.width || 100,
|
|
241
|
+
height: rectData.height || 100,
|
|
242
|
+
text: rectData.label
|
|
243
|
+
};
|
|
244
|
+
console.log('💾 儲存格式 (MapRectangleRange):', rectangleRange);
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case 'pathNode':
|
|
248
|
+
{
|
|
249
|
+
const pathData = node.data;
|
|
250
|
+
console.log('🔗 路徑資訊:', {
|
|
251
|
+
color: pathData.color,
|
|
252
|
+
strokeWidth: pathData.strokeWidth,
|
|
253
|
+
pointCount: pathData.points?.length || 0,
|
|
254
|
+
points: pathData.points,
|
|
255
|
+
text: pathData.label,
|
|
256
|
+
// 計算路徑邊界
|
|
257
|
+
bounds: pathData.points?.length > 0 ? {
|
|
258
|
+
minX: Math.min(...pathData.points.map((p)=>p.x)),
|
|
259
|
+
minY: Math.min(...pathData.points.map((p)=>p.y)),
|
|
260
|
+
maxX: Math.max(...pathData.points.map((p)=>p.x)),
|
|
261
|
+
maxY: Math.max(...pathData.points.map((p)=>p.y))
|
|
262
|
+
} : null
|
|
263
|
+
});
|
|
264
|
+
// 轉換格式(對應儲存時的格式)
|
|
265
|
+
const polygonRange = {
|
|
266
|
+
id: node.id,
|
|
267
|
+
type: MapRangeType.POLYGON,
|
|
268
|
+
color: pathData.color || '#0000FF',
|
|
269
|
+
points: pathData.points || [],
|
|
270
|
+
text: pathData.label
|
|
271
|
+
};
|
|
272
|
+
console.log('💾 儲存格式 (MapPolygonRange):', polygonRange);
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
default:
|
|
276
|
+
console.warn(`未知的節點類型: ${node.type}`);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
console.log('🔢 完整節點資料:', node);
|
|
280
|
+
console.groupEnd();
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* 格式化輸出 Map 資料到 console,包含詳細資訊
|
|
284
|
+
*/ const logMapData = (mapData)=>{
|
|
285
|
+
console.group('🗺️ WMS Map Data Export');
|
|
286
|
+
console.log('📋 Map Overview:', {
|
|
287
|
+
id: mapData.id,
|
|
288
|
+
backgroundCount: mapData.backgrounds.length,
|
|
289
|
+
rangeCount: mapData.ranges.length
|
|
290
|
+
});
|
|
291
|
+
if (mapData.backgrounds.length > 0) {
|
|
292
|
+
console.group('🖼️ Background Images');
|
|
293
|
+
mapData.backgrounds.forEach((bg, index)=>{
|
|
294
|
+
console.log(`Background ${index + 1}:`, {
|
|
295
|
+
id: bg.id,
|
|
296
|
+
filename: bg.filename,
|
|
297
|
+
position: {
|
|
298
|
+
x: bg.x,
|
|
299
|
+
y: bg.y
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
console.groupEnd();
|
|
304
|
+
}
|
|
305
|
+
if (mapData.ranges.length > 0) {
|
|
306
|
+
console.group('📐 Ranges');
|
|
307
|
+
mapData.ranges.forEach((range, index)=>{
|
|
308
|
+
if (range.type === MapRangeType.RECTANGLE) {
|
|
309
|
+
const rect = range;
|
|
310
|
+
console.log(`Rectangle ${index + 1}:`, {
|
|
311
|
+
id: rect.id,
|
|
312
|
+
type: rect.type,
|
|
313
|
+
color: rect.color,
|
|
314
|
+
position: {
|
|
315
|
+
x: rect.x,
|
|
316
|
+
y: rect.y
|
|
317
|
+
},
|
|
318
|
+
size: {
|
|
319
|
+
width: rect.width,
|
|
320
|
+
height: rect.height
|
|
321
|
+
},
|
|
322
|
+
text: rect.text
|
|
323
|
+
});
|
|
324
|
+
} else if (range.type === MapRangeType.POLYGON) {
|
|
325
|
+
const poly = range;
|
|
326
|
+
console.log(`Polygon ${index + 1}:`, {
|
|
327
|
+
id: poly.id,
|
|
328
|
+
type: poly.type,
|
|
329
|
+
color: poly.color,
|
|
330
|
+
pointCount: poly.points.length,
|
|
331
|
+
points: poly.points,
|
|
332
|
+
text: poly.text
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
console.groupEnd();
|
|
337
|
+
}
|
|
338
|
+
console.log('📄 Complete Map Data:', mapData);
|
|
339
|
+
console.groupEnd();
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export { logMapData, logNodeData, transformNodeToClickInfo, transformNodesToMapData };
|
|
@@ -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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate offset position for copied node
|
|
3
|
+
*/ const calculateCopyOffset = (width, height, offsetPercentage = 0.25)=>{
|
|
4
|
+
return {
|
|
5
|
+
offsetX: width * offsetPercentage,
|
|
6
|
+
offsetY: height * offsetPercentage
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Create a copy of a rectangle node
|
|
11
|
+
*/ const createRectangleCopy = (options)=>{
|
|
12
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
13
|
+
const { offsetX, offsetY } = calculateCopyOffset(data.width, data.height, offsetPercentage);
|
|
14
|
+
return {
|
|
15
|
+
id: `rectangle-${Date.now()}`,
|
|
16
|
+
type: 'rectangleNode',
|
|
17
|
+
position: {
|
|
18
|
+
x: currentNode.position.x + offsetX,
|
|
19
|
+
y: currentNode.position.y + offsetY
|
|
20
|
+
},
|
|
21
|
+
data: {
|
|
22
|
+
width: data.width,
|
|
23
|
+
height: data.height,
|
|
24
|
+
color: data.color,
|
|
25
|
+
label: data.label
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Create a copy of a path node
|
|
31
|
+
*/ const createPathCopy = (options)=>{
|
|
32
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
33
|
+
// Calculate path bounds
|
|
34
|
+
const xs = data.points.map((p)=>p.x);
|
|
35
|
+
const ys = data.points.map((p)=>p.y);
|
|
36
|
+
const bounds = {
|
|
37
|
+
minX: Math.min(...xs),
|
|
38
|
+
minY: Math.min(...ys),
|
|
39
|
+
maxX: Math.max(...xs),
|
|
40
|
+
maxY: Math.max(...ys)
|
|
41
|
+
};
|
|
42
|
+
const pathWidth = Math.max(bounds.maxX - bounds.minX, 10);
|
|
43
|
+
const pathHeight = Math.max(bounds.maxY - bounds.minY, 10);
|
|
44
|
+
const { offsetX, offsetY } = calculateCopyOffset(pathWidth, pathHeight, offsetPercentage);
|
|
45
|
+
return {
|
|
46
|
+
id: `path-${Date.now()}`,
|
|
47
|
+
type: 'pathNode',
|
|
48
|
+
position: {
|
|
49
|
+
x: currentNode.position.x + offsetX,
|
|
50
|
+
y: currentNode.position.y + offsetY
|
|
51
|
+
},
|
|
52
|
+
data: {
|
|
53
|
+
points: data.points,
|
|
54
|
+
color: data.color,
|
|
55
|
+
strokeWidth: data.strokeWidth,
|
|
56
|
+
label: data.label
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Create a copy of an image node
|
|
62
|
+
*/ const createImageCopy = (options)=>{
|
|
63
|
+
const { currentNode, offsetPercentage = 0.25, data } = options;
|
|
64
|
+
const { offsetX, offsetY } = calculateCopyOffset(data.width, data.height, offsetPercentage);
|
|
65
|
+
return {
|
|
66
|
+
id: `image-${Date.now()}`,
|
|
67
|
+
type: 'imageNode',
|
|
68
|
+
position: {
|
|
69
|
+
x: currentNode.position.x + offsetX,
|
|
70
|
+
y: currentNode.position.y + offsetY
|
|
71
|
+
},
|
|
72
|
+
data: {
|
|
73
|
+
imageUrl: data.imageUrl,
|
|
74
|
+
width: data.width,
|
|
75
|
+
height: data.height,
|
|
76
|
+
fileName: data.fileName,
|
|
77
|
+
originalWidth: data.originalWidth,
|
|
78
|
+
originalHeight: data.originalHeight
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { calculateCopyOffset, createImageCopy, createPathCopy, createRectangleCopy };
|
|
@@ -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,37 @@
|
|
|
1
|
+
const calculateImageSize = (originalWidth, originalHeight, maxSize = 500)=>{
|
|
2
|
+
const needsResize = originalWidth > maxSize || originalHeight > maxSize;
|
|
3
|
+
if (!needsResize) {
|
|
4
|
+
return {
|
|
5
|
+
width: Math.round(originalWidth),
|
|
6
|
+
height: Math.round(originalHeight)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
const ratio = Math.min(maxSize / originalWidth, maxSize / originalHeight);
|
|
10
|
+
return {
|
|
11
|
+
width: Math.round(originalWidth * ratio),
|
|
12
|
+
height: Math.round(originalHeight * ratio)
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const calculateStaggeredPosition = (index, baseX = 100, baseY = 100, viewportX, viewportY, viewportZoom)=>{
|
|
16
|
+
// If viewport information is provided, calculate position within current viewport
|
|
17
|
+
if (viewportX !== undefined && viewportY !== undefined && viewportZoom !== undefined) {
|
|
18
|
+
// Convert viewport coordinates to canvas coordinates
|
|
19
|
+
// The viewport shows the center of the view, so we need to offset from the center
|
|
20
|
+
const centerX = -viewportX / viewportZoom + window.innerWidth / 2 / viewportZoom;
|
|
21
|
+
const centerY = -viewportY / viewportZoom + window.innerHeight / 2 / viewportZoom;
|
|
22
|
+
// Position images slightly offset from center
|
|
23
|
+
const offsetX = centerX - 200 + index * 30; // Start 200px left of center
|
|
24
|
+
const offsetY = centerY - 100 + index * 20; // Start 100px above center
|
|
25
|
+
return {
|
|
26
|
+
x: offsetX,
|
|
27
|
+
y: offsetY
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Fallback to original fixed positioning
|
|
31
|
+
return {
|
|
32
|
+
x: baseX + index * 30,
|
|
33
|
+
y: baseY + index * 20
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { calculateImageSize, calculateStaggeredPosition };
|