点击预定义标记按钮后,标记无法在图像上显示。
发现了两个关键问题导致标记功能失效:
问题位置: MarkPanel.tsx
和 ViewerContainer.tsx
问题描述:
MarkPanel.tsx
发送的 action 是 'AddPredefinedMark:拉姿'
(带参数的字符串)ViewerContainer.tsx
的 switch case 匹配的是 'AddPredefinedMark'
(不带参数)修复方案:
在 ViewerContainer.tsx
的 useEffect 中,在 switch 语句之前添加预处理逻辑:
// 预处理带参数的 action
if (action.startsWith('AddPredefinedMark:')) {
const markText = action.substring('AddPredefinedMark:'.length);
console.log(`添加预定义标记到图像: ${markText}`);
selectedViewportIds.forEach((viewportId) => {
addCustomMark(viewportId, markText);
});
dispatch(clearAction());
return;
}
问题位置: stack.image.viewer.tsx
问题描述:
addCustomMark
函数使用 document.getElementById(currentViewportId)
来获取元素<div>
没有设置 id
属性getElementById
返回 null
,无法获取元素尺寸和添加标记修复方案: 给 StackViewer 组件的根 div 添加 id 属性:
return (
<div
id={viewportId} // ✅ 添加此行
ref={elementRef}
onContextMenu={(e) => e.preventDefault()}
style={{...}}
/>
);
问题位置: MarkPanel.tsx
问题描述:
handleDeleteMark
函数只有 TODO 注释,没有实际实现修复方案:
const handleDeleteMark = () => {
// 触发删除选中标记的action
dispatch({ type: 'functionArea/setAction', payload: 'Delete Selected Mark' });
console.log('删除选中的标记');
};
src/pages/view/components/ViewerContainer.tsx
case 'AddPredefinedMark'
分支src/pages/view/components/MarkPanel.tsx
handleDeleteMark
函数src/pages/view/components/viewers/stack.image.viewer.tsx
id={viewportId}
属性修复后,以下功能应该正常工作:
对于带参数的 action,使用字符串前缀匹配的方式:
if (action.startsWith('ActionPrefix:')) {
const param = action.substring('ActionPrefix:'.length);
// 处理逻辑
dispatch(clearAction());
return;
}
当底层函数需要通过 DOM API 访问元素时,确保:
id
属性id
值与传递给底层函数的 viewportId
保持一致使用 Cornerstone 的 LabelTool 添加文本标记:
toolGroup.setToolActive(LabelTool.toolName, { bindings: [] });
const position: Types.Point3 = [x, y, 0];
LabelTool.hydrate(viewportId, position, text);
toolGroup.setToolPassive(LabelTool.toolName, { removeAllBindings: true });
标记位置优化
标记样式定制
标记持久化
删除功能增强
错误处理
2025年10月22日
Cline AI Assistant