修复样式设置覆盖的bug

This commit is contained in:
JIANG
2025-12-22 17:16:07 +08:00
parent b35af91008
commit 6c1e193f60

View File

@@ -272,8 +272,14 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
); );
// 保存当前图层的样式状态 // 保存当前图层的样式状态
const saveLayerStyle = useCallback( const saveLayerStyle = useCallback(
(layerId?: string, newLegendConfig?: LegendStyleConfig) => { (
if (!selectedRenderLayer || !styleConfig.property) { layerId?: string,
newLegendConfig?: LegendStyleConfig,
overrideStyleConfig?: StyleConfig
) => {
const currentStyleConfig = overrideStyleConfig || styleConfig;
if (!currentStyleConfig.property) {
console.warn("无法保存样式:缺少必要的图层或样式配置"); console.warn("无法保存样式:缺少必要的图层或样式配置");
return; return;
} }
@@ -281,17 +287,17 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
// 如果没有传入图例配置,则创建一个默认的空配置 // 如果没有传入图例配置,则创建一个默认的空配置
const layerName = const layerName =
newLegendConfig?.layerName || newLegendConfig?.layerName ||
selectedRenderLayer.get("name") || selectedRenderLayer?.get("name") ||
`图层${layerId}`; `图层${layerId}`;
const property = availableProperties.find( const property = availableProperties.find(
(p) => p.value === styleConfig.property (p) => p.value === currentStyleConfig.property
); );
let legendConfig: LegendStyleConfig = newLegendConfig || { let legendConfig: LegendStyleConfig = newLegendConfig || {
layerId, layerId,
layerName, layerName,
property: property?.name || styleConfig.property, property: property?.name || currentStyleConfig.property,
colors: [], colors: [],
type: selectedRenderLayer.get("type"), type: selectedRenderLayer?.get("type") || "point",
dimensions: [], dimensions: [],
breaks: [], breaks: [],
}; };
@@ -299,7 +305,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
const newStyleState: LayerStyleState = { const newStyleState: LayerStyleState = {
layerId, layerId,
layerName, layerName,
styleConfig: { ...styleConfig }, styleConfig: { ...currentStyleConfig },
legendConfig: { ...legendConfig }, legendConfig: { ...legendConfig },
isActive: true, isActive: true,
}; };
@@ -320,7 +326,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
} }
}); });
}, },
[selectedRenderLayer, styleConfig] [selectedRenderLayer, styleConfig, availableProperties]
); );
// 设置分类样式参数,触发样式应用 // 设置分类样式参数,触发样式应用
const setStyleState = () => { const setStyleState = () => {
@@ -663,7 +669,7 @@ const StyleEditorPanel: React.FC<StyleEditorPanelProps> = ({
}; };
// 自动保存样式状态,直接传入图例配置 // 自动保存样式状态,直接传入图例配置
setTimeout(() => { setTimeout(() => {
saveLayerStyle(renderLayer.get("value"), legendConfig); saveLayerStyle(renderLayer.get("value"), legendConfig, styleConfig);
}, 100); }, 100);
}; };
// 应用样式函数,传入 breaks 数据 // 应用样式函数,传入 breaks 数据